Re: multilingual code
On Jul 5, 9:56 pm, Sam <s...@email-scan.com> wrote:
James Kanze writes:
In C++, this is handled by the localization library. The
general approach used in C and C++ is that application
messages are written in one language, usually English, and are
looked up in a message catalog for a different language. If
found, the translated message string gets returned, otherwise
the application's native message string is returned by
default, so that the original message gets used.
Except that the standard library interface in locale takes an
int as the message id, with a separate parameter for the
default in case the message isn't found:-(.
Yes, I was still thinking in gettext terms.
=85 and not to mention that gcc's std::messages facet is broken. It uses
global state. Instantiating two std::messages facets in different locales
will result in chaos.
Sadly, for the moment, it appears that std::messages is broken goods.
In general, I fear that there is no really workable portable
solution. There's Windows, and Unix, and it wouldn't surprise
me if Apple handled the issue differently than most of the other
Unix (and that there were subtle variations between Unix,
despite Posix having standardized a good deal).
In French, however, "found" becomes "trouv=E9e". Or "trouv=E9es",
depending on the count---suddenly found also needs a table
lookup. In German, found must come before the noun (in this
case, at least), and found changes depending on the number,
whereas error ("Fehler") doesn't. And in Russian, from what
I've been told, numbers like 21 or 31 also take a singular.)
Recent GNU gettext libraries actually have a mechanism for
handling this, that is, having multiple plural forms and
selecting the correct one for a given numerical quantity.
And handling different genders. And different rules for
according number and gender. Including between verbs. (Some
languages mark verbs with gender.)
A lot of people are making significant progress, but human
languages are extremely complex and varied. For the moment, if
you want linguistically correct output in various language,
I think the only solution is to create a dynamically linked
object for each language, programming all of the special cases
by hand.
--
James Kanze