Locale sensitive cache for named objects. An object into I18N pool is identified by an application level unique name and by
locale settings. Both single and multiple locale implementations should be supported. Locale parameter is used only for
implementations with multiple locale support; implementation should throw illegal argument exception if
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());
}