public class WeblateMessageSource extends org.springframework.context.support.AbstractMessageSource implements AllPropertiesSource
MessageSource loading texts from Weblate translation server via REST
API.
If you use the WeblateMessageSource with a parent
ReloadableResourceBundleMessageSource
and want to resolve all properties you can use the
AllPropertiesReloadableResourceBundleMessageSource
instead.
| Constructor and Description |
|---|
WeblateMessageSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCache()
Clears the cache for all locales and message bundles.
|
Properties |
getAllProperties(Locale locale) |
String |
getBaseUrl() |
Map<String,Locale> |
getCodeToLocale() |
String |
getComponent() |
Set<Locale> |
getExistingLocales() |
long |
getInitialCacheTimestamp() |
long |
getMaxAgeMilis() |
String |
getProject() |
String |
getQuery() |
void |
registerLocaleMapping(String code,
Locale locale)
Registers a manual mapping of a Weblate code to a
Locale. |
void |
reload(Locale... locales)
Updates the translations for the given locales from Weblate.
|
void |
reloadExistingLocales()
Reload the cached list of existing locales.
|
void |
removeEmptyCacheEntries()
Remove cache entries that do not contain a translation.
|
protected MessageFormat |
resolveCode(String code,
Locale locale) |
protected String |
resolveCodeWithoutArguments(String code,
Locale locale) |
void |
setBaseUrl(String baseUrl)
Set Weblate base URL.
|
void |
setCodeToLocale(Map<String,Locale> codeToLocale)
Set the manual mapping of Weblate codes to
Locales. |
void |
setComponent(String component)
Set component.
|
void |
setInitialCacheTimestamp(long initialCacheTimestamp)
Set the timestamp that is used when no cache entry is set.
|
void |
setMaxAgeMilis(long maxAgeMilis)
Sets the max age for items in the cache (in milliseconds).
|
void |
setProject(String project)
Set project.
|
void |
setQuery(String query)
Set the Weblate query for extracting the texts.
|
void |
setRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
Set the
RestTemplate to use for getting data from Weblate REST API. |
void |
useAuthentication(String authToken)
Sets
WeblateAuthenticationInterceptor for calling the REST API. |
getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessagepublic String getBaseUrl()
public void setBaseUrl(String baseUrl)
baseUrl - the URL of your Weblate instance without trailing /public String getProject()
public void setProject(String project)
project - project slug in Weblatepublic String getComponent()
public void setComponent(String component)
component - component slug in Weblatepublic long getInitialCacheTimestamp()
public void setInitialCacheTimestamp(long initialCacheTimestamp)
This can be used when you have bundled translations that are provided via a parent message source. Only translations newer than this timestamp will ever be fetched from weblate.
initialCacheTimestamp - the initial cache timestamppublic String getQuery()
public void setQuery(String query)
See also: Weblate Search.
query - the Weblate querypublic long getMaxAgeMilis()
public void setMaxAgeMilis(long maxAgeMilis)
maxAgeMilis - the max age for items in the cache (in milliseconds)public Set<Locale> getExistingLocales()
public void reloadExistingLocales()
This does not clear the cached translations.
public void setRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
RestTemplate to use for getting data from Weblate REST API.
Please configure the given parameter with UTF-8 as the standard message converter:
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));restTemplate - the RestTemplatepublic void useAuthentication(String authToken)
WeblateAuthenticationInterceptor for calling the REST API. Be aware: this
replaces all interceptors in the RestTemplate.authToken - Weblate API tokenpublic Map<String,Locale> getCodeToLocale()
Localespublic void setCodeToLocale(Map<String,Locale> codeToLocale)
Locales.codeToLocale - the mappingpublic void registerLocaleMapping(String code, Locale locale)
Locale.code - the Weblate language codelocale - a Locale withpublic void clearCache()
public void reload(Locale... locales)
Only if the translations from Weblate could be loaded, the translation cache will be updated
locales - the locales that should be reloadedpublic void removeEmptyCacheEntries()
This is useful e.g. when called after updating the existing locales. It ensures that newly found locales are available.
protected MessageFormat resolveCode(String code, Locale locale)
resolveCode in class org.springframework.context.support.AbstractMessageSourceprotected String resolveCodeWithoutArguments(String code, Locale locale)
resolveCodeWithoutArguments in class org.springframework.context.support.AbstractMessageSourcepublic Properties getAllProperties(Locale locale)
getAllProperties in interface AllPropertiesSourcelocale - the locale to load the propertiesCopyright © 2022 Porsche Informatik. All rights reserved.