1
How XOOPS works now:
Directory structure:
modules/dummy/language/english/
modules/dummy/language/portuguese/
modules/dummy/language/pt_utf8/
Inside each language file we can find translations like this:
first %s is replaced by sitename and second %s by number of users
english:
define('_MA_DUMMY_USER', "User");
define('_MA_DUMMY_USER_REG', "Hi, %s has already %s users registered);
portuguese:
define('_MA_DUMMY_USER', "Usuário");
define('_MA_DUMMY_USER_REG', "Olá, %s já tem %s usuários registados);
pt_utf8:
define('_MA_DUMMY_USER', "Usuário");
define('_MA_DUMMY_USER_REG', "Olá, %s já tem %s usuários cadastrados);
Configuration in system module:
Choose default language from (english, portugese...)
Usage on files:
echo _MA_DUMMY_USER;
echo sprintf(_MA_DUMMY_USER_REG, $xoopsConfig['sitename'], $number);
How it works:
Xoops takes the default language from system preferences and checks if the translation file exists.
If does not exist then uses the english language.
Problems:
-If translation misses one line then we get an error on debug and translation for that expressions is replaced by the DEFINE key.
-We cannot use translation in portuguese and in english on same page.
- We cannot change the order of the translation arguments
-------------------------------------------------------
My proposal:
Directory
modules/dummy/language/en/
modules/dummy/language/pt/
modules/dummy/language/pt-br/
en:
define('_EN_MA_DUMMY_USER', "User");
define('_EN_MA_DUMMY_USER_REG', "Hi, {0} has already {1} users registered);
pt:
define('_PT_MA_DUMMY_USER', "Usuário");
define('_PT_MA_DUMMY_USER_REG', "Olá, {0} já tem {1} usuários registados);
pt-br:
define('PT-BR_MA_DUMMY_USER', "Usuário");
define('PT-BR_MA_DUMMY_USER_REG', "Olá, {0} já tem {1} usuários cadastrados);
Configuration in system module:
Choose default language from (pt, pt-br...)
Choose language fallback order: pt then pt-br then en
Usage on files:
echo _xt('_MA_DUMMY_USER');
echo _xt('_MA_DUMMY_USER_REG', array($xoopsConfig['sitename'], $number));
Other possible use to force a translation in other language:
echo _xt('_MA_DUMMY_USER', null, 'pt-br');
function can be like this:
function _xt($string, $arguments=null, $language=null)
How it works:
Module includes translation file given in config or by the function
If file does not exists or translation for that string is not present then it loads other language file has given in system config.
Advantages:
-Since defines are prefixed then we can include several language files with no conflict. So if a define is missing for a string then it will try to use other file and, at the end, it uses english translation.
We can change order of arguments like:
define('_EN_MA_DUMMY_USER_REG', "Hi, {0} has already {1} users registered);
into:
define('_EN_MA_DUMMY_USER_REG', "Hi, we have {1} users registered in {0}!' );
We don't need to make complete translations for languages that differ very little.
We just need to change the lines that differ.
If I use pt as default language and have a fallbackk to pt-br, I may want to have just this line:
define('_PT_MA_DUMMY_USER_REG', "Olá, {0} já tem {1} usuários registados);
and leave the other for the fallback mechanism to handler.
Also, when a module is updated and new definitions are added, the worst it can happen is we have missing definitions translated in english!
If we want to change something in the original translation files, we can create a language folder called 'default', then just add the lines we want to change there. This way everytime we update the module we do not have to redo everything. We just need to use 'default' has default language and have it fallbacking to the original language.
So for me, the fall back could be something like:
default
pt
pt-br
en
I would not touch the original translation, I would only make necessary changes in my default folder!
I'm not sure if you understand the idea, just ask if you don't.
My english is very bad today, lol