Errai 3.0.1-SNAPSHOT

org.jboss.errai.ui.client.local.spi
Class TranslationService

java.lang.Object
  extended by org.jboss.errai.ui.client.local.spi.TranslationService

public abstract class TranslationService
extends Object

A base class for a generated translation service that includes all of the translation visible at compile time.

Author:
eric.wittmann@redhat.com, Max Barkley

Constructor Summary
TranslationService()
          Constructor.
 
Method Summary
static String currentLocale()
           
 String format(String key, Object... args)
          Look up a message in the i18n resource message bundle by key, then format the message with the given arguments and return the result.
 String getActiveLocale()
           
static String getBrowserLocale()
          Gets the browser's configured locale.
 Collection<String> getSupportedLocales()
           
 String getTranslation(String translationKey)
          Gets the translation for the given i18n translation key.
 boolean isEnabled()
           
protected  void registerBundle(String jsonData, String locale)
          Registers the bundle with the translation service.
protected  void registerJSON(JSONMap data, String locale)
          Registers some i18n data with the translation service.
protected  void registerTranslation(String key, String value, String locale)
          Registers a single translation.
static void retranslateTemplatedBeans()
          Re-translate displayed Templated beans to the current locale.
static void setCurrentLocale(String locale)
          Forcibly set the current locale and re-translate all instantiated Templated beans.
static void setCurrentLocaleWithoutUpdate(String locale)
          Forcibly set the current locale but do not re-translate existing templated instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TranslationService

public TranslationService()
Constructor.

Method Detail

isEnabled

public boolean isEnabled()
Returns:
true if the translation service is enabled/should be used

getSupportedLocales

public Collection<String> getSupportedLocales()

registerBundle

protected void registerBundle(String jsonData,
                              String locale)
Registers the bundle with the translation service.

Parameters:
jsonData -

registerTranslation

protected void registerTranslation(String key,
                                   String value,
                                   String locale)
Registers a single translation.

Parameters:
key -
value -
locale -

registerJSON

protected void registerJSON(JSONMap data,
                            String locale)
Registers some i18n data with the translation service. This is called for each discovered bundle file.

Parameters:
data -
locale -

getTranslation

public String getTranslation(String translationKey)
Gets the translation for the given i18n translation key.

Parameters:
translationKey -

format

public String format(String key,
                     Object... args)
Look up a message in the i18n resource message bundle by key, then format the message with the given arguments and return the result.

Parameters:
key -
args -

getActiveLocale

public String getActiveLocale()

currentLocale

public static String currentLocale()
Returns:
the currently configured locale

getBrowserLocale

public static final String getBrowserLocale()
Gets the browser's configured locale.


setCurrentLocale

public static final void setCurrentLocale(String locale)
Forcibly set the current locale and re-translate all instantiated Templated beans.

Parameters:
locale -

setCurrentLocaleWithoutUpdate

public static final void setCurrentLocaleWithoutUpdate(String locale)
Forcibly set the current locale but do not re-translate existing templated instances. Mostly useful for testing.

Parameters:
locale -

retranslateTemplatedBeans

public static void retranslateTemplatedBeans()
Re-translate displayed Templated beans to the current locale.


Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.