简体   繁体   English

没有过程语言环境的Gettext

[英]Gettext without process locale

I want to use gettext for i18n. 我想为i18n使用gettext。 But I need to translate messeges to a different languages. 但是我需要将信息翻译成其他语言。 Is it possible to specify a locale for a one gettext call? 是否可以为一个gettext调用指定语言环境?

If you use multiple threads then you can use gettext if you use the locale-related facilities specified in POSIX.1-2008 (and implemented in GLIBC 2.3). 如果使用多个线程,那么如果使用POSIX.1-2008(在GLIBC 2.3中实现)中指定的与语言环境相关的功能,则可以使用gettext。 The key function you would use is uselocale , which is a bit like setlocale but for the current thread only. 您将使用的关键功能是uselocale ,它有点像setlocale但仅适用于当前线程。

If you are using Windows then you are out of luck--MSVCRT does not provide an equivalent to uselocale , and I believe on that platform libintl emulates setlocale itself, in a non-thread-safe way IIRC. 如果您使用的是Windows,那么您就不走运了uselocale不提供等效于uselocale ,我相信libintl在该平台上以非线程安全的方式IIRC模仿setlocale本身。

As you can see from Replacements for gettext I had similar problems, only it gets worse if you have to support more platforms. “ gettext的替换”中可以看到,我也遇到了类似的问题,只有在必须支持更多平台的情况下,情况才会变得更糟。

Basically gettext is only really suitable for single-threaded interactive programs. 基本上,gettext仅真正适用于单线程交互式程序。

If you have the chance then a different translation system (ICU looks quite nice). 如果您有机会,那么可以使用其他翻译系统(ICU看起来不错)。

Otherwise there are a few libraries that read .mo files directly, and can provide the translation as you want: 否则,有一些库可以直接读取.mo文件,并可以根据需要提供翻译:

http://art-blog.no-ip.info/cppcms/blog/post/16 http://art-blog.no-ip.info/cppcms/blog/post/16

I want to use gettext for i18n. 我想为i18n使用gettext。 But I need to translate messeges to a different languages. 但是我需要将信息翻译成其他语言。

If your application is single threaded you may switch locale, otherwise you can't use gettext library for this purpose. 如果您的应用程序是单线程的,则可以切换语言环境,否则,您不能为此使用gettext库。

Is it possible to specify a locale for a one gettext call? 是否可以为一个gettext调用指定语言环境?

You may use Unofficial Boost library Boost.Locale that supports gettext message catalogs. 您可以使用支持gettext消息目录的非官方Boost库Boost.Locale But it is C++ only. 但这仅是C++

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM