Yii Framework Forum: Using translations in form labels - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Using translations in form labels Rate Topic: -----

#1 User is offline   manilodisan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 17-September 09
  • Location:Bucharest

Posted 18 September 2009 - 03:04 PM

How do I use translations in form labels?

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

0

#2 User is offline   jayrulez 

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

Posted 18 September 2009 - 03:09 PM

View Postmanilodisan, on 18 September 2009 - 03:04 PM, said:

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
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   manilodisan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 17-September 09
  • Location:Bucharest

Posted 18 September 2009 - 03:16 PM

View Postjayrulez, on 18 September 2009 - 03:09 PM, said:

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
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,898
  • Joined: 04-October 08
  • Location:DC, USA

Posted 18 September 2009 - 03:26 PM

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

#5 User is offline   jayrulez 

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

Posted 18 September 2009 - 03:45 PM

View Postmanilodisan, on 18 September 2009 - 03:16 PM, said:

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



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
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

#6 User is offline   manilodisan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 17-September 09
  • Location:Bucharest

Posted 18 September 2009 - 04:09 PM

View Postqiang, on 18 September 2009 - 03:26 PM, said:

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

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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