Jump to content

I look forward to create a module about languages


Sten
 Share

Recommended Posts

Hello

Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.

So I'd like to create a module to include theses files added according to the url /fr/en/...

Have you some observations to do before I begin about the direction to take ?

Thank you

Link to comment
Share on other sites

I'm also using Twig with a custom translations system for interface text / code i18n. While the built-in multilanguage support for page fields is well-done, I don't really like the system and interface for code internationalization and localization, and it doesn't work with Twig files (which is probably why you want to build your own).

I have written about the approach I took in the second part of my Twig + ProcessWire tutorial (towards the end, the section about translations). It comes down to a ProFields Table field that holds all the translations (so they can be edited through the backend as well) and a function that gets a local translation for the current language based on translatable strings (msgid). By the way I've switched to a Twig filter since writing this tutorial, I find it easier to write, so now I can simply do the following in Twig: {{ 'hamburger_button_label'|t }}

If you do end up writing a module for this, make sure to publish it here as well, I've been looking for a more scalable approach 🙂

  • Like 2
Link to comment
Share on other sites

Hello MoritzLost,

Thank you for your answer. I found an other solution and I'll tell you my system.

I got rid of TwigExtension and replace its function inside twig by using fuction in my php files.

In my system, I find useful and simple. I have translations files : fr.php, de.php...

Inside them I have the translations strings with constants. I call them in my init file after getting the language from the url, the transform the constant into variables for commodity. At last each varialbe is in the twig files. I have 8 languages and so translators just write in the file, I feel it simple. Ask me if you're interested and want precisions.

Have a nice sunday.

Link to comment
Share on other sites

Thanks for the insights! Static translation files are definitely a fast approach. If all your editors / translators are comfortable editing source code files directly, that's reasonable. Though they have to be careful not to overwrite each other's changes two or more editors are working on the same language (unless of course you're using distributed version control).

Does that mean you have to add a constant to eight different files whenever you want to add a translatable string? I'd get fed up with that very quickly 😛

Link to comment
Share on other sites

Hi MoritzLost,

That is just for the interface (menus, formulas...) the body field contains each post in any language. I have a default language and an URL  segment to get the chosen language. The translators complete the files once only per language.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...