Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 translation of long texts

Tags:

Since a few weeks I started playing with Symfony2. It seems a very powerful framework, but there are some things I cannot still understand.

In documentation I see that i18n (i.e. Translations) is managed by the Translator service. If I correctly understood, the main way to have a website translated is to put the collection of messages I want to translate inside the different files messages.XX.yml (XX=en,fr,it,etc...), one for each language.

This could be perfect for short texts, which possibly do not include any HTML markup. But how do you deal with long text? For instance, how can I manage the translation of a Terms Of Service or an About page?

I guess I should include different templates for each locale I want to use. Am I right?

Thanks for your help!

like image 612
Andrea Avatar asked Mar 26 '12 18:03

Andrea


People also ask

How do I translate a long text?

Google Translate It's very simple to use, and allows for instant translation of text, websites, images, and videos from one language to another. You can translate single words or entire phrases and paragraphs. Google Translate is available for over 100 languages, and is completely free to use!

Why is a translation generally longer than the original text?

Another reason why this happens (especially in technical and specialized areas) is because the translator is unaware of the subject and tries to paraphrase, instead of using a single term as in the original text. When we confuse translating with explaining, the length of the translated text increases.

Which text is the text that is to be translated?

In translation, a source text is the original text that is to be translated into another language.

Is a translation of a text a different text?

Translation is the transmittal of written text from one language into another. Although the terms translation and interpretation are often used interchangeably, by strict definition, translation Refers to the written language, and interpretation to the spoken word.


2 Answers

You can have long texts in .yml translation file as well as html tags. Put your Terms Of Service text in messages.xx.yml file like this:

TermsOfServiceText: >   <p>Here goes my Terms of service code</p>   <p>It can be put in several lines and <strong>can include html tags!</strong></p>   <p>It can also include <a href="http://symfony.com/doc/current/book/translation.html" rel="nofollow">links</a></p>   <p>Just make sure that you put '>' sign after your translation keyword like in the first line of this example code    and start your message in next line with double space indentation</p> 

Now, in your twig template call translation with this:

{{ 'TermsOfServiceText'|trans|raw }} 

raw is used to skip escaping html tags.

like image 128
Kosta Avatar answered Oct 24 '22 04:10

Kosta


I don't think that different templates could be as solution. But feel free to choose what you prefer. I'll go with https://github.com/stof/StofDoctrineExtensionsBundle in particular with the Translatable behaviour.

like image 25
Polmonino Avatar answered Oct 24 '22 05:10

Polmonino