[Internationalization] - on tools folder/files

Permalink Browser Info Environment
Hello, I m currently sending mail via an ajax script call on the tool folder.

But the T() function seems to not translate any of my sentence.

This is what I have in my code
$c = Page::getByID($_REQUEST['cId']);
Loader::model('section', 'multilingual');
$lang = strtolower(MultilingualSection::getCurrentSection()->getLocale());
echo t('trans : hello word');


The get Locale is returning the good language, the echo always return 'trans : hello word'

Thank you

Type: Discussion
Status: New
rubbik
View Replies: View Best Answer
mkly replied on at Permalink Reply
mkly
Localization::setLocale('sv_SE');
echo t('trans : hello word');
echo t('Cancel');


That said, do you have 'trans: hello world' in your po file?

Best Wishes,
Mike
rubbik replied on at Permalink Reply
rubbik
Hello Mkly,

Thanks for your response, nevertheless it's not working still the same ('trans : hello world'). It's of course in my PO file (the string is translate on a page juste before so I m sure it's working).

It's so weird, I went deeper, and on localizaion library I have :

function t($text) {
   $zt = Localization::getTranslate();
   if (func_num_args() == 1) {
      if (is_object($zt)) {
         return $zt->_($text);
      } else {
         return $text;
      }
   }


($zt in my case is not an object...) so it's returning the text itself.. still does not know why.

Best Regards
rubbik replied on at Permalink Reply
rubbik
so deeper

this code on any of my page return all the translation as it should :-) .
On the tools file it's empty.

Localization::setLocale('en_GB');
    print_r(Localization::getInstance());
mkly replied on at Permalink Best Answer Reply
mkly
Hello,
setLocale() is not a static method, so you might want to try this. I just tested this on my concrete5.6.1.2 development environment.

$loc = Localization::getInstance();
$loc->setLocale('sv_SE');
echo t('Cancel');


With the po file I downloaded from Transifex it displayed
Avbryt

I would make sure that the language pack is installed. Can you select Swedish in the Dashboard for the sites default language? You wouldn't need to do this for what we are doing, but it would confirm that the language pack is installed correctly and the site is finding it.

Best Wishes,
Mike
rubbik replied on at Permalink Reply
rubbik
Great thanks, It's working properly. as you said wrong call on getInstance() :-)

Best Regards
Xavier
mkly replied on at Permalink Reply
mkly
Indeed. Oops. Glad it's working for you now.

Best Wishes,
Mike
PulseTDI replied on at Permalink Reply
PulseTDI
I do not know why but this is not working for me. For one of the blocks I created I make an ajax call to a script in the tools folder and I am trying to get it to recognize the language or force it and nothing seems to work.

$loc = Localization::getInstance();
$loc->setLocale('pt_BR');
echo t('Model');


Just echos "Model" onto the page. If anyone has any ideas please help. I am debugging it right now to try and trace it down.
mkly replied on at Permalink Reply
mkly
Is the pt_BR language installed into your site?

Best Wishes,
Mike
PulseTDI replied on at Permalink Reply
PulseTDI
Yes. Through the multilingual and multilingual plus add-ons we have setup multiple languages. Everything gets translated every where that is wrapped in a t function except for any ajax calls to tools. None of their strings wrapped in t functions get translated. When the tools scripts are called they dont know what language is being used and I cannot seem to force it with the code I posted above.
mkly replied on at Permalink Reply
mkly
If you create a tools file with this,
$loc = Localization::getInstance();
var_dump($loc->getLocale());

What do you get?

Best Wishes,
Mike
PulseTDI replied on at Permalink Reply
PulseTDI
string(5) "en_US"
mkly replied on at Permalink Reply
mkly
$loc = Localization::getInstance();
var_dump($loc->getLocale());
$loc->setLocal('pt_BR');
var_dump($loc->getLocale());


Are you sure the Model is included in the concrete5 translations?

Best Wishes,
Mike
PulseTDI replied on at Permalink Reply
PulseTDI
So I finally figured it out. Thanks for your help. I had an override of localization.php. This override was removed though and I cleared the cache but it was still looking for the override for some reason. As soon as I copied the one out of the concrete directory and put it in the right doc root folder it started working. I have to figure out why the override did not clear but at least I its working.
mkly replied on at Permalink Reply
mkly
Good to hear.

Best Wishes,
Mike

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.