4 ms·
MediaWiki is one of those websites that is translated into nearly every language known to humans, and it has a pretty elegant system for this. Not perfect, but
by neilk 16y ago
MediaWiki is one of those websites that is translated into nearly every language known to humans, and it has a pretty elegant system for this. Not perfect, but good enough for almost anything. You can get away with minimal markup in the lexicon this way:
* In the code, messages are specified abstractly, e.g.
print getMessage('found_x_files_in_x_dirs', $fileCount, $dirCount);
* Languages each have their own class with a 'convertPlural' function that maps the quantity to the forms. So in english, that function might be simple, for Arabic, it's complex: http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/languages/classes/LanguageAr.php http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/lang...
* Lexicons use a simple wiki markup to define the different forms of their language. To illustrate that the arguments don't have to be used in order, I did it in the reverse of how the code passes arguments.
'found_x_files_in_x_dirs' =>
"I searched $2 {{PLURAL:$2|directory|directories}}
and found $1 {{PLURAL:$1|file|files}}"
So for a language like Arabic you write a similar pipe-delimited list of forms. You just have to know how to lay down the six different forms in the order that LanguageAr.php defined.
Note how this side-steps most (but not all) complicating issues like case or gender, so you don't have to mark it that way in the lexicon. If the word is used in the feminine gender, accusative case plural in the sentence, that's what the translator writes.
All this is mediated with the amazing http://translatewiki.net/ http://translatewiki.net/ website, run mostly by volunteers.