Package net.kyori.adventure.translation
Interface TranslationRegistry
- All Superinterfaces:
- Translator
public interface TranslationRegistry extends Translator
A registry of translations.
- Since:
- 4.0.0
- 
Field SummaryFields Modifier and Type Field Description static PatternSINGLE_QUOTE_PATTERNA pattern which matches a single quote.
- 
Method SummaryModifier and Type Method Description static @NonNull TranslationRegistrycreate(Key name)Creates a new standalone translation registry.voiddefaultLocale(@NonNull Locale locale)Sets the default locale used by this registry.voidregister(@NonNull String key, @NonNull Locale locale, @NonNull MessageFormat format)Registers a translation.default voidregisterAll(@NonNull Locale locale, @NonNull Path path, boolean escapeSingleQuotes)Registers a resource bundle of translations.default voidregisterAll(@NonNull Locale locale, @NonNull Map<String,MessageFormat> formats)Registers a map of translations.default voidregisterAll(@NonNull Locale locale, @NonNull ResourceBundle bundle, boolean escapeSingleQuotes)Registers a resource bundle of translations.default voidregisterAll(@NonNull Locale locale, @NonNull Set<String> keys, Function<String,MessageFormat> function)Registers a resource bundle of translations.@Nullable MessageFormattranslate(@NonNull String key, @NonNull Locale locale)Gets a message format from a key and locale.voidunregister(@NonNull String key)Unregisters a translation key.
- 
Field Details- 
SINGLE_QUOTE_PATTERNA pattern which matches a single quote.- Since:
- 4.0.0
 
 
- 
- 
Method Details- 
createCreates a new standalone translation registry.- Returns:
- a translation registry
- Since:
- 4.0.0
 
- 
translateGets a message format from a key and locale.If a translation for localeis not found, we will then trylocalewithout a country code, and then finally fallback to a default locale.- Specified by:
- translatein interface- Translator
- Parameters:
- locale- a locale
- key- a translation key
- Returns:
- a message format or nullto skip translation
- Since:
- 4.0.0
 
- 
defaultLocaleSets the default locale used by this registry.- Parameters:
- locale- the locale to use a default
- Since:
- 4.0.0
 
- 
registerRegisters a translation.final TranslationRegistry registry; registry.register("example.hello", Locale.US, new MessageFormat("Hi, {0}. How are you?"));- Parameters:
- key- a translation key
- locale- a locale
- format- a translation format
- Throws:
- IllegalArgumentException- if the translation key is already exists
- Since:
- 4.0.0
 
- 
registerAllRegisters a map of translations.- Parameters:
- locale- a locale
- formats- a map of translation keys to formats
- Throws:
- IllegalArgumentException- if a translation key is already exists
- Since:
- 4.0.0
- See Also:
- register(String, Locale, MessageFormat)
 
- 
registerAllRegisters a resource bundle of translations.- Parameters:
- locale- a locale
- path- a path to the resource bundle
- escapeSingleQuotes- whether to escape single quotes
- Throws:
- IllegalArgumentException- if a translation key is already exists
- Since:
- 4.0.0
- See Also:
- registerAll(Locale, ResourceBundle, boolean)
 
- 
registerAlldefault void registerAll(@NonNull Locale locale, @NonNull ResourceBundle bundle, boolean escapeSingleQuotes)Registers a resource bundle of translations.It is highly recommended to create your bundle using UTF8ResourceBundleControlas your bundle control for UTF-8 support - for example:final ResourceBundle bundle = ResourceBundle.getBundle("my_bundle", Locale.GERMANY, UTF8ResourceBundleControl.get()); registry.registerAll(Locale.GERMANY, bundle, false);- Parameters:
- locale- a locale
- bundle- a resource bundle
- escapeSingleQuotes- whether to escape single quotes
- Throws:
- IllegalArgumentException- if a translation key is already exists
- Since:
- 4.0.0
- See Also:
- UTF8ResourceBundleControl
 
- 
registerAlldefault void registerAll(@NonNull Locale locale, @NonNull Set<String> keys, Function<String,MessageFormat> function)Registers a resource bundle of translations.- Parameters:
- locale- a locale
- keys- the translation keys to register
- function- a function to transform a key into a message format
- Throws:
- IllegalArgumentException- if a translation key is already exists
- Since:
- 4.0.0
 
- 
unregisterUnregisters a translation key.- Parameters:
- key- a translation key
- Since:
- 4.0.0
 
 
-