Reputation:
I'm trying to use symfony translations. Here is my translation.yml
framework:
default_locale: 'en'
translator:
paths:
- '%kernel.project_dir%/translations'
fallbacks: ['en']
I have created messages.en.yml in translations directory.
## YAML Template.
Home: Home
Admin: Admin
Dashboard: Dashboard
Vehicles: Vehicles
Id: Id
But when I try to use like this,
{% trans %}Dashboard{% endtrans %}
I get this error message,
These messages are not available for the given locale and cannot be found in the fallback locales. Add them to the translation catalogue to avoid Symfony outputting untranslated contents.
Upvotes: 5
Views: 7087
Reputation: 543
A locale consists of 2 parts (language and country) combined with an underscore: eg. it_IT or en_EN
For example switzerland has 3 spoken languages:
The filenames of your translation-files should be like:
The translation-keys should be unique, dot-separated and equal in each single translation-file. First comes translation-key and after the colon comes the translated content.
# messages.it_IT.yml
navigation.home: Clicca per casa
navigation.help: Clicca per aiuto
# messages.en_EN.yml
navigation.home: Click for home
navigation.help: Click for help
Now you can use the navigation-keys in your application and a good IDE will help you by selecting them. When using different files for the different parts of your application, you have to address them in twig like:
{{ 'navigation.home'|trans({}, 'application') }}
{{ 'navigation.help'|trans({}, 'application') }}
<div class="error-message">
The following error occured: {{ 'error.login'|trans({}, 'messages') }}
</div>
Upvotes: 2
Reputation:
I just found a work around. added messages.it.yml file and changed fallbacks: ['it']
in translation.yml
framework:
default_locale: 'en'
translator:
paths:
- '%kernel.project_dir%/translations'
fallbacks: ['it']
since I already added messages.en.yml changes showed with english bu I'm not sure why this happens.
Upvotes: 0
Reputation: 594
php bin/console cache:clear
Clear your cache, if you craeted new translation file, you have to do it.
Upvotes: 2