title: play framework 2.0 - internationalization - how to translate a message
body: <p>First question: how can I retrieve the translation of a text in a controller?</p>
  
  <p>Second question: how can I retrieve the translation of a text in a template?</p>
  
  <p>The api says that there is a .get method that translates a message:</p>
  
  <p><a href="http://www.playframework.org/documentation/api/2.0/java/play/i18n/Messages.html">http://www.playframework.org/documentation/api/2.0/java/play/i18n/Messages.html</a></p>
  
  <p>However my application does not recognize this method. Opening in eclipse the Message.class shows that there is an .apply method in it, written in Scala and Java!?</p>
  
  <pre><code>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 =&gt;
        app.plugin[MessagesPlugin].map(_.api.translate(key, args)).getOrElse(throw new Exception("this plugin was not registered or disabled"))
      }.getOrElse(noMatch(key, args))
    }
  </code></pre>
  
  <p>Now eclipse tells me that I can invoke this method like this:</p>
  
  <pre><code>&gt; String play.api.i18n.Messages.apply(String arg0, Seq&lt;Object&gt; arg1,
  &gt; Lang arg2)
  </code></pre>
  
  <p>But what should I enter as the "Seq" argument?</p>
  
  <p>--The solution--</p>
  
  <p>The problem was that I imported play.api.i18n.Messages instead of play.i18n.Messages ...</p>
  
  <p>Having defined two message files (messages.de-DE and messages.en-UK) and using the following code everything works fine:</p>
  
  <p>Controller:</p>
  
  <pre><code>    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"));
  </code></pre>
  
  <p>application.conf</p>
  
  <pre><code>    application.langs="en-GB,de-DE"
  </code></pre>