Best practice: Coding for different languages and regions

  • Store text strings in separate resource files and use unique identifiers (string IDs) for each text string.
  • Avoid concatenating partial strings to form a sentence. When translated, the strings might not produce a logical sentence. Create a new string for the sentence instead.
  • Avoid using variables in place of nouns (for example, "The <X> is locked."). Instead, create a specific string for each noun. Even if the sentence appears correctly in English, in some languages, if a noun is singular or plural and masculine or feminine, the rest of the string might need to change. Only use variables for strings that can only be known at runtime (for example, file names).
  • Avoid making part of a sentence into a link. When translated, the words in the link might appear in a grammatically incorrect order. For example, use "For more information, click the following link: <link>" instead of "Click on <link> for more information."
  • Avoid using a common string if the context of usage differs. Depending on the context, a word could require different translations. For example, the word "new" might require a different translation depending on the gender of the noun.
  • Avoid hard-coding spaces, punctuation marks, and words. Include these items in translatable strings instead. This approach allows translators to make changes according to the rules for each language.
  • Avoid hard-coding strings of any kind, including weekdays and weekends. Verify that the start of the week matches the convention for each locale.

Guidelines for numbers

  • Make arrangements for singular and plural nouns on a per-language basis. Nouns in some languages can have one form for both singular and plural, one form for singular and another form for plural (for example, "1 day" and "2 days"), or multiple forms, depending on the number of items (for example, one item, two items, a few items, and many items).
  • Avoid hard-coding number separators. For example, 1,234.56 appears in United States English but 1 234,56 appears in French.
  • Avoid hard-coding the number of digits between separators. For example, 123,456,789.00 appears in the United States but 12,34,56,789.00 appears in India.
  • Avoid hard-coding the display of negative numbers. For example, negative numbers can appear as -123, 123-, (123), or [123].
  • Provide options for currencies. For example, currencies can appear as $12.34, 12,34€, or 12€34. In addition, some currency symbols require more space.
  • Verify that numbers, measurements, dates, and time formats reflect the locale of your users.

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus