1

I am currently developing a plugin - if the current Wordpress language is for instance GERMAN or SWEDISH, the Wordpress texts (like Dashboard, "Your Profile", etc) will be translated into that specific language.

However, I am currently looking for a way, to revert the translated string BACK into en_US language. What I am trying to do, is something like this:

echo __('Dashboard');
// will output: "Kontrolpanel" (da_DK)

Scenario:

__('Kontrolpanel', array('da_DK' => 'en_US'));
// should output: "Dashboard" (because it is the original WP language, en_US)

Is this possible? I am dealing with content, which is created by Wordpress, this means, I have to find a way to translate the outputted string (which translated to current wp_lang) to translate it back to get the english version of the foregin word.

Does it makes sense? It's pretty complicated to explain.

I hope to hear from somebody!

Thanks in advance!

FooBar
  • 5,752
  • 10
  • 44
  • 93
  • The normal behavior is to have all the texts in this case in English and then have different translations files, I cannot understand why would be useful to have that kind of reverse translations. – ssola Dec 17 '13 at 16:50
  • For instance, I get the data from the global variable $menu - and then the contents of the menu is outputted in the default language (german, swedish, french, etc), but I need to convert it back to english. – FooBar Dec 17 '13 at 17:03
  • WordPress translating system is build on top of gettext. Unfortunately reverse translation is not supported by default. For that you will have to maybe develop a method to do it parsing the .mo/.po files. – ssola Dec 17 '13 at 17:06
  • OK, thanks! I have found a solution, to programmatically change the language to en_US, and then translate the string using the currenct locale (by defined: WPLANG). So what I am looking for now, is a way to output __( using a specific locale. Ie: `__('Dashboard', 'da_DK');`. But is it even possible? – FooBar Dec 17 '13 at 17:17
  • The problem with gettext is that only find messages from the same origin, in this case English. So you can change your base language to translate to English, Denmark or any other language but you have to continue passing to gettext the English text in order to find the proper translation. So, your request is not accomplished in that way. – ssola Dec 17 '13 at 17:25
  • OK thank you very much Ssola! Do you think there is a workaround? – FooBar Dec 17 '13 at 18:32
  • The unique workaround I can imagine is to write a function to read the translation file (.mo/.po) and search manually the required sentence. For example: reverseTranslation("Hallo", "de_DE"); and then open the de_DE.mo file and search for Hallo and extract Hello. This kind of files are quite simple to parse. – ssola Dec 17 '13 at 23:23
  • Here you can find an example: http://stackoverflow.com/questions/1949162/how-could-i-parse-gettext-mo-files-in-php4-without-relying-on-setlocale-locales – ssola Dec 17 '13 at 23:24
  • @Mattias _ there are many ways to do that - but Your question implies that you do not really understand the tools or the translation mechanism. Can you please try to edit your question to include the full scenario explanation of WHERE and HOW such a thing would be useful ? – Obmerk Kronen Mar 11 '14 at 01:25
  • @ObmerkKronen Are you saying you know how it can be done, but you won't tell unless OP can prove that he really needs it? Here are two imaginary use cases: 1) Users enter option values in their own language. 2) A book lovers' plugin with program logic based on references to authors and their works. References are rendered differently per language. Problem: it is not enough to translate output of references–to apply program logic to references input by users these must be "reverse translated" into canonical representation. I am looking for a solution and hopeful you can advise. – jjaderberg Mar 24 '15 at 20:00
  • @jjaderberg - no. what I said is that judging by the question, where the OP has asked of a translation of strings created **BY** wordpress ( note : not **WITH** wordpress - see the example string of "dashboard" ) it is my opinion that the OP does not really understand the native language and translations mechanisms in wp . if you have a specific case where you feel you need a "reverse translation" ( still don't understand what that means ) please do open a new question and I will be happy to look at it and try to solve ( just drop me a note in comment or something ) – Obmerk Kronen Mar 27 '15 at 01:22

0 Answers0