31

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

开源或专有并不重要。

当我说 gettext 的替代方案时,我的意思是一个用于国际化的库,具有某种本地化后端。

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

4

4 回答 4

47

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

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


编辑:

如果你不喜欢gettext...

这些是翻译技术:

  • 绿洲XLIFF
  • GNU gettext po/mo 文件
  • POSIX 目录
  • Qt ts/tm 文件
  • Java 属性,
  • 视窗资源。

现在:

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

现在我们有什么?

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

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

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

于 2010-02-02T16:16:59.123 回答
8

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

一个流畅的 .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.
于 2019-03-27T22:58:51.733 回答
3

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

我并不是说它在大多数情况下都无法正常工作,但我尝试用它管理一个项目,并且很快就被使用它的难度所压倒。也许今天有一些翻译人员的用户界面,但我什至没有看。字符串的提取和合并不是为我做的。

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

我建议看看这个,例如:

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

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

于 2011-09-19T06:30:21.270 回答
2

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

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

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

于 2012-11-15T04:50:46.233 回答