Translation cakephp not working
Asked Answered
G

3

10

I'm trying to implement a translation in Cakephp but isn't working and don't show me any erros.

I have this HTML in a element

<a href="/sites/pages/servicos" target="_blank">
    <span class="title">Serviços</span>
    <div class="description"><?php __('o que fazemos') ?></div>
</a>

In App Controller inside beforeFilter():

Configure::write('Config.language', 'eng');

In my folder locale/eng/LC_MESSAGES/default.po I have this:

msgid "o que fazemos"
msgstr "What we do"

But isn't working... Thanks

Guillemot answered 29/4, 2015 at 14:4 Comment(2)
What is the problem you're having? The string comes up as "o que fazemos"? Or you don't see anything? Are you sure your beforeFilter() method is being called for that specific view?Vantassel
This show "o que fazemos". The beforeFilter() is called in the App controller...Guillemot
W
3

I think you're just forgot "echo"

<?php echo __('o que fazemos'); ?>
Workman answered 29/4, 2015 at 14:34 Comment(1)
I've just baked fresh app, added your html into Views/Pages/home.ctp, configured 'Config.language' to 'eng' in beforeFilter and pasted your .po and nothing ... added the echo and the string 'What we do' is there .... last resort is that you element is cached, clear your caches in tmp/cacheHatfield
G
1

Have you correctly generated the i18n files with the ./cake i18n command?

Use PoEdit to edit your translate files, instead of doing it by hand if you've done so.

http://poedit.net/

Godden answered 2/5, 2015 at 15:43 Comment(0)
S
0
  • First of all, Did you generate the default.pot file by typing app\console\cake followed by i18n extract after having the full file in _() format?
  • Second, why did you put the Configure::write('Config.language', 'eng'); in App Controller instead of app\Config\core.php (recommendation). And as +JazzCat said as it is a .po file it is highly recommended to use poedit.

PS: you can set the language in AppController using session:

$this->Session->write('Config.language', 'en');
Soares answered 2/5, 2015 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.