0

I designed a WordPress theme from scratch starting from my html site and in the conversion I used the functions _e() and __() to make the theme multilingual ready.

Then I created the translation .po and .mo files via Poedit (containing translations of the texts concerned) and enabled translation support via functions.php. So in theory I should have all the elements at my disposal.

So my question is simple: is there a way to recall translations without using additional plugins (which I would like to avoid)? For example, can another language appear according to user's language browser, or simply with a manual switcher?

0

The shorts answer is no. The __() and _e() functions are evaluated on the server side. So by the time the page is sent tot the user, there is a plain string in the html. There is no way on the user end to access a different translation.

That said, you can get around this by using the locale filter. For instance, you could have a button on your site 'same page in french', add a query variable to the link, extract that on the server side, change the language and then generate the same page in a different language (its theme strings, not the actual post content).

Depending on how extensively you want to do this you're looking at quite some work of quite a lot of work. And you might come to regret that you didn't use that translation plugin.

  • Thanks for the reply. Is there a plugin that works synergistically with the translations found in the Poedit files I've already created? Whether the answer is yes or no what do you suggest? Unfortunately I do not know how to implement the solution in which you suggest me to create a query that extracts the language from the server because I am a neophyte. And still using this solution would involve having to click on a translation link every time you access a different page? – Vizzale May 10 '18 at 17:45
  • I have no direct experience with translation plugins, but they are meant to translate post content, not template files. So I wouldn't bet on them helping with your requirement. – cjbj May 11 '18 at 9:22
  • Analyzing the problem I would practically need to translate both the texts of the posts and the "static" texts of the template files. Let's see if someone suggests something to me. – Vizzale May 11 '18 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.