1
trabis
languages on xoops 2.4 - an idea
  • 2009/5/15 14:38

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 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












2
bumciach
Re: languages on xoops 2.4 - an idea
  • 2009/5/15 17:08

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


I understand... I think (my english is bad too...not only today) ;)
The idea is very interesting!
But what about backward compatibility?

3
demian
Re: languages on xoops 2.4 - an idea
  • 2009/5/17 12:54

  • demian

  • Quite a regular

  • Posts: 225

  • Since: 2008/4/29


nice good idea... !! ..yes backward compatibility is important

Login

Who's Online

309 user(s) are online (187 user(s) are browsing Support Forums)


Members: 0


Guests: 309


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits