Skip to content
/ lang Public

A simple Java library to assist with writing multi-language programs

License

Notifications You must be signed in to change notification settings

ewpratten/lang

Repository files navigation

Lang

Lang is a simple Java library that can handle multiple .lang files, and switch languages at runtime. The goal is to provide a minimal interface for multi-language programs.

Installation

Step 1. Add the RetryLife maven server to your build.gradle file:

repositories {
    maven { url 'https://maven.retrylife.ca' }
}

Step 1. Add this library as a dependency:

dependencies {
    implementation 'ca.retrylife:lang:v1.+'
}

Usage

Lang expects to find .lang files in resources/lang/. These files follow the same format as .properties files. The following is an example .lang file at resources/lang/en_us.lang, and the Java code to interact with it:

test.greeting=Hello, world!
library.name=Lang
// Set en_us as the primary language
LanguageManager.getInstance().setLanguage(new Language("en_us"));

// Other languages can also be set as a fallback, where their 
// definitions will be used in the event the main language is missing something
LanguageManager.getInstance().setFallbackLanguage(new Language("sv_se"));

// Run a query
assert LanguageManager.getInstance().query("test.greeting").equals("Hello, world!")