gettext 的替代品?

发布于 2024-08-19 15:57:11 字数 155 浏览 5 评论 0原文

gettext 是否有任何通用的本地化/翻译替代方案?

开源或专有并不重要。

当我说 gettext 的替代品时,我指的是一个具有本地化后端的国际化库。

我问的原因是因为(除其他外)我发现 gettext 做事的方式有点麻烦和静态,主要是在后端位。

Are there any general localization/translation alternatives to gettext?

Open source or proprietary doesn't matter.

When I say alternative to gettext, I mean a library for internationalization, with a localization backend of sorts.

The reason I'm asking is because (among other things) I find the way gettext does things slightly cumbersome and static, mostly in the backend bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

丶情人眼里出诗心の 2024-08-26 15:57:11

首先,我认为 gettext 是目前最好的之一。

您可以查看 Boost.Locale ,它可能提供更好的 API 并使用 gettext 的字典模型:http://cppcms.sourceforge.net/boost_locale/docs/(不是 Boost 的官方部分,仍为测试版)。


编辑:

如果您不喜欢gettext...

这些是翻译技术:

  • OASIS XLIFF
  • GNU gettext po/mo 文件
  • POSIX 目录
  • Qt ts/tm 文件
  • Java 属性、
  • Windows资源。

现在:

  • 最后两个完全是废话...很难使用翻译和维护,不支持复数形式。
  • Qt ts/tm——需要使用 Qt 框架。与 gettext 具有非常相似的模型。不错的解决方案,但仅限于 Qt。在通用程序中不太有用。
  • POSIX 目录——没有人使用它们,不支持复数形式。废话。
  • OASIX XLIFF——“标准”解决方案,依赖于XML,甚至ICU也需要编译到特定的ICU资源才能使用。翻译工具有限,我不知道有什么库支持 XLIFF。复数形式不太容易使用(ICU 仅在 4.x 版本中包含一些支持)。

现在我们有什么?

GNU gettext,广泛使用,有很棒的工具,有很好的复数形式支持,在翻译社区中很受欢迎......

所以决定,你真的认为 gettext 不是很好的解决方案吗?

我不这么认为。您根本没有使用过其他解决方案,因此首先尝试了解它是如何工作的。

First of all I think gettext is one of the best at this point.

You may take a look on Boost.Locale that may provide a better API and use gettext's dictionary model: http://cppcms.sourceforge.net/boost_locale/docs/ (not official part of Boost, still beta).


Edit:

If you don't like gettext...

These are translation technologies:

  • OASIS XLIFF
  • GNU gettext po/mo files
  • POSIX catalogs
  • Qt ts/tm files
  • Java properties,
  • Windows resources.

Now:

  • Last two total crap... Very hard to use translate and maintain, do not support plural forms.
  • Qt ts/tm -- requires usage of Qt framework. Have very similar model to gettext. Not bad solution, but limited to Qt. Not so useful in generic programs.
  • POSIX catalogs -- nobody uses them, no plural forms support. Crap.
  • OASIX XLIFF -- "standard" solution, depends on XML, even ICU requires compilation to specific ICU resources for use. Limited translation tools, I don't know any library that supports XLIFF. Plural forms not so easy to use (ICU included some support only in 4.x release).

Now what do we have?

GNU gettext, widely used, has great tools, has great plural forms support, very popular in translators community...

So decide, do you really think that gettext is not so good solution?

I don't think so. You haven't worked with other solutions at all, so try to understand how it works at first place.

梦幻之岛 2024-08-26 15:57:11

Fluent 是一个新系统,它提供了 gettext 所缺乏的许多适应性。 gettext 支持复数形式,而 Fluent 则为文本变体提供了通用框架。 gettext 使用“未翻译”字符串作为其翻译键,而 Fluent 支持抽象键(允许对源语言中恰好同名的内容进行多种翻译。 这里有更广泛的比较。Fluent

.ftl 文件的示例,取自 firefox 的首选项代码库,如下所示:

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

blocklist-window =
    .title = Block Lists
    .style = width: 55em

blocklist-description = Choose the list { -brand-short-name } uses to block online trackers. Lists provided by <a data-l10n-name="disconnect-link" title="Disconnect">Disconnect</a>.
blocklist-close-key =
    .key = w

blocklist-treehead-list =
    .label = List

blocklist-button-cancel =
    .label = Cancel
    .accesskey = C

blocklist-button-ok =
    .label = Save Changes
    .accesskey = S

# This template constructs the name of the block list in the block lists dialog.
# It combines the list name and description.
# e.g. "Standard (Recommended). This list does a pretty good job."
#
# Variables:
#   $listName {string, "Standard (Recommended)."} - List name.
#   $description {string, "This list does a pretty good job."} - Description of the list.
blocklist-item-list-template = { $listName } { $description }

blocklist-item-moz-std-listName = Level 1 block list (Recommended).
blocklist-item-moz-std-description = Allows some trackers so fewer websites break.
blocklist-item-moz-full-listName = Level 2 block list.
blocklist-item-moz-full-description = Blocks all detected trackers. Some websites or content may not load properly.

Fluent is a new system that offers a number of adaptations that gettext lacks. Where gettext supports pluralization, fluent has a generic framework for the text variants. Where gettext uses the "untranslated" string as its translation key, fluent supports an abstract key (allowing multiple translations for something that just happens to be homonymous in the source language. Here is a more extensive comparison.

An example of fluent .ftl file, taken from firefox's preferences codebase, looks like this:

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

blocklist-window =
    .title = Block Lists
    .style = width: 55em

blocklist-description = Choose the list { -brand-short-name } uses to block online trackers. Lists provided by <a data-l10n-name="disconnect-link" title="Disconnect">Disconnect</a>.
blocklist-close-key =
    .key = w

blocklist-treehead-list =
    .label = List

blocklist-button-cancel =
    .label = Cancel
    .accesskey = C

blocklist-button-ok =
    .label = Save Changes
    .accesskey = S

# This template constructs the name of the block list in the block lists dialog.
# It combines the list name and description.
# e.g. "Standard (Recommended). This list does a pretty good job."
#
# Variables:
#   $listName {string, "Standard (Recommended)."} - List name.
#   $description {string, "This list does a pretty good job."} - Description of the list.
blocklist-item-list-template = { $listName } { $description }

blocklist-item-moz-std-listName = Level 1 block list (Recommended).
blocklist-item-moz-std-description = Allows some trackers so fewer websites break.
blocklist-item-moz-full-listName = Level 2 block list.
blocklist-item-moz-full-description = Blocks all detected trackers. Some websites or content may not load properly.
荒岛晴空 2024-08-26 15:57:11

关于 gettext() 和所有支持 gettext() 的有趣评论。

我并不是说它在大多数情况下都不能正常工作,但我尝试用它来管理一个项目,但很快就对使用它的难度感到不知所措。也许今天有一些供翻译人员使用的用户界面,但我什至没有看。字符串的提取和合并并不适合我。

现在,我感谢 Artyom 谈论 XLIFF,这对我的环境来说是一个更好的解决方案,因为一切都是 XML。哦!那里有优秀的编辑。但如果您喜欢 gettext(),您将找不到它们。 8-)

我建议看看这个:

https://sourceforge.net/projects/wordforge2/现在

,这可能会给程序员带来一场噩梦,让一切顺利进行,但我们想要的是翻译人员的梦想成真(随着翻译的涌入,程序员的工作量为零,因为我可以告诉你, gettext() 我必须完成所有工作!)

Interesting comments about gettext() and all those pro-gettext().

I'm not saying that it ain't working right in most cases, but I tried to manage one project with it and quickly felt overwhelm by the hardness of using it. Maybe there are a few user interfaces for translators today, but I did not even look. The extraction and merging of strings is just not doing it for me.

Now, I thank you Artyom for talking about XLIFF which is a much better solution for my environment since everything is XML. Oh! And there are excellent editors out there. But if you like gettext() you won't find them. 8-)

I'll suggest looking at this one for example:

https://sourceforge.net/projects/wordforge2/

Now, this may give the programmer a nightmare to make it all work, but what we want is a dream come true for the translators (and zero work by the programmer as translations pour in, because I can tell you that with gettext() I had to do all the work!)

南城旧梦 2024-08-26 15:57:11

Zend 有一个替代方案,支持 gettext *.po / *.mo 文件和更多格式。
许多 Apache 服务器会缓存翻译文件,因为 gettext 是作为模块实现的,并且必须重新启动服务器才能刷新翻译数据。

Zend 实现避免了这种情况并支持更多格式:

http://framework。 zend.com/manual/1.12/en/zend.translate.html

There is an alternative from Zend that supports gettext *.po / *.mo files and many more formats.
Many Apache servers cache the translation files because gettext is implemented as a module and the server has to be restarted to refresh the translation data.

The Zend implementation avoids this and supports many more formats:

http://framework.zend.com/manual/1.12/en/zend.translate.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文