Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ewpratten/lang
A simple Java library to assist with writing multi-language programs
https://github.com/ewpratten/lang
java lang-files languages locale translation utility
Last synced: 8 days ago
JSON representation
A simple Java library to assist with writing multi-language programs
- Host: GitHub
- URL: https://github.com/ewpratten/lang
- Owner: ewpratten
- License: gpl-3.0
- Created: 2020-11-18T22:07:03.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-25T13:59:36.000Z (almost 4 years ago)
- Last Synced: 2024-10-08T18:41:37.542Z (30 days ago)
- Topics: java, lang-files, languages, locale, translation, utility
- Language: Java
- Homepage: https://ewpratten.retrylife.ca/lang/
- Size: 369 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```groovy
repositories {
maven { url 'https://maven.retrylife.ca' }
}
```**Step 1.** Add this library as a dependency:
```groovy
dependencies {
implementation 'ca.retrylife:lang:v1.+'
}
```## Usage
Lang expects to find `.lang` files in `resources/lang/`. These files follow the same format as [`.properties`](https://en.wikipedia.org/wiki/.properties) files. The following is an example `.lang` file at `resources/lang/en_us.lang`, and the Java code to interact with it:
```properties
test.greeting=Hello, world!
library.name=Lang
``````java
// 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!")```