The framework’s own strings — messages, control captions, dialog texts — are resource-bundle based and ship in English and Icelandic; applications localize their domain the same way, with plain Java resource bundles. The active language follows the default locale, so localization is selected with Locale.setDefault() during application startup, before any UI is created.
1. Localizing the domain
Entity and attribute captions are localized by associating an EntityType with a resource bundle, by passing a class when defining it:
interface Artist {
EntityType TYPE = DOMAIN.entityType("chinook.artist", Artist.class);
...
}
The bundle is resolved from the class name — here Chinook$Artist.properties — with the entity type name as the key for the entity caption and attribute names for attribute captions:
# Chinook$Artist.properties
chinook.artist=Artists
name=Name
number_of_albums=Number of albums
Adding a language is then a matter of providing the locale-suffixed sibling — Chinook$Artist_is_IS.properties — for each entity, as the Chinook demo does for Icelandic. A caption found in the resource bundle takes precedence over one defined in code via .caption(); with neither, the attribute name serves as the caption.
2. Overriding
The default i18n strings can be overridden by implementing Resources and registering the implementation with the ServiceLoader.
package is.codion.demos.chinook.i18n;
import is.codion.common.utilities.resource.Resources;
import is.codion.framework.i18n.FrameworkMessages;
import java.util.Locale;
/**
* Replace the english modified warning text and title.
*/
public final class ChinookResources implements Resources {
private static final String FRAMEWORK_MESSAGES =
FrameworkMessages.class.getName();
private final boolean english = Locale.getDefault()
.equals(new Locale("en", "EN"));
@Override
public String getString(String baseBundleName, String key, String defaultString) {
if (english && baseBundleName.equals(FRAMEWORK_MESSAGES)) {
return switch (key) {
case "modified_warning" -> "Unsaved changes will be lost, continue?";
case "modified_warning_title" -> "Unsaved changes";
default -> defaultString;
};
}
return defaultString;
}
}
module is.codion.demos.chinook {
...
provides is.codion.common.utilities.resource.Resources
with is.codion.demos.chinook.domain.impl.ChinookResources;
}
See Chinook demo.
3. i18n Property Values
For a complete reference of all available i18n property keys and their default values, see i18n Property Values Reference.