Welcome Guest, Not a member yet? Register   Sign In
Advanced Translations?
#1

[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?
#2

[eluser]Unknown[/eluser]
gettext ?
http://pl2.php.net/gettext
#3

[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.
#4

[eluser]esra[/eluser]
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.
#5

[eluser]xwero[/eluser]
I haven't used the language functions of CI but the way i do it is to have a placeholder in the string
Code:
// 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.
#6

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

http://ellislab.com/forums/viewthread/57331/




Theme © iAndrew 2016 - Forum software by © MyBB