php string variables in gettext
Asked Answered
D

2

2

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!

Danieledaniell answered 28/8, 2009 at 20:27 Comment(0)
C
9

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.

Croup answered 28/8, 2009 at 20:35 Comment(1)
What if you have a foreach going with a variable that is defined in hundreds of different ways?Illusionary
B
-1

There is detailed information available in https://www.php.net/manual/en/book.gettext.php.

Broomfield answered 28/8, 2009 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.