final case class Message extends Product with Serializable
Contains a language independent message.
In order to support internationalisation of applications it is necessary to provide a mechanism that allows a string to be generated in a language independent way. The Message class provides such a mechanism.
A Message contains information used to
extract a string and format it when it needs to be displayed.
In order to display the string it is necessary to invoke the
showLocal
method passing in an implicit java.util.Locale
. The locale
determines what language is used to extract the string.
A language independent string is identified by three things, namely:
bundle
identifies a group of strings stored within the one resourcecode
indicates which string to extract from the bundleargs
that are interpolated into the string when displayed
Message objects may be passed around and
the showLocal
method only invoked when it is necessary to display the
string in a language dependent way.
Let's look at an example:
class Messages_en extends java.util.ListResourceBundle { final override val getContents: Array[Array[AnyRef]] = Array( Array("BadValue", "The bad value is %s") ... ) } class Messages_de extends java.util.ListResourceBundle { final override val getContents: Array[Array[AnyRef]] = Array( Array("BadValue", "Der falsche Wert ist %s") ... ) } implicit val bundle = MessageBundle("Messages") val message = Message("BadValue", "abc123") implicit val locale = Locale.ENGLISH message.showLocal message.showLocal(Locale.GERMAN)
Output:
The bad value is abc123 Der falsche Wert ist abc123
The Messages_en
class contains a mapping between the code
used to
identify a string and its English message, similarly Messages_de
contains the same codes with the equivalent German message.
The Message is created using an implicit
MessageBundle identifying the base
class name containing the translated strings. Since the translated strings
contain a format marker (%s
) an argument must be supplied along
with the code when the Message
is instantiated.
The showLocal
method is used when a Message is
to be displayed. The method takes an implicit java.util.Locale
identifying which language is to be shown. The method is an extension
method added by the ShowLocal type class.
- Source
- Message.scala
- Alphabetic
- By Inheritance
- Message
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val args: Any*
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- val bundle: MessageBundle
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- val code: String
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Documentation for the Axiell Utilities Project
Overview
The Axiell Utilities Project attempts to provide a small library of classes and object applicable to most Axiell developments. The library is not geared towards any one project and so should be useful for new projects as well as existing ones.
The library is based on a few simple principles, namely:
Package structure
The
package consists of a number of utilities, where each utility provides a single piece of functionality.com.axiell.util
Notable utilities are:
Configure
generic configuration reader allowing application settings defined as resources to be interrogated.Error
generic error handling class defining a locale independent error message along with details relating to the context of the error. The context may include an exception and other relevant values.Formatter
retrieves and formats a locale specific string from a specified resource bundle. The formatting is specified in aC
printf style.Implicits
implements implicit methods and classes used to pimp methods onto existing classes (e.g.fold()
method toBoolean
class) and to provide implicit implementations for the JsonLocal and ShowLocal type classes.JsonLocal
type class used to output locale specific JSON structures. Implementations exist for Message and Error.Message
provides a locale independent mechanism for handling strings. The strings for a given locale are stored in resource bundles that are accessed when the message is to be displayed.ShowLocal
type class used to show locale specific strings. Allows Message and Error to be converted to a given language string.Dependencies
The list of dependencies are:
Typesafe Config
a generic configuration file reader. The library is used by theConfigure
class to access settings stored as resources within an application.