OK,等进一步的思考,我意识到,我知道如何使用预 - 在gettext中存在翻译。要使用预先存在的文本域asdf
,只是做
const Gettext = imports.gettext.domain('asdf');
const _ = Gettext.gettext;
没有意外出现。
原来,我的实际问题是我想用“最小化”,“最大化”,“还原”,“关闭”等翻译,我虽然我确信这些翻译已经存在我的系统某处,我不知道是什么gettext的域他们实际上是
要了解这一点:
在Fedora(我的版本反正),翻译文本是/usr/share/locale
。
我去了/usr/share/locale/en_GB/LC_MESSAGES
,那里有一堆.mo
文件。这些都不是人类可读的,但我仍然可以通过他们的grep:
[[email protected]]$ grep -i maximize *.mo
Binary file devhelp.mo matches
Binary file evolution-3.2.mo matches
Binary file f-spot.mo matches
Binary file gnome-games.mo matches
Binary file gnome-media-2.0.mo matches
Binary file gnome-utils-2.0.mo matches
Binary file metacity.mo matches
Binary file mutter.mo matches
Binary file nautilus.mo matches
通过名单看,它发生在我,因为我正在寻找一个窗口菜单上的项目的翻译,它可能是我的窗口管理器拥有这些翻译。我的窗口管理器(因为我在gnome-shell上)是mutter
,它基于metacity
。
因此,我下载了mutter的源代码并查看了po
文件(人类可读的翻译文件),然后瞧!
#: ../src/ui/menu.c:69
msgid "Mi_nimize"
msgstr "Mi_nimise"
#: ../src/ui/menu.c:71
msgid "Ma_ximize"
msgstr "Ma_ximise"
#: ../src/ui/menu.c:73
msgid "Unma_ximize"
msgstr "Unma_ximise"
...and so on (the underscores are the keyboard accelerators for that menu item).
所以,现在,我已经找到了翻译,它只是做的情况下(在我的代码):
const Gettext = imports.gettext.domain('mutter')
const _ = Gettext.gettext;
log(_("Ma_ximize")); // to translate 'Ma_ximize'
(我在_("Ma_ximize")
喂到gettext的,因为这是在mutter.mo
文件中翻译的精确字符串 - 没有下划线的翻译没有"Maximize"
我必须从翻译后的文本中删除下划线,这可能会使用下划线作为他们写作的一部分的语言,但是,希望这不是很多)。
因此,总之 - 使用另一个(预先存在的)文本域很容易,但问题是找到具有所需字符串的文本域。