Yii Framework Forum: Translations :: variables instead - Yii Framework Forum

Jump to content

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

Translations :: variables instead Rate Topic: -----

#1 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 27 March 2012 - 01:58 AM

I was looking at how Yii does translations and really find having sentences instead of variables an issue.

Is there an alternative solution to over ride what the core does?

I'm thinking that all languages should be separate from the code.

So...
Yii:t('accounts', 'please click any new users you wish to remove')

To be honest, this is really hard to deal with for users who are not native speakers and it's very hard to change something on the fly.

Is it possible to change it to:
Yii:t('accounts', 'button_remove_new_user')?

You could then have:
title_xyz
text_xyz
button_xyz

Basically refer to everything like a variable. That way if I didn't want to use "Please click to remove any new users or any other offending dork users" I could just use "remove dork" :)
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 818
  • Joined: 02-July 10
  • Location:Central Poland

Posted 27 March 2012 - 04:52 AM

well, you can simply do this.

in config (main.php) specify:
'sourceLang'=>'var',
'language'=>'en',

and use variables as literals. sourceLanguage=var is just something that is for sure not used as another language so everytime yii will seek for translation file.
red
1

#3 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 27 March 2012 - 04:54 AM

Thanks for the answer!
This is gonna help a lot!

I'm on a huge g11n kick at the moment :)
0

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 27 March 2012 - 05:16 AM

View Postredguy, on 27 March 2012 - 04:52 AM, said:

well, you can simply do this.

in config (main.php) specify:
'sourceLang'=>'var',
'language'=>'en',

and use variables as literals. sourceLanguage=var is just something that is for sure not used as another language so everytime yii will seek for translation file.


Clever! Thanx for the idea.
0

#5 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 27 March 2012 - 05:46 AM

Does Yii convert the translations on the fly in the view or in the controller?

I read the dic on localization but it didn't mention when this occurs.

Which has got wondering about performance of translating on the fly.
0

#6 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 818
  • Joined: 02-July 10
  • Location:Central Poland

Posted 27 March 2012 - 07:35 AM

View PostSapporoGuy, on 27 March 2012 - 05:46 AM, said:

Does Yii convert the translations on the fly in the view or in the controller?

I read the dic on localization but it didn't mention when this occurs.

Which has got wondering about performance of translating on the fly.

Yii loads translation file first time Yii::t is called and there is no file loaded for current language. You can use Yii::t wherever you want (actions/widgets/views). Translation you have to provide on your own (there is "yiic message" command which helps to generate new translation files). There is however dedicated solution for translating views - if there is a subdirectory that match language and there is view file with same name - it will be used. Example:

you have such files structure:
/protected/views/site
     |- index.php
     |- en/
         |- index.php

then for english (en) /protected/views/site/en/index.php will be used. For any other language - /protected/views/site/index.php.
red
0

#7 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 27 March 2012 - 12:19 PM

Thanks for all the helpful information!
Now I have to give it a try!
0

#8 User is offline   Iqra 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 05-November 13

Posted 11 May 2014 - 11:51 AM

when I change this line of config/main.php to
'sourcelanguage'=>'ur'
its not working . i want this language how can i do plz tell me.
0

#9 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 11 May 2014 - 11:08 PM

View PostIqra, on 11 May 2014 - 11:51 AM, said:

when I change this line of config/main.php to
'sourcelanguage'=>'ur'
its not working . i want this language how can i do plz tell me.

'sourceLanguage'=>
is what you wrought the app in.

'language'=>
is what you want the app to display in.
Do, or do not. There is no 'try.' Jedi Master Yoda
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