T
- type of objects stored by this cache.public interface I18nPool<T>
locale
argument is missing. For single locale implementations locale
argument is silently ignored.
Used locale should be based only on language and optional country, encoded with ISO 639 alpha-2, respective ISO 3166 alpha-2.
Implementation should throw illegal argument exception if provided locale has script, variant or extension. Also, for string
representation, implementations should use Locale.toLanguageTag()
that guarantee usage of newly language codes. This
is because, accordingly Java Locale
API, language encoded ISO 639 alpha-2 is not a stable standard and has some codes
changed.
To facilitate loading I18N cache from files system there is companion I18nRepository
class. In code snippet below,
iterate files from repository and update pool. Note that I18N file has locale detected by repository iterator while scanning
the files system. For single locale repository detected locale is null but is ignored anyway by I18N pool, that is created
also a single locale instance.
// create single or multiple locale I18N pool accordingly repository support I18nPool pool = repository.getPoolInstance(); for (I18nFile i18nFile : repository) { // create object instance and initialize it from file content File file = i18nFile.getFile(); Template template = new Template(file); // store created object instance on cache, bound to file name and detected locale pool.put(file.getName(), template, i18nFile.getLocale()); }
Modifier and Type | Method and Description |
---|---|
T |
get(String name,
Locale... locale)
Get instance identified by name and optional locale settings.
|
boolean |
has(String name,
Locale... locale)
Test if cache has an instance identified by given name and optional locale settings.
|
boolean |
put(String name,
T t,
Locale... locale)
Store an instance on this cache bound to given name and optional locale settings.
|
boolean put(String name, T t, Locale... locale)
locale
argument is silently ignored and not even tested for validity.name
- unique name with application scope,t
- object instance to store on cache,locale
- optional locale settings, mandatory for implementations with multiple locale support.IllegalArgumentException
- if name
argument is null or empty or locale
argument is
missing, null or has variant, script or extension, on an implementation with multiple locale support.T get(String name, Locale... locale)
locale
argument is silently ignored and not
even tested for validity.name
- unique name with application scope,locale
- optional locale settings, mandatory for implementations with multiple locale support.IllegalArgumentException
- if name
argument is null or empty or locale
argument is
missing, null or has variant, script or extension, on an implementation with multiple locale support.boolean has(String name, Locale... locale)
locale
argument is silently ignored and not even tested for validity.name
- unique name with application scope,locale
- optional locale settings, mandatory for implementations with multiple locale support.IllegalArgumentException
- if name
argument is null or empty or locale
argument is
missing, null or has variant, script or extension, on an implementation with multiple locale support.Copyright © 2018. All rights reserved.