How does gettext translate string variables? It doesn't seem to want to do it.. lets say I have $sentence = "Hello World"; and then I want to echo ($sentence); ... how can I do that so that I can translate what's inside $sentence in Poedit?I can use -> echo sprintf(("%s test"), $sentence) and this will print "Hello World test" in the browser but it will appear as "%s test" in Poedit and I won't get the translated version of Hello World inside of Poedit. So how can I use string variables inside Poedit? Thanks!
php string variables in gettext
You just must not have string variables. You should do e.g.
$sentance = _('Hello world');
The other way is to use some king of parser, which will be able to find your hello world strings and finally output somewhere
$fakie = _('Hello World');
This output should be stored in some file, which will then be pickedup by poedit and translated. For showing the translation you can than use
$myTranslation = _($sentance);
We used this conversion process for javascript files and smarty templates.
What if you have a foreach going with a variable that is defined in hundreds of different ways? –
Illusionary
There is detailed information available in https://www.php.net/manual/en/book.gettext.php.
© 2022 - 2024 — McMap. All rights reserved.