bug-gnu-gettext is a slightly better mailing list for this type of question;
I'm adding it in CC.
Chris Scaife asked:
> Documentation for functions like dngettext state that translated
> strings are statically allocated. However if I were to keep opening
> new domains surely it would run out of space?
No, it won't run out of space. "statically allocated" here means allocated
with indefinite extent. If you keep passing new domains to dgettext, dcgettext,
the MO files will be loaded and transformed to "statically allocated" memory.
> Please can someone help me understand how that static allocation works
> so that I can make sure I'm not accidentally using strings that have
> been discarded from memory.
If gettext(s) != s, you are guaranteed that gettext(s) is statically allocated,
that is, you can access it as long as you want, and it will not be discarded
from memory. Of course, if gettext(s) == s, then it depends on how the caller
has allocated s and will free s.
Bruno
I am pleased that the strings will remain on hand and I don't have to
worry about copying them into other containers. It is also very handy
to be able to test if a translation took place by simply checking the
return value for identity with the original string provided. I get the
impression the whole gettext thing was really well designed from the
start :)
In my project I wanted to differentiate on negative values for
ngettext and dngettext pluralization. Sadly they only work with
unsigned long integers. Part of the problem is that on some systems
this can be 32 bit and on others 64 bit. I'm hoping to suggest to the
GNU gettext team that we could use signed values instead. For the time
being, I've wrapped my pluralizing numbers that are above 10000 into
the space 10000 - 19999... and then negative values can be discovered
by testing > 20000 in the .po pluralization formula. It's not an
elegant solution so if anyone has alternative suggestions I would love
to hear :)
Another possibility would be that rather than mapping numbers into a
particular range (yours is probably fine but one never knows) you could
have your function make two separate calls to [d]ngettext, with
different message contexts (negative numbers would have " (negative
values)" appended to the default context or something like that).
This is a little inelegant for the translators, in that the .po file
will contain the same message twice (with different contexts) but at
least it will be very explicit what is going on, and in any language
where a negative value requires different translation, it will be quite
clear to the translator what needs to be done.
@alex
--
mailto:alex....@mac.com
What I was using "pluralization" for is to select different numerical
template strings for outputting numbers depending on the value. By way
of example to show very different for large amounts and small amounts
and debts when dealing with money. i.e. the following formatting
changes are all done with translatable template strings.
$> export LANG=en_NZ.UTF-8
$> ./a.out 0.20 -0.20 12345678
0.20 = 20¢
-0.20 = ($ 0.20)
12345678 = $ 12,345,678.00
Note: You can see this in action with my numeric test program where the word
"counter" is translated into a template
for rendering digits... Here some sample output. I hope the international
characters are maintained in this email, but the source code is all at
http://code.google.com/p/speaknumber/
<http://code.google.com/p/speaknumber/>Next I'm moving forward with my GUI
demo program that will let one experiment with number templates and their
translations interactively.
$ ./test.sh T_CHINA
test program is ./a.out
$ ./a.out 1956
1956 number = counter, financial = $ 19.56, template=$ 222,222.33
$ export LANG=zh_CN.utf-8
$ ./a.out 1956
1956 number = 仟九佰五拾六, financial = 仟玖佰伍拾陆, template=1仟1佰1拾0
$ ./a.out -1956
-1956 number = 负仟九佰五拾六, financial = 負仟玖佰伍拾陆, template=負1仟1佰1拾0
$ export LANG=en_NZ.UTF-8
$ ./a.out -1956
-1956 number = -counter, financial = ($ 19.56), template=($ 222,222.33)