Forums / Developer / what is i18n

what is i18n

Author Message

santosh kumar

Saturday 29 November 2003 5:23:54 am

can any body help me out to explain i18n .
thank u
santosh

Arash Molavi

Sunday 30 November 2003 1:50:16 pm

i18n is the translation system.

Jo Henrik Endrerud

Tuesday 02 December 2003 6:52:38 am

i18n is used in the templates to create text that is different based on the language used on the site (the admin interface is an example of this).

If you write {'My string'|i18n('/some/block')} the template engine will look in the .ts file (translation file) for the current language for a block named '/some/block'. In this block it will look for a key called 'My string' and will return the value stated in the translation file. If no value for this key is found, the key it self is printed (this is the reason for UK English doesn't have a translation file)

Jo Henrik Endrerud | System Developer @ Seeds Consulting | http://www.seeds.no

Luis Cruz

Wednesday 28 January 2004 6:57:17 am

OK; I have some text in my templates that need to be translated to German. The above example for the i18n function makes sense, but I still have a few questions.

First, how does the system know when to use the German version versus the default translation (English in my case)? Is it done via the language encoding sent by the user's browser? For example, let's say I have {'My string'|i18n('/some/block')} in my template. If the browser sends [en-us] to the page, will it display 'My String', and if the browser sends [de] will it perform the i18n lookup?

Second, do I place my translations in {path to ezpublish}/share/translations/ger-DE/translation.ts?

Third, is there a document outlining the structure of the .ts files and how you modify them? And how does '/some/block' relate to that structure? From snooping around the admin console code, it appears that you call it via what is listed in the <name> tag in the context. However, this does not appear to be working for me. I added the following to ger-DE/translation.ts under the "design/standard/layout" context:

<context>
<name>design/standard/layout</name>
<message>
<source>Home Page</source>
<translation>Startseite</translation>
</message>
. . .

I then added this line to my pagelayout.tpl file for my siteaccess:

<a href="">{'Home Page'|i18n('design/standard/layout')}</a>

I then flushed all the caches. Changed my browser to send "de" as the primary/preferred language code, but the text still comes up "Home Page" rather than "Startseite".

Maybe I am missing some fundmental understanding of the system, so an application of the clue-by-4 followed by a "read this doc more closely" would not be unwarranted. :)

Marco Zinn

Saturday 31 January 2004 12:04:21 pm

Hi Luis,
I didn't try a multilinual site yet, there are others, who did this (successfully).

While the i18n function is used to translate string to different languages based on the .ts files, I think, you should NOT use this to translate your own strings in a template.
The .ts is part of the disctribution and is maintaned by ezSystems (or the translator guys is the community). But the strings in there "only" are string of the UI or of Template made by ezSystems.
You can modify/enhance it (look for "translating ezPublish" to get the Tools for this... you don't have to edit the XML), but in the next update, you changes will be overridden with the new .ts file.
I think, the system does not use multiple .ts files, so you cannot create a .ts file for your own strings (maybe this would be a good idea !).

As Lazaro has outlined, multilanguage sites usually use one siteaccess per language. So, the language is defined by the siteaccess. One siteaccess is the "default" and the use can swtich to other siteaccesses. Maybe you could read the browsers "preferred language" setting to auto-switch...
Now, every siteaccess can use it's own "design" and this will lead you to different templates (they are part of the design). So, finally, i guess, that you should use different templates for different languages.

If Lazaro has some other attempt, follow his, because he really did it.
I just want to mention, that you should not start to modify the original .ts files.

Marco
http://www.hyperroad-design.com

Guglielmo Celata

Monday 02 February 2004 11:01:13 am

Hi Marco,
I am setting up a multilingual site. What I am noting is:

A. If you use the i18n operator for a multilingual site, all of your changes are lost the next time you upgrade the system, unless you don't merge your changes and eZ crew's ones, which sounds impractical.

B. If, as you suggest, you rely on different templates in different directories, even if just for a single phrase, you have to change two (or even more) files every time you change the layout, which also sounds impractical.

A possible solution could be to add a parameter to the i18n operator.

{"sentence"|i18n("design/standard/myBlock", "myTranslation.ts")}
would use myTranslation.ts translation file, if found, in the very same directories where the original translation.ts file is looked for.

I am going with solution A, anyway. :-)

Eirik Alfstad Johansen

Monday 02 February 2004 11:20:57 am

Hi guys,

Please note that translations can be stored as extensions (extension/[extname]/translations) to prevent newer eZP distributions from overwriting your custom translations.

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Guglielmo Celata

Monday 02 February 2004 12:24:29 pm

Yup!
you're right.

Creating folder extension/<myext>/translations/ita-IT/translations.ts
and putting

<!DOCTYPE TS><TS>
<context>
<name>design/rightbar</name>
<message>
<source>site map</source>
<translation>mappa del sito</translation>
</message>
...
...
</context>
</TS>

into it, then
adding

TranslationExtensions[]=<myExt>
under [RegionalSettings] in settings/siteaccess/<mySite>/site.ini.append

will do the job, proven that the context specified in the i18n operator does not exist in the original translation.ts file.

Thank you very much Eirik