Kerim
Kerim

Reputation: 231

Why I can't translated message with id in Symfony 3

I am newbie for Symfony. I am trying translate some message for some languages. I can do it with message like 'Syfony is great'. Now I want to do for id like id='hello_message'.

My index.twig at below

{% block body %}
<p>{{'hello_message'|trans}}</p>
{% endblock %}

My xliff file at below

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
    <body>
        <trans-unit id="hello_message">
            <source>hello.message</source>
            <target>Symfony Harika!</target>
        </trans-unit>
    </body>
</file>

And my default controller just call twig

    public function indexAction(Request $request)
{
    return $this->render('default/index.html.twig');
}       

Upvotes: 0

Views: 434

Answers (2)

Nguyen Nhu Tuan
Nguyen Nhu Tuan

Reputation: 21

With Symfony 3 you use attribute resname. Example:

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file original="global" datatype="plaintext" source-language="en" target-language="vi">
        <body>
            <!-- COMMONS -->
            <trans-unit id="common_say_hello" resname="common_say_hello">
                <source>Hello</source>
                <target>Xin chào</target>
            </trans-unit>            
        </body>
    </file>
</xliff>

{{ 'common_say_hello'|trans }}

Output Xin chào

Upvotes: 0

devilcius
devilcius

Reputation: 1884

It's the source that get translated, not the id:

{% block body %}
<p>{{'hello.message'|trans}}</p>
{% endblock %}

Also, remember to clear the cache if you're in prod environment.

Upvotes: 2

Related Questions