Integration - LunarWatcher/JVMI18N GitHub Wiki
Integrating this into an existing application is fairly easy, since it only requires a single instance (two with the formatter) to get started.
After you have created the Translation
object, you can pass it as an instance to whereever you need translations. Alternatively, you can pass an instance of a core class in your project that has the Translation
object as a field.
In a lot of production cases, there's a setting to change language. Should you need to change the locale, you can simply call the setter method on the translation instance:
translation.setLocale("nb_NO");
Should you further wish to customize the library, there are three core booleans for this defined in the Translation
class:
public static String EXTENSION = ".i18n";
public static boolean CRASH_IF_NOT_FOUND = false;
public static boolean FORCE_FROM_FILE = false;
The extension says itself. CRASH_IF_NOT_FOUND
is used for crashing if the key isn't found in the active translation. If there are no translations, this is skipped.
FORCE_FROM_FILE
is the boolean used if you want to force a reload of a file every time it's called. This is false by default which enables caching. Don't spend time loading properties from a file if you can simply load a cached file. It uses the path, filename and extension as the key in the map to ensure that nothing is loaded from cache by mistake because the file name is the same but the path is different.
In addition, you can use a custom formatter for formatting strings. This is a separate instance, meaning it can also be used for separate usage, assuming the formatting syntax matches.