Packages

class Messages extends Logging

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 the messages.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.

Source
Messages.scala
Examples:
  1. @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:

  2. ,
  3. 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:

  4. ,
  5. @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, as java.lang.Number if a number format is used, and Any otherwise.

See also

MessageFormat

PluralFormat

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.

Linear Supertypes
Logging, LazyLogging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Messages
  2. Logging
  3. LazyLogging
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Messages(folder: String = "i18n", filename: String = "messages", extension: String = "conf", cache: Cache[Locale, Config] = SimpleCache.empty, formatCache: Cache[KeyLocale, MessageFormat] = NoCache.empty)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Messages to any2stringadd[Messages] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Messages, B)
    Implicit
    This member is added by an implicit conversion from Messages to ArrowAssoc[Messages] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def apply(key: Key, args: (String, Any)*)(implicit locale: Locale): String

    Formats the localized message pattern identified by key for the given locale using the given arguments args.

    Formats the localized message pattern identified by key for the given locale using the given arguments args.

    key

    the key identifying the message pattern

    args

    a map of arguments to be replaced into the pattern

    locale

    the locale

    returns

    the formatted localized message if it exists, a default placeholder otherwise

    Annotations
    @SuppressWarnings()
  7. def apply(key: Key)(implicit locale: Locale): String

    Returns the localized message identified by key for the given locale.

    Returns the localized message identified by key for the given locale.

    key

    the key identifying the message

    locale

    the locale

    returns

    the localized message if it exists, a default placeholder otherwise

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  10. def ensuring(cond: (Messages) ⇒ Boolean, msg: ⇒ Any): Messages
    Implicit
    This member is added by an implicit conversion from Messages to Ensuring[Messages] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: (Messages) ⇒ Boolean): Messages
    Implicit
    This member is added by an implicit conversion from Messages to Ensuring[Messages] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: Boolean, msg: ⇒ Any): Messages
    Implicit
    This member is added by an implicit conversion from Messages to Ensuring[Messages] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean): Messages
    Implicit
    This member is added by an implicit conversion from Messages to Ensuring[Messages] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Messages to StringFormat[Messages] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  18. def get(key: Key, args: (String, Any)*)(implicit locale: Locale): Option[String]

    Optionally formats the localized message pattern identified by key for the given locale using the given arguments args.

    Optionally formats the localized message pattern identified by key for the given locale using the given arguments args.

    key

    the key identifying the message pattern

    args

    a map of arguments to be replaced into the pattern

    locale

    the locale

    returns

    the optional value containing the formatted localized message if it exists, None otherwise

    Annotations
    @SuppressWarnings()
  19. def get(key: Key)(implicit locale: Locale): Option[String]

    Optionally returns the localized message identified by key for the given locale.

    Optionally returns the localized message identified by key for the given locale.

    key

    the key identifying the message

    locale

    the locale

    returns

    the optional value containing the localized message if it exists, None otherwise

  20. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  21. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. lazy val logger: Logger
    Attributes
    protected
    Definition Classes
    LazyLogging
    Annotations
    @transient()
  24. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  26. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  32. def [B](y: B): (Messages, B)
    Implicit
    This member is added by an implicit conversion from Messages to ArrowAssoc[Messages] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Logging

Inherited from LazyLogging

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from Messages to any2stringadd[Messages]

Inherited by implicit conversion StringFormat from Messages to StringFormat[Messages]

Inherited by implicit conversion Ensuring from Messages to Ensuring[Messages]

Inherited by implicit conversion ArrowAssoc from Messages to ArrowAssoc[Messages]

Ungrouped