com.atlassian.sal.core.message
Class AbstractI18nResolver

java.lang.Object
  extended by com.atlassian.sal.core.message.AbstractI18nResolver
All Implemented Interfaces:
I18nResolver

public abstract class AbstractI18nResolver
extends Object
implements I18nResolver

Basic skeleton of an implementation of I18nResolver, which host applications can use to get started. Subclasses should only need to implement the abstract methods resolveText(String, java.io.Serializable[]) and resolveText(Locale, String, Serializable[]).


Constructor Summary
AbstractI18nResolver()
           
 
Method Summary
 Message createMessage(String key, Serializable... arguments)
          Creates an instance of Message.
 MessageCollection createMessageCollection()
           
 String getText(Locale locale, Message message)
          Given a Message this method: returns the i18ned text formatted with the message arguments if the message key can be resolved. Otherwise, returns the message key (formatted with the message arguments).
 String getText(Locale locale, String key)
          Does the same as I18nResolver.getText(Locale, String, java.io.Serializable...) however it is needed for velocity.
 String getText(Locale locale, String key, Serializable... arguments)
          Given a key and a list of arguments: this method returns the i18ned text formatted with the arguments if the key can be resolved. otherwise, the key itself will be returned (after formatting). Arguments may also be of the form Message which means they will be resolved as well before being included as an argument.
 String getText(Message message)
          Given a Message this method: returns the i18ned text formatted with the message arguments if the message key can be resolved. Otherwise, returns the message key (formatted with the message arguments). Uses the default locale.
 String getText(String key)
          Does the same as I18nResolver.getText(String, java.io.Serializable...) however it is needed for velocity.
 String getText(String key, Serializable... arguments)
          Given a key and a list of arguments: this method returns the i18ned text formatted with the arguments if the key can be resolved. otherwise, the key itself will be returned (after formatting). Arguments may also be of the form Message which means they will be resolved as well before being included as an argument.
abstract  String resolveText(Locale locale, String key, Serializable[] arguments)
          Subclasses should implement this method to dispatch to a matching language in the given locale.
abstract  String resolveText(String key, Serializable[] arguments)
          Subclasses should implement this method to dispatch to a matching language in (in order of preference): the user's locale the application's configured locale, or the system default locale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.sal.api.message.I18nResolver
getAllTranslationsForPrefix, getAllTranslationsForPrefix, getRawText
 

Constructor Detail

AbstractI18nResolver

public AbstractI18nResolver()
Method Detail

getText

public String getText(String key,
                      Serializable... arguments)
Description copied from interface: I18nResolver
Given a key and a list of arguments:
  1. this method returns the i18ned text formatted with the arguments if the key can be resolved.
  2. otherwise, the key itself will be returned (after formatting).
Arguments may also be of the form Message which means they will be resolved as well before being included as an argument. Uses the default locale.

Specified by:
getText in interface I18nResolver
Parameters:
key - key for the i18ned message
arguments - Optional list of arguments for the message.
Returns:
I18ned string

getText

public String getText(Locale locale,
                      String key,
                      Serializable... arguments)
Description copied from interface: I18nResolver
Given a key and a list of arguments:
  1. this method returns the i18ned text formatted with the arguments if the key can be resolved.
  2. otherwise, the key itself will be returned (after formatting).
Arguments may also be of the form Message which means they will be resolved as well before being included as an argument.

Specified by:
getText in interface I18nResolver
Parameters:
locale - the locale to use for the i18ned text
key - key for the i18ned message
arguments - Optional list of arguments for the message.
Returns:
I18ned string

getText

public String getText(String key)
Description copied from interface: I18nResolver
Does the same as I18nResolver.getText(String, java.io.Serializable...) however it is needed for velocity.

Specified by:
getText in interface I18nResolver
Parameters:
key - key for the i18ned message
Returns:
I18ned string

getText

public String getText(Locale locale,
                      String key)
Description copied from interface: I18nResolver
Does the same as I18nResolver.getText(Locale, String, java.io.Serializable...) however it is needed for velocity.

Specified by:
getText in interface I18nResolver
Parameters:
locale - the locale to use for the i18ned text
key - key for the i18ned message
Returns:
I18ned string

getText

public String getText(Message message)
Description copied from interface: I18nResolver
Given a Message this method:
  1. returns the i18ned text formatted with the message arguments if the message key can be resolved.
  2. Otherwise, returns the message key (formatted with the message arguments).
Uses the default locale.

Specified by:
getText in interface I18nResolver
Parameters:
message - The message to i18n
Returns:
I18ned string

getText

public String getText(Locale locale,
                      Message message)
Description copied from interface: I18nResolver
Given a Message this method:
  1. returns the i18ned text formatted with the message arguments if the message key can be resolved.
  2. Otherwise, returns the message key (formatted with the message arguments).

Specified by:
getText in interface I18nResolver
Parameters:
locale - the locale to use for the i18ned text
message - The message to i18n
Returns:
I18ned string

resolveText

public abstract String resolveText(String key,
                                   Serializable[] arguments)
Subclasses should implement this method to dispatch to a matching language in (in order of preference):

Parameters:
key - the key to translate.
arguments - the arguments to be inserted into the translated string.
Returns:
the translated string.

resolveText

public abstract String resolveText(Locale locale,
                                   String key,
                                   Serializable[] arguments)
Subclasses should implement this method to dispatch to a matching language in the given locale.

Parameters:
locale - the locale to translate into.
key - the key to translate.
arguments - the arguments to be inserted into the translated string.
Returns:
the translated string.

createMessage

public Message createMessage(String key,
                             Serializable... arguments)
Description copied from interface: I18nResolver
Creates an instance of Message.

Specified by:
createMessage in interface I18nResolver
Parameters:
key - The message key
arguments - The arguments to interpolate
Returns:
The message

createMessageCollection

public MessageCollection createMessageCollection()
Specified by:
createMessageCollection in interface I18nResolver
Returns:
an instance of MessageCollection.


Copyright © 2015 Atlassian. All rights reserved.