[Localization] Best practices for developers
Bert Freudenberg
bert at freudenbergs.de
Tue Apr 20 07:35:03 EDT 2010
It's only a problem if there are multiple replacements in the same string. For those, it is indeed recommended to use named substitutions, which also allows reordering and leaving out parts:
_('%(count)d books on %(topic)s') % {'count': 42, 'topic': 'sugar'}
Of course, translators must not accidentally translate the placeholder names.
In fact, plural forms need special treatment anyway, and Jim did not touch on those in his chapter at all yet.
>>> from gettext import ngettext
>>> [ngettext('%(count)d book on %(topic)s', '%(count)d books on %(topic)s', n)
... % {'count': n, 'topic': 'sugar'}
... for n in (0, 1, 2)]
['0 books on sugar', '1 book on sugar', '2 books on sugar']
I'm not really sure if plural forms are extracted automatically to the po file though ...
In any case, Translators are advised to *never* remove unnamed substitutions, because, as you pointed out, that can lead to program errors.
- Bert -
On 20.04.2010, at 12:04, Khaled Hosny wrote:
>
> I highly recommend against using '%s' in translatable strings, as in
> case of several format code in one string, some languages might omit
> one of them which will crash the application. For example:
>
> "%d books on %s"
>
> The first three plural forms in Arabic will be like:
>
> "no books on %s"
> "one book on %s"
> "two books on %s"
>
> And this will cause a crash.
>
> On Wed, Mar 24, 2010 at 11:00:58AM -0600, James Simmons wrote:
>> Bert,
>>
>> I did have a chance to try out using %s in translated strings and it
>> worked fine, so I modified the chapter on Pootle in the book to
>> recommend the technique. As the book is intended for beginners I
>> think what I put in there is adequate.
>>
>> James Simmons
>>
>>
>> On Thu, Mar 18, 2010 at 3:03 PM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>>> On 08.03.2010, at 15:44, Clytie Siddall wrote:
>>>>
>>>> Reminder for developers: long strings are bad localization practice! Translators avoid them, since they have very little time available (thus you don't get the translation); there's much more room for error and confusion (so you get bad translations); translators can't review the string properly (more errors); and finally, most translation editors don't expect long strings, so they don't handle them well (confused and grumpy translators).
>>>
>>> Is there as document somewhere for "best practices" in making activities translatable?
>>>
>>> I found an old discussion on the OLPC wiki:
>>> http://wiki.laptop.org/go/Python_i18n
>>>
>>> And this on the Sugar wiki:
>>> http://wiki.sugarlabs.org/go/Translation_Team/i18n_Best_Practices
>>>
>>> But I'm pretty sure I've seen a more general discussion somewhere ...
>>>
>>> James is going to add some of these hints to his activity developing book:
>>> http://en.flossmanuals.net/bin/view/ActivitiesGuideSugar/GoingInternationalWithPootle
>>>
>>> So if you feel there is something you need budding activity developers to know, tell him ;)
>>>
>>> - Bert -
>>>
>>>
>> _______________________________________________
>> Localization mailing list
>> Localization at lists.laptop.org
>> http://lists.laptop.org/listinfo/localization
>
> --
> Khaled Hosny
> Arabic localiser and member of Arabeyes.org team
> Free font developer
More information about the Localization
mailing list