LanguageUtils

uk.gov.hmrc.play.language.LanguageUtils
class LanguageUtils(langs: Langs, configuration: Configuration)(implicit messagesApi: MessagesApi)

This object provides access to common language utilities.

This object contains language codes for English and Welsh and a function to return the current language based on a request header.

Additionally, a Dates object is provided which provides helper functions to return correctly formatted dates in both English and Welsh.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Classlikes

object Dates extends Dates

Helper object to correctly display and format dates in both English and Welsh.

Helper object to correctly display and format dates in both English and Welsh.

This object provides a default implementation of the Dates trait in order to provide support for Welsh and English dates.

Attributes

Companion
trait
Supertypes
trait Dates
class Object
trait Matchable
class Any
Self type
Dates.type
trait Dates

A trait that correctly displays and formats dates in multiple languages.

A trait that correctly displays and formats dates in multiple languages.

This object contains helper methods to correctly format dates in any language supported by the IBM ICU library.

This trait requires a default timezone to be defined, as well as String values for the English words:

  • to
  • day
  • days

These values should come from a Messages file for each language that needs to be supported.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Dates

Value members

Concrete methods

def getCurrentLang(implicit request: RequestHeader): Lang

Returns the current language as a Lang object.

Returns the current language as a Lang object.

This function returns the current language as an i18n Lang object. It first checks that the PLAY_LANG cookie exists from the request object and then gets the value from it. If it does not exist then it returns the accepted language from the request object. If there is no Play application then it just defaults to return the accepted language in the request or use the default language.

Value parameters

request

The RequestHeader object to extract the language information from.

Attributes

Returns

Lang object containing the current langugage.

def isLangAvailable(lang: Lang): Boolean

Returns true if the lang passed exists within play.i18n.langs config value

Returns true if the lang passed exists within play.i18n.langs config value

Value parameters

lang

The language to check against

Attributes

Returns

A boolean on wether this language is supported in the current application

def onlyAvailableLanguages(langMap: Map[String, Lang]): Map[String, Lang]

Filters a Map of languages against what languages are enabled in the current application

Filters a Map of languages against what languages are enabled in the current application

This function returns a filtered Map containing only languages which are enabled in the play.i18n.langs configuration value. This function is to be used to dynamically populate which languages should be displayed on the applications language switcher.

Value parameters

langMap

List of all supported languages

Attributes

Returns

filtered list of enabled languages