Using translations in form labels

How do I use translations in form labels?


<?php echo CHtml::activeLabel($user,'name'); ?>

wherever you define the label just put use Yii::t(‘translation_category’,‘label_name’);

Yii::t is static so it is avalaible at all places in your extension of Yii.

just a suggestion, you could post a compiled list of your issues and we will try to help you with it in one topic

Thank you @jayrulez. I can’t post compiled lists as I need to figure things out step by step. One whole leads to another and the same with the topics. Can you make a list of things you won’t know next week? :))

Anyways, other users searching for the same thing will benefit more from divided/targeted topics rather than lists.


<?php echo CHtml::activeLabel($user,'name'); ?>

produces the label itself so I don’t have a place to use the Yii::t method other than this:


<label><?=Yii::t('bla')?></label>

but this way I use the functionality of CHtml::activeLabel

You can translate the labels in your model’s attributes() function, something like: ‘attributeName’=>Yii::t(‘category’, ‘attribute label’)

It produces itself because that’s the source language. If you are going to translate the form labels to other languages using Yii i18n implementation then you will need to use Yii::t

Thank you @qiang and @jayrulez, I think that’s the perfect answer.