This is not a direct answer to your question, but a different solution to solve your problem. The other answer addresses how to technically achieve what you want, but using reflection to do some internationalization is unnecessarily fragile and definitely not recommended.
As is mentioned in the comments, when you use Twirl in the context of a Play app, Play provides you with its own way to do internationalization. Since you don't use Play in your application, you can't use that. But you don't need to use Play's specific way to do internationalization. You can easily build your own rudimentary internationalization construct without pulling in extra dependencies, which I will show in this answer.
First and foremost, this approach should be much more DRY. Secondly, it decouples your layout from the language you happen to be using. Lastly, it's completely typesafe and does not use reflection.
First, make a class representing a language, wrapping a Properties
object.
// Language.scala
class Language(filename: String) {
val properties = new java.util.Properties()
properties.loadFromXML(new FileInputStream(filename))
def apply(key: String) = properties.getProperty(key, s"Key $key not found.")
}
object Language {
val English = new Language("path/to/english.xml")
val Russian = new Language("path/to/russian.xml")
}
Also define some translations using the Properties XML format:
<!-- path/to/english.xml -->
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="hello.world">Hello World</entry>
</properties>
<!-- path/to/russian.xml -->
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="hello.world">привет мир</entry>
</properties>
Then, when rendering, you can put the language you are using implicitly on the scope:
implicit val language: Language = determineLanguage() // Your logic for determining the language you want to use
// Do other things here..
// Render template
Send.txt.MonoEnsure("hi")
Then, in your template, use the language like this:
@(arg1: Any, arg2: Any)(implicit lang: Language)
<html>
<body>
<p>@lang("hello.world")</p>
</body
</html>
Which, will output a page displaying "Hello World" or "привет мир", depending on which language was chosen.
Update: My first suggestion was to use Java's default properties file format, but it turns out it uses Latin-1 encoding which does not support Cyrillic characters, making it difficult to use with Russian. Therefore, I've updated my answer to instead use the (unfortunately more verbose) Properties XML format, which uses UTF-8 encoding and therefore supports Cyrillic characters.