https://github.com/rmraya/bcp47j
Java library for languages and BCP47
https://github.com/rmraya/bcp47j
bcp47 i18n java l10n
Last synced: 4 months ago
JSON representation
Java library for languages and BCP47
- Host: GitHub
- URL: https://github.com/rmraya/bcp47j
- Owner: rmraya
- License: epl-1.0
- Created: 2024-03-07T21:34:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-02-10T23:52:16.000Z (5 months ago)
- Last Synced: 2026-02-11T00:34:07.943Z (5 months ago)
- Topics: bcp47, i18n, java, l10n
- Language: Java
- Homepage:
- Size: 1.85 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# BCP47J
A library written in Java for handling Language Tags in compliance with [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt).
This library is part of [OpenXLIFF Filters](https://github.com/rmraya/OpenXLIFF)
## Usage
Use the static methods provided by class `com.maxprograms.languages.LanguageUtils`
| Method | Description |
| --- | --- |
| `List getAllLanguages()` | Returns a list of all languages from BCP47 |
| `List getCommonLanguages()` | Returns a list of most common languages |
| `Language getLanguage(String code)` | Returns a language given its code |
| `Language languageFromName(String description)` | Returns a language given its description |
| `String normalizeCode(String code)` | Normalizes a language code to the format described in BCP47 |
| `boolean isBiDi(String code)` | Returns true if the language is written right-to-left |
| `boolean isCJK(String code)` | Returns true if the language is written in CJK script |
| `String[] getLanguageNames()` | Returns an array with the names of most common languages |
### Localization
This library includes lists of languages with their names in English, Spanish and French.
Set `Locale` to `en` (default), `es` or `fr` to get the names in English, Spanish or French respectively.
```java
Locale.setDefault(Locale.forLanguageTag("es"));
String[] names = LanguageUtils.getLanguageNames();
```
Contact to localize the names to other languages.
### Example
```java
import com.maxprograms.languages.Language;
import com.maxprograms.languages.LanguageUtils;
...
boolean isValidLanguage(String code) {
return LanguageUtils.getLanguage(code) != null;
}
```
## Building
You need Java 21 and [Gradle](https://gradle.org/)
* Point your `JAVA_HOME` variable to JDK 21
* Checkout this repository
* Run `gradle` to compile the source code
``` text
git clone https://github.com/rmraya/BCP47J.git
cd BCP47J
gradle
```
## License
This software is source-available and proprietary.
You may view and modify the source code for personal, educational, or internal evaluation purposes.
Redistribution, commercial use, or distribution of modified versions is prohibited without prior written permission from Maxprograms.
See the `LICENSE.md` file for full terms.