English 中文(简体)
R 脚本的翻译
原标题:Translation of R script using gettext

是否有可能使用像 optext 这样的文字来翻译 R 脚本 。 如果是, 如何翻译? 如果没有, 我还有什么其他选择?

最佳回答

You can use base::gettext/ngettext, base::bindtextdomain and tools::xgettext2pot functions.
For example:

myFunction <- function()
{  
  bindtextdomain("R-myProgram","/my/translation/dir")
  gettext("Hello",domain="R-myProgram")
}

然后,假设此函数位于一个路径为“/my/ dir/R/myfile.R” 的文件内,使用: tools::xgettext2poot ("/my/dir"), ,然后使用 msginit、 msgfmt 等创建 mo 文件 /my/ translation/dir/fr/LC_MESAGES/R-myProgram.mo 。 我的功能() 现在应该打印“ Bonjour”, 而不是“ hello”, 如果您的语系是法语 。

还有其他几点:

  • It seems like xgettext2pot assumes your project is a standard R package and looks only for *.R files inside the R/ subdirectory.
  • The domain argument seems to be by default the namespace of the function calling gettext()
  • stop(), message(), warning() and packupStartupMessage() are also detected by xgettext2pot. There is also a gettextf() function available as a sprintf-like variant of gettext().
  • Since the standard xgettext utility doesn t seem to support R syntax, and since one has to use tools::xgettext2pot, a couple of things will miss from the standard approach, such as message contexts (pgettext()), flags indicating printf-like strings and the possibility to write in-code comments for the translators (extracted by xgettext -c) without modifying the .pot file by hand.
问题回答

暂无回答




相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?