Replacements for gettext

后端 未结 5 1734
野趣味
野趣味 2021-01-13 07:56

We use gettext for translations in our product, but have had a lot of problems with it:

  • Can\'t use a language unless the system supports it.

On

5条回答
  •  独厮守ぢ
    2021-01-13 08:32

    1. Can't use a language unless the system supports it.

    Wrong. You may manually specify language. Using LANGUAGE environment variable

    int main()
    {
          setlocale(LC_ALL,"");
          setenv("LANGUAGE","foo");
    }
    

    This works, even if the locale does not exist (have you ever seen language foo?)

    2. Uses environment to work out language

    What is problem with that? This gives user more control.

    3. Can't set a default language

    Wrong, See above.

    4. Encoding the are returned vary between UTF-8 and current local encoding.

    Wrong, See bind_textdomain_codeset(domain,codepage);

    My strong recommendation -- stay withing gettext. It is one of most supported and best tool around. Translators will be thankful to use normal and useful tool.

    There is other important point: great support of plural forms that has quite bad support in non-gettext based tools.


    There is only 1 limitation of gettext -- you can't use more then one language per-process. It is not thread safe to switch language. Fortunately most programs that incract with human beings are speak in one language.

    This may be limitation only for multi-threading services.

    EDIT: But even this is not a real problem. I had implemented thread safe gettext version once for my project. See http://art-blog.no-ip.info/cppcms/blog/post/16, based on mo files reader.

提交回复
热议问题