Search code examples
staticinternationalizationtranslationcakephp-3.0behavior

How to use Translate behavior and .po file to change dynamic text Cakephp3?


I'm using translate behavior in cakephp 3 using I18n table. Everything is working fine. But if I use .po file to translate static text the content coming from the database won't change.

Can you please help me how to use both Translate behavior and .po file to change dynamic and static text. I used the following code for the translation:

echo  __($name);

Thanks in advance


Solution

  • I have resolved this using __d() function. This allows you to override the current domain for a single message lookup.

    Use __d(<your variable>, <domain>);

    For example

       echo  __d($name, 'default');
    

    default is your .po filename;