Choosing the locale in theme for translation

I developed a plugin and a theme associated.

The plugin handles a model that defines a language attribute.

En or Fr, for this case.

I created 2 json files for the theme to hold the translation.
How can I use this attribute to provide the correct language translation in my theme?
I am currently using the tag |trans but can’t find a way to pass the language in parameters or something similar.

The idea is to provide content based translation in the theme, meaning that the theme will display the localized buttons, messages, UI in the language that is the model’s content defined. Because my model is representing a Course. It can be in any language.

Any idea please?

Interesting problem!
I think there are many things to consider, even up to a SEO standpoint.

And it also depends on what content you want to have translated. If it’s just the course content, you could just add the content in the primary site and will have the same language regardless of the selected or associated (with the site) locale. If you want your entire site to change depending on what course have been selected, you could just redirect to the matching site.

But before I drone on: |trans takes 3 parameters, the code, parameters and a locale. Maybe thats all you need.

thanks for your input @marco.grueter

The website is a platform aiming at hosting online course. The website is in english.
but the courses can be in any language.

For an english course, the author will select the language English and write his content in english.
For a french course, the author will select the language French and write his content in french.

Now when a customer purchase the english course, I want the theme UI to be displayed in English. Ex: resume course, coming soon, mark as complet, …
Now when a customer purchase the french course, I want the theme UI to be displayed in French. Ex: continuer le cours, bientot, completer, …

I tried to use trans('module.coming_soon', {}, 'fr') in my theme but got an error Unknown "trans" function.

Oh! but this 'module.coming_soon' | trans({}, 'fr') seems to be working.
Therefore, I can pull the lang locale from the course, and it should be working!

Fantastic

1 Like

Yes, the twig filter should work for what you want to accomplish!

You could also move the default UI localisation to your plugin, then you could override some of the messages through the app directory (Localization - October CMS - 3.x) and keep the rest of the theme free from those default translations. Useful if you have slightly different wordings depending on your customer (e. g. workshop instead of course) and also if you want to reuse your plugin for very different kinds of sites by completely separating your course management from the rest of the content.

interesting!
I think i will leave it to the theme to decide of the translation and wording to use for the enduser.

for the backend plugin, it has its own translation indeed which is overridable as you mention above.