OneSky Localization Blog

Insights on international expansion

4 tips for developers on preparing strings for localization

4 tips for developers on preparing strings for localization

 

You do not need to know many (or any) foreign languages in order to be a localization engineer. But you need to know how you can prepare your strings better to facilitate the whole localization process.

Below are 4 simple tips that could lead to better translation quality while at the same, making both your life and translators’ lives better (I believe you wouldn’t want your inbox to be flooded with questions from translators or your codes to crash when the translation comes back).

* If you are completely new to the area of localizing applications, you can check out our simple localization tutorials first.

 

1. Always wrap full sentences

Concatenating string pieces properly in your codes could improve the quality of localization significantly as it helps translators understand the context better.

Very-bad example:

<p><?=translate("You have got")?><?=$Item?></p>

Much better:

<p><?=translate("You have got %{Item}", array('Item' => $Item))?></p>



Why?

The 2nd code provides better contextual information. It’s because translators can only see the parts that you wrapped. “You have got”… what?

Examples of languages that might be affected:

  • For Turkish, translators often need to know the basic context of the object in order to decide what translation to use for the verb.
  • For Japanese, the object might be put in front of the verb: あなたは%{Item}を持っている。


NEVER do the following unless you’d like to be killed by the translators:
<p><?=translate("You have got") + $number + translate("items.")?></p>



2. Be aware of the SPACE


Bad example:

<p><?=translate("Places checked in:")?> <?=$NumberOfPlaces?></p>

Much better:

<p><?=translate("Places checked in: %{Number}", array('Number' => $NumberOfPlaces))?></p>



Why?

In English, a space is needed between words or after certain punctuations. But for some languages, a space is not needed or might even introduce errors.

Examples of languages that might be affected:

  • In Thai, space acts like a full-stop in English.
  • In Chinese, there are no spaces between words or after punctuations, e.g. 去過的地方:%{Number}



3. Try your best to avoid HTML tags in wrapped strings

Very-bad example:

<div><?=translate('<p>This is a <a href="/a/link/to/heaven">link</a> and I am loving it</p>')?></div>

Much better:

<div><p><?=translate('This is a %{link} and I am loving it', array(
    'link'    => '<a href="/a/link/to/heaven">' + translate('link') + '</a>'
))?></p></div>


Why?

  1. Most translators are not programmers. They may not even understand the difference between <br /> and <p>. Do not provide them the opportunity to crash your HTML. You’d be the one who stay late in the office fixing them while others are gone for Happy Hours.
  2. The URI may be changed later. If you place it in the wrapped string and you decide to change the URI at a latter point, you will have to edit it in EVERY translated version. Say if you have 30 languages, then you will have to edit 30 times.


4. Try to add meanings to variables


Bad example:

<p><?=translate("%$1s, you have got %$2s and %$3s in %$4s.", …)?></p>

In translators’ mind: WHAT THE HECK IS THIS?

Much better:

<p><p><?=translate("%{username}, you have got %{item_1} and %{item_2} in %{place}.", …)?></p></p>


Why?

  1. Again, most translators are not programmers and wouldn’t know what %s is. Even if they know programming, they wouldn’t know what the four %s are referring to in order to provide accurate translation.


Not all platforms allow you to use variable naming. For example, there is no variable naming in Objective C for iOS but both Ruby on Rails and Django allow such an option.

Your platform doesn’t support variable naming? Don’t worry, you can easily get around with it by using OneSky cloud-based translation management tool (see placeholder validation for more info)! It’s always our goal to simply the localization process for both developers and translators. Try OneSky now and rock the world!