Class TranslationMessage
- java.lang.Object
-
- com.vmware.vipclient.i18n.base.instances.TranslationMessage
-
public class TranslationMessage extends java.lang.Object implements Message
This class provide some APIs to get translation from VIP service in string-based, component-based level.For string-based level APIs, some need the source string as parameter, some don't, instead the source string is put to the resource bundle. Currently we support source string of the following form: message = messageText (argument messageText)* argument = noneArg | simpleArg | complexArg complexArg = pluralArg noneArg = '{' argNameOrNumber '}' simpleArg = '{' argNameOrNumber ',' argType [',' argStyle] '}' pluralArg = '{' argNameOrNumber ',' "plural" ',' pluralStyle '}' pluralStyle: see PluralFormat argNameOrNumber = argName | argNumber argName = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+ argNumber = '0' | ('1'..'9' ('0'..'9')*) argType = "number" | "date" argStyle for "number" type = "currency" | "percent" (argStyle is optional, when it's not specified, the number will be formatted in decimal format) argStyle for "date" type = "shortDate" | "mediumDate" | "longDate" | "fullDate" | "shortTime" | "mediumTime" | "longTime" | "fullTime" | "short" | "medium" | "long" | "full" (The format results of "short" | "medium" | "long" | "full" style are the combination of date and time.) (When argStyle for "date" is not specified, the date will be formatted in "medium" style) Below is an example for the format of source: "At {1,date,shortTime} on {1,date,longDate}, there was {2} on planet {0,number}."
-
-
Constructor Summary
Constructors Constructor Description TranslationMessage()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description VIPCfggetCfg()java.lang.StringgetMessage(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.Object... args)java.lang.StringgetMessage(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)java.lang.StringgetMessage(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.Object... args)Retrieves the localized messagejava.lang.StringgetMessage(java.util.Locale locale, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)Retrieves the localized messagejava.util.Map<java.lang.String,java.lang.String>getMessages(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component)java.util.Map<java.lang.String,java.lang.String>getMessages(java.util.Locale locale, java.lang.String component)Retrieves the set of localized messages from the cache.java.lang.StringgetMultiVersionMessage(java.util.Locale locale, java.lang.String version, java.lang.String component, java.lang.String key, java.lang.Object... args)Get one version's key based message if there is multiple versions for one product, the message's arguments are put in a variable object.java.lang.StringgetMultiVersionMessage(java.util.Locale locale, java.lang.String version, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)Get one version's key based message if there is multiple versions for one product, the message's arguments are put in a Map This method is designed specially for product which need multiple version's message at runtime by configuring the 'version' item in your config file for singleton client as multiple versions separated by comma or 'all'; if your product only need one version's message at runtime, please use @code getMessage API by configuring the 'version' as one specified version.java.lang.StringgetString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment, java.lang.Object... args)Deprecated.Replaced bygetMessage(Locale, String, String, Object...)which fetches source messages from messages_source.json of the component.java.lang.StringgetString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment, java.util.Map<java.lang.String,java.lang.Object> args)get a translation under the component of the configured productjava.lang.StringgetString2(java.lang.String component, java.lang.String bundle, java.util.Locale locale, java.lang.String key, java.lang.Object... args)Deprecated.Replaced bygetMessage(Locale, String, String, Object...)which fetches source messages from messages_source.json of the component.java.lang.StringgetString2(java.lang.String component, java.lang.String bundle, java.util.Locale locale, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)get one translation of the configured product from VIP, if message not found will get the English message from specified bundle.java.util.Map<java.lang.String,java.lang.String>getStrings(java.util.Locale locale, java.lang.String component)Deprecated.Replaced bygetMessages(Locale, String)java.util.Map<java.util.Locale,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>>getStrings(java.util.Set<java.util.Locale> locales, java.util.Set<java.lang.String> components)get multiple components' translations from VIP serverbooleanisAvailable(java.lang.String component, java.lang.String key, java.util.Locale locale)check if one translation of specified key is availablebooleanisAvailable(java.lang.String component, java.util.Locale locale)check if the translations of specified component is availablebooleanpostString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment)Deprecated.Collection of source message is not supported at runtime.booleanpostStrings(java.util.Locale locale, java.lang.String component, java.util.List<org.json.simple.JSONObject> sources)Deprecated.Collection of source message is not supported at runtime.voidsetCfg(VIPCfg cfg)
-
-
-
Method Detail
-
getCfg
public VIPCfg getCfg()
-
setCfg
public void setCfg(VIPCfg cfg)
-
getMessage
public java.lang.String getMessage(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.Object... args)Retrieves the localized message- Parameters:
locale- The locale in which the message is requested to be localizedcomponent- The Singleton component in which the message belongskey- The key that represents the messageargs- Values to replace placeholders in the message with- Returns:
- One of the items in the following priority-ordered list:
- Throws:
VIPJavaClientException- If none from the list below is available- The source message, if source message hasn't been collected and translated
- The message in the requested locale
- The message in the next available fallback locale
- The source message
-
getMessage
public java.lang.String getMessage(java.util.Locale locale, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)Retrieves the localized message- Parameters:
locale- The locale in which the message is requested to be localizedcomponent- The Singleton component in which the message belongskey- The key that represents the messageargs- Named arguments to replace placeholders in the message with- Returns:
- One of the items in the following priority-ordered list:
- Throws:
VIPJavaClientException- If none from the list below is available- The source message, if source message hasn't been collected and translated
- The message in the requested locale
- The message in the next available fallback locale
- The source message
-
getMessage
public java.lang.String getMessage(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)
-
getMessage
public java.lang.String getMessage(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.Object... args)
-
getMultiVersionMessage
public java.lang.String getMultiVersionMessage(java.util.Locale locale, java.lang.String version, java.lang.String component, java.lang.String key, java.lang.Object... args)Get one version's key based message if there is multiple versions for one product, the message's arguments are put in a variable object. This method is designed specially for product which need multiple version's message at runtime by configuring the 'version' item in your config file for singleton client as multiple versions separated by comma or 'all'; if your product only need one version's message at runtime, please use @code getMessage API by configuring the 'version' as one specified version. They can't be called at the same time in one product's code since the value of the configured 'version' is conflict, but can be used simultaneously in different products' code as different products have different config file which avoids conflict. If the source message at your local or sent to Singleton service is different with that for translation, will return the former directly; if the requested message is not found, will fallback to source message; if the source message is empty, will throw VIPJavaClientException.- Parameters:
locale- Set as default locale if emptyversion-component- throw VIPJavaClientException if emptykey-args-- Returns:
- Throws:
VIPJavaClientException
-
getMultiVersionMessage
public java.lang.String getMultiVersionMessage(java.util.Locale locale, java.lang.String version, java.lang.String component, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)Get one version's key based message if there is multiple versions for one product, the message's arguments are put in a Map This method is designed specially for product which need multiple version's message at runtime by configuring the 'version' item in your config file for singleton client as multiple versions separated by comma or 'all'; if your product only need one version's message at runtime, please use @code getMessage API by configuring the 'version' as one specified version. They can't be called at the same time in one product's code since the value of the configured 'version' is conflict, but can be used simultaneously in different products' code as different products have different config file which avoids conflict. If the source message at your local or sent to Singleton service is different with that for translation, will return the former directly; if the requested message is not found, will fallback to source message; if the source message is empty, will throw VIPJavaClientException.- Parameters:
locale- Set as default locale if emptyversion-component- throw VIPJavaClientException if emptykey-args-- Returns:
- Throws:
VIPJavaClientException
-
getString
public java.lang.String getString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment, java.lang.Object... args)Deprecated.Replaced bygetMessage(Locale, String, String, Object...)which fetches source messages from messages_source.json of the component. This method only supports English as both the default and the source locale.get a translation under the component of the configured product- Parameters:
locale- an object used to get the source's translationcomponent- defined on VIP service, it will be created automatically if not existkey- identify the sourcesource- it's English source which will be return if no translation available. For the format of source, please refer to the class annotation.comment- used to describe the source to help understand the source for the translators.args- used to format the message with placeholder, it's not required if the message doesn't contain any placeholder- Returns:
- string
-
getString
public java.lang.String getString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment, java.util.Map<java.lang.String,java.lang.Object> args)get a translation under the component of the configured product- Parameters:
locale- an object used to get the source's translationcomponent- defined on VIP service, it will be created automatically if not existkey- identify the sourcesource- it's English source which will be return if no translation available. For the format of source, please refer to the class annotation.comment- used to describe the source to help understand the source for the translators.args- named arguments used to format the message with placeholder- Returns:
- string
-
postStrings
public boolean postStrings(java.util.Locale locale, java.lang.String component, java.util.List<org.json.simple.JSONObject> sources)Deprecated.Collection of source message is not supported at runtime.post a set of sources to remote VIP server which is configured- Parameters:
locale- currently no matter which locale it is, all sources will be considered as Englishcomponent- the component name used to categorize the sources and auto-created first timesources- the JSONObject should contain three attributes(key, source, commentForSource). For the format of source, please refer to the class annotation.- Returns:
- a boolean to indicate the post status
-
postString
public boolean postString(java.util.Locale locale, java.lang.String component, java.lang.String key, java.lang.String source, java.lang.String comment)Deprecated.Collection of source message is not supported at runtime.post a source to remote VIP server- Parameters:
locale- an object used to get the source's translationcomponent- defined on VIP service, it will be created automatically if not existkey- identify the sourcesource- it's English source which will be return if no translation available. For the format of source, please refer to the class annotation.comment- used to describe the source to help understand the source for the translators.- Returns:
- a boolean to indicate post succeeded or failed
-
getStrings
@Deprecated public java.util.Map<java.lang.String,java.lang.String> getStrings(java.util.Locale locale, java.lang.String component)Deprecated.Replaced bygetMessages(Locale, String)get one component's translations from VIP of the configured product- Parameters:
locale- a language tag to get the translationscomponent- defined on VIP service, it will be created automatically if not exist- Returns:
- a map contains all translations of the component mapped by the source's key
-
getMessages
public java.util.Map<java.lang.String,java.lang.String> getMessages(java.util.Locale locale, java.lang.String component)Retrieves the set of localized messages from the cache. It applies locale fallback mechanism in case of failure.- Parameters:
component- The Singleton componentlocale- The locale in which the messages are requested to be localized- Returns:
- One of the items in the following priority-ordered list:
- The messages in the requested locale
- The messages in the default locale
- The source messages
-
getMessages
public java.util.Map<java.lang.String,java.lang.String> getMessages(java.lang.String resourceBundle, java.util.Locale locale, java.lang.String component)
-
getStrings
public java.util.Map<java.util.Locale,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>> getStrings(java.util.Set<java.util.Locale> locales, java.util.Set<java.lang.String> components)get multiple components' translations from VIP server- Parameters:
locales- locales to get the translations of themcomponents- names of the components to get translation- Returns:
- a map contains all translations of the components of specified locales. Key is loale; value is also a map whose key is component and value is the messages belong to this component.
-
getString2
public java.lang.String getString2(java.lang.String component, java.lang.String bundle, java.util.Locale locale, java.lang.String key, java.lang.Object... args)Deprecated.Replaced bygetMessage(Locale, String, String, Object...)which fetches source messages from messages_source.json of the component. This method only supports English as both the default and the source locale.get one translation of the configured product from VIP, if message not found will get the English message from specified bundle.- Parameters:
component- defined on VIP service, it will be created automatically if not existbundle- properties file name, normally it should be put under the root 'src' pathlocale- an object used to get the source's translationkey- identify the sourceargs- used to format the message with placeholder, it's not required if the message doesn't contain any placeholder- Returns:
- a message of translation, if the translation is not found from VIP service, it will return the value defined in the bundle searching by the key
-
getString2
public java.lang.String getString2(java.lang.String component, java.lang.String bundle, java.util.Locale locale, java.lang.String key, java.util.Map<java.lang.String,java.lang.Object> args)get one translation of the configured product from VIP, if message not found will get the English message from specified bundle.- Parameters:
component- defined on VIP service, it will be created automatically if not existbundle- properties file name, normally it should be put under the root 'src' pathlocale- an object used to get the source's translationkey- identify the sourceargs- named arguments used to format the message with placeholder- Returns:
- a message of translation, if the translation is not found from VIP service, it will return the value defined in the bundle searching by the key
-
isAvailable
public boolean isAvailable(java.lang.String component, java.util.Locale locale)check if the translations of specified component is available- Parameters:
component-locale-- Returns:
-
isAvailable
public boolean isAvailable(java.lang.String component, java.lang.String key, java.util.Locale locale)check if one translation of specified key is available- Parameters:
component-locale-- Returns:
-
-