Package com.vaadin.flow.i18n
Interface I18NProvider
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DefaultI18NProvider
I18N provider interface for internationalization usage.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptiongetAllTranslations
(Locale locale) Retrieves all available translations.Get the locales that we have translations for.default String
getTranslation
(Object key, Locale locale, Object... params) Get the translation for key with given locale.getTranslation
(String key, Locale locale, Object... params) Get the translation for key with given locale.getTranslations
(Collection<String> keys, Locale locale) Retrieves the translations for a collection of keys.static String
Get the translation for key viaI18NProvider
instance retrieved from the current VaadinService.static String
Get the translation for key with given locale viaI18NProvider
instance retrieved from the current VaadinService.
-
Method Details
-
getProvidedLocales
Get the locales that we have translations for. The first locale should be the default locale.- Returns:
- provided locales
-
getTranslation
Get the translation for key with given locale.Note! For usability and catching missing translations implementation should never return a null, but an exception string e.g. '!{key}!'
- Parameters:
key
- translation keylocale
- locale to useparams
- parameters used in translation string- Returns:
- translation for key if found
-
getTranslation
Get the translation for key with given locale.Note! For usability and catching missing translations implementation should never return a null, but an exception string e.g. '!{key}!'
- Parameters:
key
- translation keylocale
- locale to useparams
- parameters used in translation string- Returns:
- translation for key if found
-
getAllTranslations
Retrieves all available translations. This is currently used only by Hilla in development mode.- Parameters:
locale
- locale to use- Returns:
- a map of all available translations (the default implementation just returns an empty map)
-
getTranslations
Retrieves the translations for a collection of keys. By default, it calls `getTranslation` on each key, but this can be optimized by the implementation.- Parameters:
keys
- the keys to be translatedlocale
- locale to use- Returns:
- a map of translations
-
translate
Get the translation for key viaI18NProvider
instance retrieved from the current VaadinService. Uses the current UI locale, or if not available, then the default locale.- Parameters:
key
- translation keyparams
- parameters used in translation string- Returns:
- translation for key if found
- Throws:
IllegalStateException
- thrown if no I18NProvider found from the VaadinService
-
translate
Get the translation for key with given locale viaI18NProvider
instance retrieved from the current VaadinService.- Parameters:
locale
- locale to usekey
- translation keyparams
- parameters used in translation string- Returns:
- translation for key if found
- Throws:
IllegalStateException
- thrown if no I18NProvider found from the VaadinService
-