Reputation: 1159
Before I asked this question, I've carefully checked many similar ones on stackoverflow, but haven't solved it anyway.
The task is to use russian messages instead of english. Lets assume it in the case of well known authentication failure message "Bad credentials". So here is what I did.
In my config:
translator: { fallback: en }
default_locale: ru
Created messages.ru.xliff
<?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>Bad credentials</source>
<target>My russian variant here</target>
</trans-unit>
</body>
</file>
</xliff>
And finally, in my login.html.twig:
{% if error %}
<div class="error">{{ error.message | trans }}</div>
{% endif %}
When authentication fails, I still continue to receive "Bad credentials" message. I tried to clear the cache, but it doesn't help.
Maybe I missed something. Any help appreciated. Thanks.
Upvotes: 2
Views: 285
Reputation: 11364
I guess the problem is because you specified source translation as "Bad credentials" but you use "error.message" as input for the translator. So your messages.ru.xliff should look more like:
<?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>error.message</source>
<target>My russian variant here</target>
</trans-unit>
</body>
</file>
</xliff>
Or change message label in your template:
{% if error %}
<div class="error">{{ "Bad credentials" | trans }}</div>
{% endif %}
Upvotes: 1