How to translate streber into other languages.
How Translation works in streber
Streber uses translation tables. You can find them in directory
/lang/*:
scanLanguages.pl
de.inc
de.inc.changes
_new_.inc
_new_.inc.changes
pt-br.inc
pt-br.inc.changes
There are typically two files for each language. The
??.inc.php contains the actual translation table as an associative array. This file looks like:
<?php
...
$g_lang_table= array(
'English|for language selection' =>'Englisch',
'Home|Tab in top navigation' =>'Home',
'%s error(s) occured' =>'%s Fehler is aufgetreten',
...
);
?>
As you can see in the example, the orignal string consists of two parts separated by a pipe ( '|' ) symbol. The second part is optional and clarifies the context. Do not translate this ;-)
At the end of some lines there might be comments starting with "#". You can ignore them.
Inside Streber, strings that require translation are used like this:
echo __("Home");
The two underscores are actually a function name. This function looks into the translation table of the current language and searches the Key "Home". If there is one, it will be used. Otherwise the original English string will be used (of course without the context part).
Strings containing dynamic attributes contain
%s and are built with the sprintf(). Like:
echo sprintf( __("%s error(s) occured"), __("No"))
If translation keys are not found (e.g. for "No"), they are stored in an internal list of missing language-keys. You can display this list at the footer of each page by adding this line to your
customize.inc.php :
confChange('LIST_UNDEFINED_LANG_KEYS',true);
Although this might be good for testing a tranlation, it is cumbsersome to get all strings that needs translation. For this we wrote a small perl-script called
scanLanguages.pl. It scans all source files in all of the project's directories and looks for strings inside the __() functions. It then looks for languages in /lang/*.inc and writes a list of untranslated strings to files called
??.inc.changes. One file for each language.
If you have translated streber into a language, please check the release of each new version for a ".changes"-file concerning your language and add those keys to your translation.
How to translate Streber into a new language
- Start with a copy of
/lang/_new_.inc
- Rename the copy to the shortform of your language (like "uk.inc","es.inc", etc).
- Open the new file with a text editor capable of utf8 editing
- Add your translation into the quotes. (Keep in mind to ignore the part after "|")
- Save the file
- Open /conf/conf.inc
- Search for "g_languages" and add your language like:
$g_languages=array(
'en'=>'English',
'de'=>'German',
'pt-br'=>'Portugese',
);
- Add the following line to your
customize.inc.php. This will warn you on missing translation keys when testing the translation.
confChange('LIST_UNDEFINED_LANG_KEYS',true);
- For testing make your language the default-language or adjust your profile accordingly. To customize.inc add:
confChange('DEFAULT_LANGUAGE','??'); #<- replace ?? with your new language
- Start using Streber and check your translation. Esp. check for layout problemns when translated words (e.g. column-headers) get too long.
- If the context for the translation is not clear enough, please drop a comment to ?. I will check this.
- If you are done...
** Don't forget to place your credits into the header
** Add a new Folder at
? and attacht the new file. We will add it to the next release.
Localization of dates
Localization of dates is being performed though the PHP functions
gmstrftime, which needs the proper locale to be set with function
setlocale. Each language file must provide a list of locales to be passed to
setlocale as a translation of the string
'en_US.utf8,en_US,enu|list of locales'. You should provide at least three locale names in the translation. For example the Italian translation would be
'it_IT.utf8,it_IT,ita', where:
'it_IT.utf8' is the name of the locale for libc-based PHP implementation (for example under Linux) with proper utf-8 support. Names in this form are language_country with two letter ISO names for both language and country;
'it_IT' is the same name for those platforms who lack proper utf-8 support;
'ita' is the three letter name for Windows-based platforms. See msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp for a list of supported names.
The formatting string themselves needs to be translated. In particular:
'%b %e, %Y|strftime format string' for dates like Jan 16, 2007 used in very many places;
'%I:%M%P|strftime format string' for time strings like 4:48pm used in very many places (the only meaningful translation for this string is '%H:%M' for those languages that prefer 24-hour format);
'%a %b %e, %Y %I:%M%P|strftime format string' for long timestamps like Tue Jan 16, 2007 4:48pm used in many places;
'%A, %B %e|strftime format string' for dates like Tuesday, January 16, currently used only in page titles.
Attention: pixtur reports that some PHP implementation do not handle the
%e formatter (day of the month from '1' to '31') properly. In those cases the
%d formatter (which is the same but from '01' to '31') although not as good-looking should be used instead.
For further details about
strftime/gmstrftime and
setlocale, please refer to the respective doc pages:
php.net/manual/en/function.strftime.php and
php.net/manual/en/function.setlocale.php .
Thanks for your support!