• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Advanced Translations?

[eluser]Tom Vogt[/eluser]
I've just started working with CI, and I'm wondering about the translation engine:

How do I do translations beyond simple string replacements?

Imagine I have a page that says something like:

"You have 123 new messages."

Obviously, in different languages, the sentence structure would be different, so just splitting it into something like $lang['You have'].$Number.$lang['new messages'] wouldn't work.

So how do I do it in CI?

gettext ?

[eluser]Tom Vogt[/eluser]
Yeah, I know about gettext. I was wondering if there's a plugin, helper, library or anything to include gettext (whatever implementation) in CI.

There is a Language extension and Language Select class posted on the forums and possibly on the wiki. It basically allows the user to switch between languages. I believe that this contribution was due to be merged into the Kohana fork.

If you're interested in a solution for switching between languages based on IP addresss and its associated locale, you might take a look at how this was handled in the Rapyd library for CI.

You can roll your own Language extension and store a current language value in a session. I believe this has been discussed elsewhere on the forums.

I haven't used the language functions of CI but the way i do it is to have a placeholder in the string
// language files
$some_string_en = 'You have [NUMBER] new messages.';
$some_string_nl = 'U hebt [NUMBER] nieuwe berichten.';
// controller
echo strtr($some_string_lang,'[NUMBER]',123);

Maybe it should be build in somewhere in the functions to recognize placeholders.

[eluser]Armchair Samurai[/eluser]
This was also recently discussed here:


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.