2
votes

I have a question regarding i18n default plugin for CakePHP 2.5.

I know there's a possibility to translate short strings just by placing them between __('') notation.

I also know there's a possibility to translate all model-related text by adding TranslateBehaviour to model.

The problem begins when I want to translate longer portions of text on many different pages. I could make different views for different languages but it kinda collides with MVC pattern.

Let's say we've got a text we'd like to translate to other languages:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sagittis urna augue, a eleifend orci ultrices eget. In iaculis mi mauris, eget luctus leo condimentum at. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla tristique commodo tortor, non condimentum risus egestas sed. Proin ultricies elit vitae mauris pretium facilisis. Fusce aliquam orci sed neque feugiat vestibulum. Etiam dapibus massa vel dui interdum malesuada. Nunc fringilla vulputate tristique. Sed ultrices suscipit erat eget luctus. Quisque non massa ante. Fusce volutpat neque sed rhoncus sollicitudin. Cras porta vulputate neque non congue.

How do I pack text this long to make it work with i18n? How can I keep it clean in my code?

1

1 Answers

4
votes

The __() is not limited to short strings, you could also use an identifier inside your views if you want to keep it clean, something like:

<p>
    <?php echo __('long-text'); ?>
</p>

And in your po file you make the translations:

//app/Locale/eng/LC_MESSAGES/default.po
msgid "long-text"
msgstr "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sagittis urna augue, a eleifend orci ultrices eget. In iaculis mi mauris, eget luctus leo condimentum at. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla tristique commodo tortor, non condimentum risus egestas sed. Proin ultricies elit vitae mauris pretium facilisis. Fusce aliquam orci sed neque feugiat vestibulum. Etiam dapibus massa vel dui interdum malesuada. Nunc fringilla vulputate tristique. Sed ultrices suscipit erat eget luctus. Quisque non massa ante. Fusce volutpat neque sed rhoncus sollicitudin. Cras porta vulputate neque non congue."

This will output the long strings, but your views will be clean.