public class AvailableLocaleResolver extends java.lang.Object
Discovers the locales an application is actually translated into by scanning the
classpath for <basename>_<locale>.properties resource bundles.
Unlike java.util.Locale#getAvailableLocales() (which returns every locale the JVM knows about), this returns only the locales that have a matching message bundle plus the configured default locale, making it suitable for driving a language selector. The result is sorted by each locale's display name in its own language and cached; clearCache() forces a re-scan (used when bundles change in development).
By default only the application's own messages_*.properties bundles are
scanned. When includePluginBundles is enabled, every *.properties
bundle on the classpath is considered, so locales contributed by plugins — whose
bundles are namespaced (e.g. spring-security-core_fr.properties) — are
included too. Candidate suffixes are validated against the ISO language codes (and the ISO
country codes when a country is present), so non-i18n properties files (e.g.
application.properties or foo_en_prod.properties) are ignored. See
grails.i18n.availableLocales.includePlugins.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
DEFAULT_BASE_NAME |
The base name of an application's own message bundles (messages.properties). |
| Constructor and description |
|---|
AvailableLocaleResolver(java.lang.ClassLoader classLoader, java.util.Locale defaultLocale)Scans only the application's own messages_*.properties bundles. |
AvailableLocaleResolver(java.lang.ClassLoader classLoader, java.util.Locale defaultLocale, boolean includePluginBundles)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
clearCache()Discards the cached list so the next getAvailableLocales() re-scans the classpath. |
|
public java.util.List<java.util.Locale> |
getAvailableLocales()
|
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
The base name of an application's own message bundles (messages.properties).
Scans only the application's own messages_*.properties bundles.
classLoader - the class loader whose classpath is scanned for message bundlesdefaultLocale - the locale of the base messages.properties bundle,
always included in the result (may be null to include none)
classLoader - the class loader whose classpath is scanned for message bundlesdefaultLocale - the locale of the base bundle, always included (may be null)includePluginBundles - whether to also consider plugin-contributed bundles (every
*.properties on the classpath) rather than only the application's messagesDiscards the cached list so the next getAvailableLocales() re-scans the classpath.