How do you make gettext ALWAYS use a translation instead of default languiage text

StackOverflow https://stackoverflow.com/questions/1415864

  •  06-07-2019
  •  | 
  •  

Question

When you call the gettext php function for translating text to another language, it uses the text you have on the page to act as the KEY/ID to lookup the value to replace it with

echo gettext('hello how are you today');

that would be the text used to lookup the translation, however I would like to use something like this

echo gettext('welcome_message');

and have that translated into English and any other language I offer. So how could I make this happen? How can I make gettext function ALWAYS use a language file? So if my default language is English for the site then instead of gettext showing welcome_message to an English user it would show hello how are you today

Is it as simple as just creating an English language file in addition to the other language files?

Was it helpful?

Solution

You're on the right track. The string argument to gettext() is just an identifier, not a "default language". If there is no translation in the active locale, then gettext will return that identifier.

Your solution is just what you suspect: just create an English translation file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top