I’m creating multilang site with default language SR and EN, FR, DE supported also. I’m using twig translation filter (|t), all strings in twig templates are written in SR and I don’t have sr.yaml file. I choose this approach because there is not much content but some labels/tags etc…
Problem is that on all sr pages twig translates strings to EN. I suppose it does that because no sr.yaml language file is present since I don’t need to translate strings that are already in that language.
my config:
languages:
supported:
- sr
- en
- fr
- de
default_lang: sr
include_default_lang: true
include_default_lang_file_extension: true
translations: true
translations_fallback: false
session_store_active: false
http_accept_language: false
override_locale: false
content_fallback: {
sr: sr
}
pages_fallback_only: false
Is this bad approach or there are some configs that I’m missing?? Thanks!!
Usually, strings in Twig that need to be translated have a dotted notation, like {{ 'THEMENAME.TOPIC.TITLE'|t }}.
In the language.yaml file you would then have:
en:
THEMENAME:
TOPIC:
TOPIC: The title of the topic
sr:
THEMENAME:
TOPIC:
TOPIC: Наслов теме
You say your strings are in Serbian. How do your Twig strings look like?
I suppose it does that because no sr.yaml language file is present since I don’t need to translate strings that are already in that language.
Usually, a theme/plugin makes use of a language.yaml file which contains the strings that need to be translated as shown above.
Only when overriding translations provided by the theme/plugin one can use files like user/languages/sr.yaml which contain the strings to be overridden.
Are you overriding translations provided by the theme/plugin?
Remarks like “all strings in twig templates are written in SR” and “no sr.yaml language file is present” are smells of a bad multilanguage infra structure.
As a kind request, please improve legibility by formatting code or yaml snippets using triple backticks.
You say your strings are in Serbian. How do your Twig strings look like?
I am aware that strings usually have dotted notation in twig but I tried to bypass this and hardcode strings directly in twig. (maybe not smartest idea)
Then I translated whole string in other language files eg: en.yaml:
"Наслов теме": "The title of the topic"
What happens is that even when I’m on SR version of page this is still translated to EN when I expect to remain untranslated. That’s why I wrotte that I suppose it automatically translates to EN when no SR.yaml is present.
I have configured default locale to SR and default lang to SR.
I don’t want to further overcomplicate things, I will find solution with better practice. Just wanted to check if this is something thats related to config or just how things works.