Access to translation of i18n messages from Scala templates (Play! Internationalization)

In my game! 2.0 I would like to define the following languages:

# The application languages # ~~~~~ application.langs=en-GB,de-DE,nl-NL 

I also created 3 files that end with the corresponding language codes:

 Messages.en-GB Messages.de-DE Messages.nl-NL 

When I run the application without asking for the translated key, I get the following error message:

 conf/application.conf: 12: Key 'de-DE' may not be followed by token: ',' (if you intended ',' to be part of the value for 'de-DE', try enclosing the value in double quotes) 

Also, when I try to access a message from a Scala template, I still see the same message. I am requesting a message using the following code:

 @Messages("login.page") 

The above changes I made in accordance with the game guide: http://www.playframework.org/documentation/2.0/JavaI18N . Therefore, I have two questions:

  • How can I set langauge by default and change it as in 1.2.4 (Lang.change ("en-GB"))
  • How to access messages from Scala templates?
+2
source share
2 answers

Changing the language is not possible on Play! 2.0, see Talk: http://groups.google.com/group/play-framework/browse_thread/thread/744d523c169333ac/5bfe28732a6efd89?show_docid=5bfe28732a6efd89

and this ticket: https://play.lighthouseapp.com/projects/82401-play-20/tickets/174-20-i18n-add-ability-to-define-implicit-lang-for-java-api#ticket- 174-4

Although, when you register multiple languages, you should enclose them in double qoutes, for example:

 application.langs="en-GB,de-DE,nl-NL" 

And then you can access them from scala templates, like this:

 @Messages.get("login.title") 

Thus, currently the default language is the language that is defined in the message file (without any prefix !!)

Or you can just use @Messages ("not.logged.in")

+2
source

In your scala file use:

 <h1>@Messages("pack.key")</h1> 

And in your java file use:

 String title = Messages.get("pack.key"); 

Remember to add a quote from the list of languages: conf / application.conf

 application.langs="en-GB,de-DE,nl-NL" 
+7
source

Source: https://habr.com/ru/post/914831/


All Articles