Yii Framework Forum: Internationalization - what to put on views for same source and target language - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Internationalization - what to put on views for same source and target language Rate Topic: -----

#1 User is offline   cass 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 01-February 09
  • Location:London, UK

Posted 07 November 2009 - 03:40 AM

Hello all,

We are writing an application that will use i18N for internationalization.

From the docs, I understand that translation only happens when Source and Target language are different and from that angle I could make my app work as instructed.

I created the translations under /protectec/messages/my_language/main.php and on my view, I used

<?php echo Yii::t("main","FRONTPAGETITLE");?> which worked like a charm.

My query is about what to put on views if both source and target languages are the same as if I use the above code, the view will end up displaying FRONTPAGETITLE.

Many thanks,

Cass Surek
0

#2 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 07 November 2009 - 03:33 PM

View Postcass, on 07 November 2009 - 03:40 AM, said:

Hello all,

We are writing an application that will use i18N for internationalization.

From the docs, I understand that translation only happens when Source and Target language are different and from that angle I could make my app work as instructed.

I created the translations under /protectec/messages/my_language/main.php and on my view, I used

<?php echo Yii::t("main","FRONTPAGETITLE");?> which worked like a charm.

My query is about what to put on views if both source and target languages are the same as if I use the above code, the view will end up displaying FRONTPAGETITLE.

Many thanks,

Cass Surek


I have seen quite a few people using Yii::t() incorrectly.

If your front page title is "Hello World", in your view you should put Yii::t('category','Hello World');, not Yii::t('category','helloworld');, the second parameter for Yii::t() is not a placeholder but the actual text that will be outputted for your source language.

To translate to other languages, in the file under protected/messages/locale Id/ where locale Id is the Id of your language eg: zh_cn, you'll have something like
return array(
...............,
'Hello World'=>'世界您好',
.............);

php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#3 User is offline   Zoltan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 19-October 09
  • Location:Budaörs, Hungary

Posted 12 November 2009 - 03:05 PM

I note that even if one uses the Yii::t() correctly - i.e. with real texts and not placeholders - the problem mentioned by Cass is still valid!

E.g. I am developing a product that will be installed in many instances (well, hopefully) and this may put the application into different contexts. Let's assume that a funny guy installs it who wants to change the following system message:

{attribute} cannot be blank

this way:

{attribute} is mandatory! Enter something or else...

Note that this is not really a translation - this is customization. I want to make it possible that my end users can easily change the application messages even if they "translate" them just from English to English! The obvious way to change these messages if they find them in the source and change there - but it is neither easy, nor nice. I would call it "easy" when the messages were read from language files even if no translation occurs, but this is currently not so in Yii!

I have applied the following workaround to achieve my goal:

main.php
// CWebApplication properties can be configured here.
return array(
    ...
    'sourceLanguage'=>'xyz',
    'language'      =>'en',
);

'xyz' is a non-existing language - it is only necessary to "force" the translation from the real source language (English) to the target language which I have also explicitely specified above (English).

Now, if I create the 'framework/messages/en/yii.php' file with the following content:

return array(
    ...
    '{attribute} cannot be blank.'=>'{attribute} is mandatory! Enter something or else...',
    ...
);

it will "translate" the system message to the silly one. Of course, this trick will be also applicable to other application messages - not only to system messages.

So that someone can keep all the program messages in language files (or in DB) even if they are not a subject of any translation, it may be a useful feature. And a native support for that in Yii without the necessity of applying the above workaround might make sense in my opinion.
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 November 2009 - 11:32 PM

View PostZoltan, on 12 November 2009 - 03:05 PM, said:

I would call it "easy" when the messages were read from language files even if no translation occurs, but this is currently not so in Yii!


True. For me, the i18n implementation is the only negative part of Yii I've noticed. But it's easy to write an own component, so no big deal. Still, would be cool if this could find the way into core..
0

#5 User is offline   ekerazha 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 524
  • Joined: 10-October 08
  • Location:European Union

Posted 15 November 2009 - 08:29 AM

View PostY!!, on 12 November 2009 - 11:32 PM, said:

True. For me, the i18n implementation is the only negative part of Yii I've noticed. But it's easy to write an own component, so no big deal. Still, would be cool if this could find the way into core..


Open a ticket http://code.google.c...yii/issues/list
Yii user #37
0

#6 User is offline   mlindhout 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 13-January 10

Posted 14 January 2010 - 03:52 AM

Hello,

I'm trying for 2 days to get i18n working, read all posts, guides and api docs, and still the most simple case doesn't work. I did this:

set the language and sourceLanguage in controller and main.php to 'nl' Created a general.php under protected/messages/nl with this content:

return array(
'Aanmelden'=>'Aanmelden',
);

And used this in the login.php (from the generated skeleton app)

<h1><?php Yii::t("general", 'Aanmelden'); ?></h1>

And still no label is displayed....

Please help, what's missing? :-(
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users