0

In localization code (like T('English phrase with %s and %s parameters', param1, param2) the order of parameters in different languages is different. How to handle this?

Our localization engine seems not to support named or numbered parameters, so the parameters need to go in the same order as they are in code.

2
  • 2
    then change the localization engine... Apr 5, 2014 at 15:03
  • 1
    We use Perl's sprintf. Now I noticed that it indeed does support numbered parameters. So my problem is solved.
    – porton
    Apr 5, 2014 at 15:40

2 Answers 2

2

If your localization engine doesn't support named parameters, then there are a few options.

  1. Get a new engine that does support named parameters
  2. Don't let your engine fill in the parameters and feed the translated string to a second "printf" engine, which does support named parameters, to fill in the parameters.
  3. Accept that you will get badly translated output and ensure that your translators know that the parameters may not be swapped during translation.1

1. I have actually worked on a product where this choice was made, due to technical limitations in the printf/display engine.

2

Pick a different localization engine, or roll your own if there are none for the language you use.

Parameters inversion is quite frequent in internationalization. That's why many format-type functions enable to specify the index of the parameter in the pattern.

For example, in Python, the two following lines print the same thing:

print('Hello, %s!' % ('John'))
print('Hello, {0}!'.format('John')) # Can specify the order

In C#, the most used pattern indicates in which order the parameters are taken:

string.Format("Hello, {0}!", "John");
2
  • 1
    Python - also: 'Hello %(name)s' % {'name': 'John'} (not as concise, but gives context in the translation string)
    – Izkata
    Apr 5, 2014 at 18:07
  • @Izkata: I was unaware of that syntax. It's very helpful. Apr 5, 2014 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.