Yii Framework Forum: Yii::t() - Yii Framework Forum

Jump to content

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

Yii::t()

#1 User is offline   JoniDS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-March 14

Posted 27 March 2014 - 09:52 AM

I have a doubt about Yii::t.

I know the standard way to declare a translation is for example for the file messages/pt-PT/main.php
return 
[
"Login here" => "Entrar"
];


If the app language is en-US it will display "Login here" if it's pt-PT it will display "Entrar".

But suppose I want the same phrase to have different translations in portuguese:
"Login" => "Entrar",
"Login" => "Iniciar sessão"


So what I thought was to create a en-US.php file with for example:
"login" => "Login",
"login2" => "Alternative login"


But it doesn't work, it never reads from the en-US.php file and always outputs "login" and "login2".

Why if the default language is en-US and I have a folder messages/en-US the files there are not used?

Thanks
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 27 March 2014 - 10:24 AM

I'm not quite sure what are you talking about. Mine works.
Default language (that is, when no language is set in config) seems to be just 'en'.

PS.

Quote

So what I thought was to create a en-US.php file with for example:


Probably you meant '/en-US/main.php' file?
God is real unless declared as integer
0

#3 User is offline   JoniDS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-March 14

Posted 27 March 2014 - 10:31 AM

View PostORey, on 27 March 2014 - 10:24 AM, said:

I'm not quite sure what are you talking about. Mine works.
Default language (that is, when no language is set in config) seems to be just 'en'.

PS.


Probably you meant '/en-US/main.php' file?


I mean if you have a file "messages/en-US/main.php with:

"login" => "Login"


and "language" => "en-US" in main.php

Yii::t("main", "login")

will print
'login' when it should print 'Login'
0

#4 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 27 March 2014 - 11:04 AM

Hmm.
Maybe something's wrong in your installation or config.

Mine looks like this:

'i18n' => [
    'translations' => [
        'app' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@app/messages',
        ],
        'label' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@app/messages',
        ],
    ],
],


So if I create messages/en-US/app.php and set language to en-US, all Yii::t('app', 'my_message') are translated correctly.
God is real unless declared as integer
0

#5 User is offline   JoniDS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-March 14

Posted 27 March 2014 - 06:02 PM

View PostORey, on 27 March 2014 - 11:04 AM, said:

Hmm.
Maybe something's wrong in your installation or config.

Mine looks like this:

'i18n' => [
    'translations' => [
        'app' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@app/messages',
        ],
        'label' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@app/messages',
        ],
    ],
],


So if I create messages/en-US/app.php and set language to en-US, all Yii::t('app', 'my_message') are translated correctly.


Found it


     'i18n' => array(
            'translations' => array(
                'app*' => array(
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => "@app/messages",
                    'sourceLanguage' => 'en-US',
                    'fileMap' => array(
                        'app' => 'app.php',
                        'app/common' => 'common.php',
                        'app/countries' => 'countries.php',
                        'app/menu' => 'menu.php'
                    )
                ),
            )
        ),



The problem was with "sourceLanguage", once I commented it, everything worked as expected.
Anyway, thanks for your help.
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