Question

I have started using the translation system in Symfony2.

All works very well.

However I have one question about best practice when it comes to referencing the source / target string from a twig view file.

Given this:

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="file.ext">
    <body>
        <trans-unit id="1">
            <source>Short String</source>
            <target>Short String</target>
        </trans-unit>

        <trans-unit id="2">
            <source>Some really long string for example a paragraph about some random thing that is likely to change in the future</source>
            <target>Some really long string for example a paragraph about some random thing that is likely to change in the future</target>
        </trans-unit>       

    </body>
    </file>
</xliff>

No problems using like:

{% trans_default_domain 'messages' %}

<h3>{{ 'Multicoin Cryptocurrency Online Wallet' | trans }}</h3>

<p>{{ 'Some really long string for example a paragraph about some random thing that is likely to change in the future' | trans }}</p>

I know you can in the source section use short source references like:

<trans-unit id="2">
            <source>page.long.paragraph</source>
            <target>Some really long string for example a paragraph about some random thing that is likely to change in the future</target>
</trans-unit> 

Which makes the twig part much cleaner:

{% trans_default_domain 'messages' %}

<h3>{{ 'Multicoin Cryptocurrency Online Wallet' | trans }}</h3>

<p>{{ 'page.long.paragraph' | trans }}</p>

The question is if I want to give the original en translation file to a translator to translate into another language it would be far better to have the whole string that needs to be translated in the field. However that makes the twig code rather untidy. Is there another way to reference the translations string in twig without having to use the whole source string?

Was it helpful?

Solution

No, you only have 2 options: Real messages or keyword messages.

And yes, keyword messages doesn't work that easy if you are adding a new language. And Xliff doesn't have a good support for it. That's the reason why you see the real messages being used when using Xliff files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top