Yii Framework Forum: Failed to get i18n working.... please help - Yii Framework Forum

Jump to content

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

Failed to get i18n working.... please help Rate Topic: -----

#1 User is offline   mlindhout 

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

Posted 14 January 2010 - 03:55 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

#2 User is offline   Nique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 10-May 09
  • Location:the Netherlands

Posted 14 January 2010 - 09:57 AM

Same problem here..

It just doesnt work.
0

#3 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 14 January 2010 - 10:01 AM

Yii::t() only returns its result, so you need to echo it yourself:
<h1><?php echo Yii::t("general", 'Aanmelden'); ?></h1>

Or was that just a trivial copying error?
0

#4 User is offline   mlindhout 

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

Posted 14 January 2010 - 10:07 AM

Ouch....! That as a stupid one.... Now my PHP-stupidity is exposed ;-)

thanx!
0

#5 User is offline   Nique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 10-May 09
  • Location:the Netherlands

Posted 14 January 2010 - 10:07 AM

View PostSander, on 14 January 2010 - 10:01 AM, said:

Yii::t() only returns its result, so you need to echo it yourself:
<h1><?php echo Yii::t("general", 'Aanmelden'); ?></h1>

Or was that just a trivial copying error?


I'm having

<?php echo Yii::t('newsModule.articles', 'news'); ?>


Inside my view file and it does absolutely nothing than printing 'news' to the screen. Even when i have set the app()->sourcelanguage to 'en' and the app()->language to 'nl'. The language file is stored in: "/modules/news/messages/nl/articles.php".

I can call the module.. it displays news.. but the translation doesnt work. (i'm sorry i do post this inside this topic because i'm having exact the same problem.

The "/modules/news/messages/en/articles.php" file:
<?php
return array(
	'news' => 'news (english)'
);


The "/modules/news/messages/nl/articles.php" file:
<?php
return array(
	'news' => 'nieuws'
);


It prints "news".. so it doesnt translate, otherwise, if i misconfigured something it should print "news (english)".

----------------------

I figured out my self. I had to put the Messages folder inside the /modules/news map. not in a application map, now it's working

Ciao
0

#6 User is offline   mlindhout 

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

Posted 14 January 2010 - 10:14 AM

Hi Nique,

The key must be a translated message! That's the cool thing in Yii, you don't have to write message resources if your targetLangue and source language are the same.

Your articles.php should contain:

<?php
return array(
'nieuws' => 'nieuws'
);

?>

But you even don't need a dutch message bundle, if you set sourceLanguage and language to 'nl' in the main.php config (like I do).

Regards
0

#7 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 14 January 2010 - 10:22 AM

Hmm, that's a more tricky one, Nique. I'm not really sure how to do that in a module, If I try your way (which is also in the guide, I noticed) and call `yiic message`, the translation files are placed in the protected/messages directory instead of protected/modules/yourmodule/messages. That may be your workaround for now (just edit the files in that directory, Yii will probably pick them up), but I too like to know how to actually put the generated message files in the correct module directory..
1

#8 User is offline   Nique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 10-May 09
  • Location:the Netherlands

Posted 14 January 2010 - 10:41 AM

It works for now.

i placed the messages inside /modules/news/messages/nl/articles.php

I know what you mean mlindhout, but i want to keep the source language of my application English. So i create a dutch translation set. I want to keep all options open (for the future). If developpers from other countries are going to edit the source files, they dont need to translate the word: aanmelden and find out what it means in english. English is the worlds main langauge. Thats why i want the sourcelanguage to be english :P

Anyway thanks.

I have a tricky folder setup.

/app/frontend/.. contains all 'frontend' stuff (controllers, views etc)
/app/backend/.. contains all 'backend' stuff (controllers, views etc)
/app/shared/.. contains all 'shared' stuff. (models, shared configs) i want to put the messages in here but that wont work)
/app/modules/.. contains all the modules

/app/modules/news/.. looks like:
/app/modules/news/frontend/..
/app/modules/news/backend/..
/app/modules/news/shared/..
/app/modules/news/modules/..
/app/modules/news/messages.. (i want this inside the shared folder.. but okay)
/app/modules/news/newsModule.php (the module class)
(later i want to add installation files etc)
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