package i18n
- Alphabetic
- Public
- All
Type Members
- final case class KeyLocale(key: Key, locale: Locale) extends Product with Serializable
-
class
Messages extends Logging
Internationalization (i18n) and localization (l10n) helper class.
Internationalization (i18n) and localization (l10n) helper class.
Message files (located in
resources/i18n/
, by default) are written using Typesafe Config "HOCON" format. HOCON fully supports UTF-8 Unicode and is more flexible and powerful than Java.properties
.For instance, it is possible to have a locale such as "en-CA" to automatically default to another locale, say "en", if a message is missing: just add the
include "messages.en.conf"
line to themessages.en-CA.conf
file.Messages are rendered by ICU4J, which provides comprehensive support for Unicode, globalization, and internationalization. Compared to Java
MessageFormat
, ICU4J supports named and numbered arguments, enhanced gender and plurals, user-friendly apostrophe quoting syntax, cardinal (one, two) and ordinal numbers (1st, 2nd, 3rd), and much more.@i18n object messages implicit val defaultLocale = Locale.ENGLISH val ptBr = Locale.forLanguageTag("pt-BR") assert(messages.helloWorld == "Hello World!") assert(messages.helloWorld(ptBr) == "Oi Mundo!")
Formatted messages are also supported:
, assert(messages.hello(name = "Scail") == "Hello Scail!") assert(messages.hello(name = "Scail")(ptBr) == "Oi Scail!")
One can pass custom parameters to the annotation by extending the
Messages
class: , @i18n object messages extends Messages(filename = "sample")
Please notice that parameter order in the method follows the same order as they were specified in the messages file. Therefore, it is highly recommended to use named parameters exclusively, as changes in the messages file can easily change parameter names or their relative order. Parameter types are inferred as
java.util.Date
if a date format is used in the messages file, asjava.lang.Number
if a number format is used, andAny
otherwise.- See also
SelectFormat Optionally, one may use the
@i18n
macro annotation for classes and objects. The@i18n
macro reads the messages file at compile time and generates typesafe methods for every localized message.
Examples: -
class
i18n extends Annotation with StaticAnnotation
- Annotations
- @SuppressWarnings() @compileTimeOnly( ... )
- See also
-
class
i18nMacro extends AnyRef
- Annotations
- @SuppressWarnings()
- See also