Internalization

Hello guys! I read the section in the documentation. I got confused by the big amount of information and different examples given.

I got the section about the different between source and target language. This is valid for me, the source language is English, but the site will be fully in Bulgarian and there won't be other language.

What should I do?

Can I just assign the target language at the config file and use one single language file for the entire website or I should somehow put for each view translation, and what is the correct format?

If your site is using single language, you don't need to touch language and sourceLanguage since no translation need to be done. If you want to use the i81n date or number formatter, then you may set both languages to your language.

Yes, but even though, how could I translate things? I mean, the core messages. Where to specify that I want the language to be Bulgarian. Soon, or later, I will finish translating core messages in bulgarian and will use them in my site. The actual question is where to specify the current language used. In application config, but how?

Please check this page: http://www.yiiframew…doc/cookbook/1/

If you want to make use of the core message translations, then you have to set source language as English and (target) language as Bulgarian so that automatic translation can occur.

Yes, and I set this in Yii config?

app config.

Ok, I copied the file I am translating under messages\bg\yii.php

I translated the string "Please fix the following input errors", because it's easy to test whether Yii recognizes the translation file.

My config file looks like this:



return array(


	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


	'name'=>'My Web Application',


	'language'=>'bg',


What am I missing?

Did you forget the colon at the end of the message? This should work.



return array(


	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


	'name'=>'My Web Application',


	'language'=>'bg',





	// preloading 'log' component


	'preload'=>array('log'),





	// autoloading model and component classes


	'import'=>array(


		'application.models.*',


		'application.components.*',


	),


This is the entire array, I don't see to have made a mistake.

And in the messages folder I have \bg\yii.php

Ok, I have resolved this. It seems that I can't put under current site\protected\messages, but I must put it under framework\messages\bg

Doesn't the first one override the framework's messages?

protected/messages are used to store application messages whose category is not 'yii'.

Lol, Qiang, seem to have found an issue, or I simply can't configure it.

First of all, I can't use different characters from latin in name of label.



<?php echo CHtml::activeLabelEx($users,'ASFSAF'); ?> // works


<?php echo CHtml::activeLabelEx($users,'Потребителско име'); ?> // doesn't work(outputs encoding-unfriendly characters :) )


<?php echo CHtml::activeTextField($users,'USERNAME'); ?>


Also, is there a way to specify {attribute} manually. I will tell you why:



Полето Username не може да бъде празно.


This is a translation of:



Field(my addition) Username cannot be blank).


But "Username" remains so, even when I translate the other words in Bulgarian. Is there a way it to be equal to the name of the label(if I succeed writing it in Bulgarian).

Qiang, I reconsidered this and it really seems a separate problem, having little similarity to the above one.

Should a create a new topic. I don't want to create a ticket unless you've said that this is a bug or something, because I may be wrong.

The question two questions that stay are:

  • Can I use non-latin characters in label titles and how to do it properly?
  • How to localize field names and could I somehow assign the value of the label to them,  because it is the most logical thing to do.

The second parameter of activeLabelEx must be an attribute name, not its label. An attribute name can only contain ASCII characters because it can be used like a PHP variable.

To customize attribute labels, you need to override attributeLabels() method in your AR class.

Thanks Qiang, this was the solution. I was lucky to see that my errors consist of the assigned value, not the field name, because this could have caused many troubles.