How to make gettext and DB? Or how to scan __("double underline")?

0 like 0 dislike
5 views
I need to mark translatable phrase, it was convenient to collect them, but the translations should be taken from the database.


When you use _("single underscore") (as well as gettext(), ngettext()) I can easily get phrase using xgettext. But _ () is an internal function and override it, I can't, and you need to take transfers from .mo and from the database. I would love to used the marking __("double underline"), but don't know how to specify xgettext'that scan need __() not _()


What to do, what to do? :)
by | 5 views

2 Answers

0 like 0 dislike
> _() — internal function
\r
Nothing like this macro it is necessary to determine, and usually it is defined as gettext(x).
\r
For example, I define as:
\r
#define _(String) gettext(String)
#define gettext_noop(String) String
#define N_(String) gettext_noop(String)
\r
You can override if you so desire, for example,
\r
#define __(String) myfunc(String)
\r
And already myfunc will take this string from the database.
\r
To xgettext yanked need, just specify that prefix is __:
\r
xgettext [other options] -k__ -o outfile.po
by
0 like 0 dislike
Well, no, to define a macro gettext_noop useless. Actually the N_ macro too! Just don't call him macro _. And then the utility will generate a file localization, xgettext does not just include your string in the output po file. By the way with the base it won't work. More precisely xgettext doesn't work. Well, because it needs to know which line need to pull out at the time of its launch. And it's not there, it will only appear at the time of the calls to the database. It works only static localization. But you can cheat if you know which rows appear there, we can manually add them to your po file... It certainly will not protect you from failure, if for example there will be new. Each time you append the file and precompiling and then put. But it is a thankless task. It is much better to write the translation into the database add the field with the appropriate language and to carry srzu rows in the target language. Then when you add a record in the database you may request to add and its translation. Not added well their problem... As you want! Well somewhere it is necessary to add, either there or here, and in any case manually...
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
33,605 users