Message-ID: <1041282546.1550.1556111834292.JavaMail.javamailuser@localhost> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1549_835059613.1556111834291" ------=_Part_1549_835059613.1556111834291 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Localization - dev best practices

Localization - dev best practices

This page is about Localization best practices for developers. I= f you are looking for information on adding Languages to you deployment go = here

Ushahidi is built on Kohana which provides language some localization he= lpers. See the Kohana docs for more info: http://docs.ko= hanaphp.com/general/i18n

Tips when = creating strings

Never hard co= de strings

Good
<?php echo Kohana::lang('ui_main.approved_reports'); ?>
Bad
<?php echo 'Approved Reports'; ?>

Don't split = strings

Example:
You're including a heading 'Approved Reports'.

Good
<?php echo Kohana::lang('ui_main.approved_reports'); ?>

There's already a translation string for 'Reports' so we could just reus= e it:

Bad
<?php echo Kohana::lang('ui_main.approved').' '.Kohana::=
lang('ui_main.reports'); ?>

However thats a bad idea..
1. it provides translators with no context
2. it assume the words will always appear in that order, when for example t= he French translation is more like: 'Rapports approuv=C3=A9s'

Us= e arguments and string formatting

Example:
You're including a reports count: 'Showing 10 - 20 reports'

Good
<?php echo Kohana::lang('ui_main.showing_x_to_y_reports', array(=
$count_min, $count_max)); ?>

// in the ui_main language file
$lang =3D array(
  'showing_x_to_y_reports' =3D> 'Showing %1$d - %2$d reports=
',
);
Bad
<?php echo Kohana::lang('ui_main.showing').$count_min.' - &#=
39;.$count_max.Kohana::lang('ui_main.reports'); ?>

// in the ui_main language file
$lang =3D array(
  'showing' =3D> 'Showing',
  'reports' =3D> 'Reports',
);

= Use explicitly ordered placeholders:

Good
'page_of'=09=3D>=09'Page %1$s of %2$s',
=09=09/* Explicit ordering of the replacements,
=09=09even if they are the same order as English */
Bad
'page_of'=09=3D>=09'Page %s of %s',
=09=09/* Just grabbing the replacements as they
=09=09come and hope they are in the right order */

Why? Because ordering my vary in other languages. The 1st version gives= translators no context and assumes all languages structure sentences the s= ame way. Using arguments and formatted strings is much better.
In some languages the string transliterated back to English might read some= thing like:

Alternativ= e Text
'page_of'=09=3D>=09'Total of %2$s pages, currently on page %=
1$s',
=09=09/* Explicit ordering of the replacements,
=09=09reversed compared to English as the total comes first */

Exception: when there is only 1 placeholder
When theres just 1 placeholder in the string, its ok to use unordered place= holders

'ushahidi_release_version' =3D> 'Ushahidi %s',

Don= 't create string in ALL CAPS

Creating strings in all caps means when the design changes and you want = search in lower case.. all the translations have to change.
And if themers want the text in lower case, they have to hack the translati= on files.
If you do this the good way, when the design changes you can just update th= e code..

Good
<?php echo utf8::strtoupper(Kohana::lang('ui_main.search')); ?&g=
t;

// in the ui_main language file
$lang =3D array(
  'search' =3D> 'Search',
);
Bad
<?php echo Kohana::lang('ui_main.search'); ?>

// in the ui_main language file
$lang =3D array(
  'search' =3D> 'SEARCH',
);

Even better might be to replace the string to upper call with a CSS text= -transform, making life even easier for themers.

Use utf8 functions when transforming text

PHP's built in string manipulation functions don't always handle UTF8 ch= aracters. Use Kohana's utf8 library where you can instead (ht= tp://docs.kohanaphp.com/core/utf8)

Good
<?php echo utf8::strtoupper(Kohana::lang('ui_main.search')); ?&g=
t;
Bad
<?php echo strtoupper(Kohana::lang('ui_main.search')); ?>

Related links

------=_Part_1549_835059613.1556111834291--