public interface I18nService
Using property files for localization is described in Internationalising your plugin.
Fallback messages should never be specified by internal developers. All internal messages should be added to properties files for translation. The variants accepting a fallback message are intended for external plugin developers only. Internal developers should use:
Plugin developers are also encouraged to use properties files but the ability to specify the message directly in the call is provided as a convenience, especially for in-house plugins which will only be used by speakers of a single language.Modifier and Type | Method and Description |
---|---|
KeyedMessage |
createKeyedMessage(String key,
Object... arguments)
Given a property key and a list of arguments, it returns:
a
KeyedMessage that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. |
Map<String,String> |
getAllTranslationsForPrefix(String prefix)
Given a property key prefix, this method will return all translations where the key starts with the given prefix as key to
value mappings using the current locale.
|
Map<String,String> |
getAllTranslationsForPrefix(String prefix,
Locale locale)
Given a property key prefix, this method will return all translations where the key starts with the given prefix as key ->
value mappings.
|
KeyedMessage |
getKeyedText(I18nKey i18nKey)
Given an
I18nKey it returns:
a KeyedMessage that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. |
KeyedMessage |
getKeyedText(String key,
String fallbackMessage,
Object... arguments)
Given a property key, a fallback message and a list of arguments, it returns:
a
KeyedMessage that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. |
String |
getMessage(I18nKey key)
Given a
key it returns:
the localized text formatted with the given arguments if the key can be resolved. |
String |
getMessage(Locale locale,
String key,
Object... arguments)
Given a locale, a property key and a list of arguments, it returns:
the localized text formatted with the given arguments if the key can be resolved.
|
String |
getMessage(String key,
Object... arguments)
Given a property key and a list of arguments, it returns:
the localized text formatted with the given arguments if the key can be resolved.
|
String |
getMessagePattern(Locale locale,
String key)
Given a locale and a property key it returns:
the localized message pattern if the key can be resolved.
|
String |
getMessagePattern(String key)
Given a property key it returns:
the associated message pattern if the key can be resolved.
|
String |
getMessagePattern(String key,
String fallbackPattern)
Given a property key and the fallback text message, it returns:
the associated message pattern if the key can be resolved.
|
String |
getText(Locale locale,
String key,
String fallbackMessage,
Object... arguments)
Given a property key, a locale, a fallback text message and a list of arguments, it returns:
the localized text formatted with the given arguments if the key can be resolved.
|
String |
getText(String key,
String fallbackMessage,
Object... arguments)
Given a property key, the fallback text message and a list of arguments, it returns:
the localized text formatted with the given arguments if the key can be resolved.
|
@Nonnull KeyedMessage createKeyedMessage(@Nonnull String key, @Nonnull Object... arguments)
KeyedMessage
that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. Otherwise...The KeyedMessage returned is useful for priming Exceptions where the localized and non-localized messages need to differ to ensure the end use sees the message localized in their language but the logs record the message for the root locale.
key
- the key for the i18ned messagearguments
- optional list of arguments for the message.@Nonnull String getMessage(@Nonnull String key, @Nonnull Object... arguments)
key
- the key for the i18ned messagearguments
- optional list of arguments for the message.@Nonnull String getMessage(@Nonnull I18nKey key)
key
it returns:
key
- the key for the i18ned message@Nonnull String getMessage(@Nonnull Locale locale, @Nonnull String key, @Nullable Object... arguments)
locale
- the locale for the lookupkey
- the key for the i18ned messagearguments
- optional list of arguments for the message.@Nonnull String getText(@Nonnull Locale locale, @Nonnull String key, @Nullable String fallbackMessage, @Nonnull Object... arguments)
locale
- the locale for the lookupkey
- key for the i18ned messagefallbackMessage
- the optional message to fallback to if lookup failsarguments
- optional list of arguments for the message.@Nonnull String getText(@Nonnull String key, @Nullable String fallbackMessage, @Nonnull Object... arguments)
key
- the key for the i18ned messagefallbackMessage
- the optional message to fallback to if lookup failsarguments
- optional list of arguments for the message.@Nullable String getMessagePattern(@Nonnull String key)
key
- the key for the i18n patternjava.text.MessageFormat
or with AJS.format()
@Nullable String getMessagePattern(@Nonnull String key, @Nullable String fallbackPattern)
key
- the key for the i18n patternfallbackPattern
- the optional pattern to fallback to if lookup failsjava.text.MessageFormat
or with AJS.format()
@Nullable String getMessagePattern(@Nonnull Locale locale, @Nonnull String key)
locale
- the locale for the lookupkey
- the key for the i18n patternjava.text.MessageFormat
or with AJS.format()
@Nonnull KeyedMessage getKeyedText(@Nonnull I18nKey i18nKey)
I18nKey
it returns:
KeyedMessage
that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. Otherwise...
The KeyedMessage returned is useful for priming Exceptions where the localized and non-localized messages
need to differ to ensure the end use sees the message localized in their language but the logs record the
message for the root locale.
The result of this method should be the same as calling #createKeyedMessage(i18nKey.getKey(), i18nKey.getArguments())
i18nKey
- the key for the i18ned message@Nonnull KeyedMessage getKeyedText(@Nonnull String key, @Nullable String fallbackMessage, @Nonnull Object... arguments)
KeyedMessage
that composes the localized and formatted message for the current locale,
the localized and formatted message for the root locale and the original key for the message. Otherwise...The KeyedMessage returned is useful for priming Exceptions where the localized and non-localized messages need to differ to ensure the end user sees the message localized in their language but the logs record the message for the root locale.
key
- the key for the i18ned messagefallbackMessage
- the optional message to fallback to if lookup failsarguments
- optional list of arguments for the message.@Nonnull Map<String,String> getAllTranslationsForPrefix(@Nonnull String prefix)
prefix
- the prefix for a particular key to start with. Empty string will match everything, which may be
slow. Throws NullPointerException
if null
.Map
of i18nKey to translation mappings where i18nKey starts with the prefix. An empty map if no matches.NullPointerException
- if link
is null
@Nonnull Map<String,String> getAllTranslationsForPrefix(@Nonnull String prefix, @Nonnull Locale locale)
prefix
- the prefix for a particular key to start with. Empty string will match everything, which may be
slow. Throws NullPointerException
if null
.locale
- the locale for which to lookup translations. Throws NullPointerException
if null
.Map
of i18nKey to translation mappings where i18nKey starts with the prefix. An empty map if no matches.NullPointerException
- if prefix
or link
are null
Copyright © 2019 Atlassian. All rights reserved.