You are not logged in.
Pages: 1
i18n: rules, tips & tricks
SliTaz have high class homemade tools & scripts, but, sadly, method of i18n of them can't catch both high standards of i18n. I want to improve this state and give some tips & tricks to script developers.
So, we all know about [c]gettext[/c] ( http://www.gnu.org/software/gettext/manual/gettext.html#Programmers ). Do you know about [c]eval_gettext[/c]? [c]eval_ngettext[/c]? I'm both programmer and translator, and I want to clear using of [c]gettext[/c] suite.
Very main rule: DON'T split message (which have to be translated) into pieces. Because it's very possible situation, that translator may need to shuffle that pieces to give correct translation on native, non-english language.
So, please, don't use:
[c]gettext "Unpacking : "; echo $PACKAGE[/c]
Use instead this:
[c]eval_gettext "Unpacking : \$PACKAGE"[/c]
Now, I can translate it, say, to Russian: "Пакет $PACKAGE распаковывается".
You can use both variants in your scripts (they are equivalent):
[c]eval_gettext "text \$variable again text"
eval_gettext 'text $variable again text'[/c]
But, if we use commands included one into another, personally I prefer use double outer qoutes and single inner quotes:
[c]boldify "$(eval_gettext 'Now: $date')"[/c]
There is also right variant with all double quotes too, but my Geany gets crazy in this point 
Second rule: use plurals.
I saw one funny piece of code. Some sort of this (in my memory):
[c]# pkg - number of packages
[ $pkg -gt 1 ] && ss="s" || ss=""
echo "$pkg package$ss installed"[/c]
How can I internationalize this code?
1 package installed; 2 packages installed…
It's pretty simple:
[c]eval_ngettext '$pkg package installed' \
'$pkg packages installed' $pkg[/c]
English have only two forms of words: single and plural. And you can write «package(s)», or, think that we have more than one package, then use only «packages». But, as my example, Russian have three forms of words. And I want to translate «package(s)» to «пакет(а,ов)». It's very dirty since we have eval_ngettext.
Example in Russian:
[c]1, 21, 31 пакет
2, 3, 4, 22, 23, 24 пакета
5-20, 25-30 пакетов[/c]
Gettext solves all the problems with plurals.
And again: don't split message into pieces.
Today I saw next code in tazpkg:
[c]echo -n $(colorize 32 "$packages ")
echo -n $(boldify $(gettext "packages installed of category:"))
colorize 34 " $ASKED_CATEGORY_I18N"[/c]
I'm so sorry, but I want to delete this coloured beauty to provide correct i18n. I do it this way:
I see colored variable $packages, then text, then colored variable $ASKED_CATEGORY_I18N.
Text needs to modify to use plural form (package/packages). Below is not colored, but correct variant of i18n:
[c]eval_ngettext '$packages package installed of category: $ASKED_CATEGORY_I18N' \
'$packages packages installed of category: $ASKED_CATEGORY_I18N' $packages[/c]
Now, I can translate it to Russian:
[c]Form 1: В категории $ASKED_CATEGORY_I18N установлен $packages пакет.
Form 2: В категории $ASKED_CATEGORY_I18N установлены $packages пакета.
Form 3: В категории $ASKED_CATEGORY_I18N установлены $packages пакетов.[/c]
(To comparison I give you bad old form: [c]В категории $ASKED_CATEGORY_I18N установлен(ы) $packages пакет(а,ов).[/c])
Now I'm enjoy — program speak my language! And speak correctly!
But, how we can to keep colorized messages? I think, we can use some sort of markup. I proposed worked function in Mailing list (). Using this function, we can write example above in next form:
[c]emsg "$(eval_ngettext \
'<c 32>$packages</c> package installed of category: <c 34>$ASKED_CATEGORY_I18N</c>' \
'<c 32>$packages</c> packages installed of category: <c 34>$ASKED_CATEGORY_I18N</c>' \
$packages)"[/c]
And translations:
[c]Form 1: В категории <c 34>$ASKED_CATEGORY_I18N</c> установлен <c 32>$packages</c> пакет.
Form 2: В категории <c 34>$ASKED_CATEGORY_I18N</c> установлены <c 32>$packages</c> пакета.
Form 3: В категории <c 34>$ASKED_CATEGORY_I18N</c> установлены <c 32>$packages</c> пакетов.[/c]
We have colorized output again! And both correct i18n!
This function emsg() not too hard, it's only have some sed's, and can operate with different output forms (html, gtk, xterm).
Next, some examples to harden rules above
1. Before:
[c]repository_name="[/c][c]gettext \"Undigest\"[/c] $(basename $path)"
echo "$repository_name [c]gettext \"is up to date.\"[/c]"
1. After:
[c]undigest_path="$(basename $path)"
repository_name="$(eval_gettext 'Undigest $undigest_path')"
eval_gettext '$repository_name is up to date.'; echo[/c]
2. Before:
[c]eval_gettext "\$new_pkgs new packages on the mirror."; echo[/c]
2. After:
[c]eval_ngettext '$new_pkgs new package on the mirror.' \
'$new_pkgs new packages on the mirror.' $new_pkgs; echo[/c]
3. Before:
[c]echo -n "$pkgs "; gettext "installed packages scanned in"; echo " ${time}s"[/c]
3. After:
[c]eval_ngettext '$pkgs installed package scanned in ${time}s' \
'$pkgs installed packages scanned in ${time}s' $pkgs; echo[/c]
4. Hidden plural
4. Before:
[c]if [ "$blocked_count" -gt 0 ]; then
blocks=[/c][c]eval_gettext " (\$blocked_count blocked)"[/c]
fi
eval_gettext "You have \$upnb available upgrades\$blocks"
4. After:
Context of message "(xxx blocked)" is "package" or "packages", so there is one translation in English, but plural form in some other languages (singular or plural form of word "blocked" in other languages):
[c]if [ "$blocked_count" -gt 0 ]; then
blocks=$(eval_ngettext ' ($blocked_count blocked)' \
' ($blocked_count blocked)' $blocked_count)
fi
eval_ngettext 'You have $upnb available upgrade$blocks' \
'You have $upnb available upgrades$blocks' $upnb[/c]
Enjoy with your scripts, that follows standards and best practices!
Offline
Also installing glibc_locale might help 
Offline
Installing glibc-locale can help you write correct bash scripts? ;D
Offline
No, but it adds locale for several things 
Offline
Ok, now I'm reach my computer. I saw at noon that my letter to mailing list ( http://listengine.tuxfamily.org/lists.tuxfamily.org/slitaz/2012/05/msg00115.html ) have no attached files.
Forum & scn can't show structured sources, paste.slitaz.org don't work, so my function emsg here, in my Dropbox: http://dl.dropbox.com/u/47815386/emsg and testsuite here: http://dl.dropbox.com/u/47815386/test
Download them free, without any ad's 
I see that I'm only one interested in correct i18n. Or I do not write where I want to?
Well, with the silent agreement of the maintainers, I'll add a function emsg() to the libtaz.sh code, while leaving the existing functions for backward compatibility (Not create harm). And, of course, I do all these steps to complete and correct tazpkg i18n and translation into Russian.
Step by step, I want to see SliTaz better than ever.
Offline
I probably should get around to moving paste
Offline
Hi Aleksej,
This post is wonderfull but will be lost in the forum.... For me and this kind of official guide we should use the main website, static doc only modifiable by us and not any user on the wiki because this should be the official and only way to code (why I prefer html doc for cook, only one and official way to build packages).
Aleksej, can you make a pretty html page in devel/ or add this guide in http://www.slitaz.org/i18n.php ? I guess i18n.php is fine since it will not be translated because any translator should know English, I'm wrong ?
Oh and much of the change you talk about are of my code... At first I was using eval_gettext but finally used minimal strings in gettext and put vars outside such has:
gettext "Installed packages:"; echo " $pkgs"
This is to save chars in po files. But is not correct for some languages since $pkgs may be at the start or middle of the sentense. I will reuse eval_gettext...
Hugs,
- Christophe
Offline
Thanks, Christophe! 
I think, it's all about coding style, so, probably, I want to push it to devel section in a few next days. My English is terrible, so I really wanted of support of our english-speak contributors.
All that changes I implemented to tazpkg right now. Number of changes are big, and I not want to break them over several commits, but I can't fit between other tazpkg commits, and edit code again and again. Ok, probably I will break my big commit into small several commits.
And, we want to re-translate new strings (maybe only check fuzzy translations). As well as in the TazPanel. I don't know all the languages, and can't check all strings. Our translators help needed.
Offline
Pages: 1
[ Generated in 0.021 seconds, 7 queries executed - Memory usage: 1.55 MiB (Peak: 1.77 MiB) ]