English 中文(简体)
框架 2.0 - 国际化——如何翻译信息
原标题:play framework 2.0 - internationalization - how to translate a message

第一个问题:我如何能够检索控制器文本的翻译?

第二个问题:我如何检索模板中文本的翻译?

缩略语说,有一套植被方法可以传递信息:

http://www.playframework.org/documentation/api/2.0/java/play/i18n/Messages.html

然而,我的申请并不承认这种方法。 打开电文。 班级显示,在Schala和Java编著中有一种适用的方法?

object Messages {

  /**
   * Translates a message.
   *
   * Uses `java.text.MessageFormat` internally to format the message.
   *
   * @param key the message key
   * @param args the message arguments
   * @return the formatted message or a default rendering if the key wasn’t defined
   */
  def apply(key: String, args: Any*)(implicit lang: Lang): String = {
    Play.maybeApplication.flatMap { app =>
      app.plugin[MessagesPlugin].map(_.api.translate(key, args)).getOrElse(throw new Exception("this plugin was not registered or disabled"))
    }.getOrElse(noMatch(key, args))
  }

我现在说,我可以这样援引:

> String play.api.i18n.Messages.apply(String arg0, Seq<Object> arg1,
> Lang arg2)

但是,我应做些什么是“Seq”的论点?

------

问题是,我进口游戏。 信息而不是游戏。 信息......

确定了两个电文档案(主题:de-DE和讯息.en-UK),并使用以下代码进行罚款:

主计长:

    import play.i18n.Messages;
    import play.api.i18n.Lang;

    Lang en = new Lang("en","GB");
    play.i18n.Lang en_lang = new play.i18n.Lang(en);

    Lang de = new Lang("de", "DE");
    play.i18n.Lang de_lang = new play.i18n.Lang(de);

    Logger.info(Messages.get("home.title"));
    Logger.info(Messages.get(en_lang, "home.title"));
    Logger.info(Messages.get(de_lang, "home.title"));

申请。

    application.langs="en-GB,de-DE"
最佳回答

3. 在控制器内部进行翻译:

// in messages file
msg.key=Hello Translation

// in you controller
Messages.get("msg.key");

甚至可以通过参数:

// in messages file
msg.key=Hello {0}, here is your translation

//in controller
Messages.get("msg.key", User.firstName);

From the view you can use: Messages("msg.key")

您甚至可以采用超文本格式格式(仅适用于意见):

// in messages file
msg.key=Hello <strong>{0}</strong>, here is your translation

// in controller
Messages.get("msg.key", User.firstName);

//in view
@Html(objectInView)

Please note the following: Currently it is not possible to define the language explicitly, see bug report: https://play.lighthouseapp.com/projects/82401/tickets/174-20-i18n-add-ability-to-define-implicit-lang-for-java-api

Similar question was asked before: Access translated i18n messages from Scala templates (Play! Internationalization)

i18n差错: 控制器和模板使用不同的隐含语言

问题回答

暂无回答




相关问题
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?

热门标签