A powerful and easy-to-use Java SDK for the Localine Translation Management API
Features β’ Installation β’ Quick Start β’ Documentation β’ Examples
- Features
- Installation
- Quick Start
- Core Concepts
- API Reference
- Advanced Usage
- Error Handling
- Contributing
- License
- π Simple & Intuitive API - Fluent builder pattern for easy configuration
- π Type-Safe - Full Java type safety with compile-time checks
- π¦ Complete Coverage - 100% API endpoint coverage for all services
- π·οΈ Term Management - Create, update, delete, lock/unlock terms
- π Translation Management - Manage translations across multiple locales
- π¨ Label System - Organize terms with customizable labels
- π₯ Import/Export - Support for multiple formats (JSON, CSV, etc.)
- β‘ Async Ready - Built on OkHttp for efficient HTTP operations
- π‘οΈ Error Handling - Comprehensive exception handling with detailed messages
Add the GitHub Packages repository to your pom.xml:
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/LocalineServices/sdk-java</url>
</repository>
</repositories>Then add the dependency:
<dependency>
<groupId>net.localine.sdk</groupId>
<artifactId>localine-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>repositories {
maven {
url = uri("https://maven.pkg.github.com/LocalineServices/sdk-java")
}
}
dependencies {
implementation 'net.localine.sdk:localine-sdk:1.0-SNAPSHOT'
}import net.localine.sdk.LocalineClient;
import net.localine.sdk.model.Term;
import net.localine.sdk.model.Translation;
public class Example {
public static void main(String[] args) {
// Initialize the client
LocalineClient client = LocalineClient.builder()
.baseUrl("https://api.yourdomain.net")
.apiKey("your-api-key")
.projectId("your-project-id")
.build();
try {
// Create a new term
Term term = client.terms().create(
"welcome.message",
"Welcome message on the home page"
);
// Add translations
client.translations().update(
term.getId(),
"en",
"Welcome to our app!"
);
client.translations().update(
term.getId(),
"de",
"Willkommen in unserer App!"
);
// Fetch all terms
List<Term> terms = client.terms().getAll();
terms.forEach(System.out::println);
} catch (LocalineException exception) {
System.err.println("Error: " + exception.getMessage());
} finally {
client.close();
}
}
}The LocalineClient is the main entry point. Use the builder pattern to configure it:
LocalineClient client = LocalineClient.builder()
.baseUrl("https://api.yourdomain.net") // API base URL
.apiKey("tk_...") // Your API key
.projectId("project-uuid") // Target project ID
.timeout(60) // Request timeout in seconds (default: 30)
.build();The SDK provides six main services:
| Service | Purpose | Access Method |
|---|---|---|
| TermService | Manage translation terms | client.terms() |
| TranslationService | Manage translations | client.translations() |
| LabelService | Manage labels | client.labels() |
| LanguageService | Manage locales | client.languages() |
| ExportService | Export translations | client.export() |
| ImportService | Import translations | client.importData() |
Manage translation keys and their metadata.
List<Term> terms = client.terms().getAll();Term term = client.terms().get("term-id");Term term = client.terms().create(
"app.button.save", // Key
"Save button label" // Description (optional)
);Term updated = client.terms().update(
"term-id",
"app.button.submit", // New key (optional)
"Submit button label" // New description (optional)
);client.terms().delete("term-id");List<Term> results = client.terms().search("button");// Lock a single term
Term locked = client.terms().setLocked("term-id", true);
// Unlock a single term
Term unlocked = client.terms().setLocked("term-id", false);
// Lock all terms in project
BulkOperationResponse response = client.terms().lockAll();
System.out.println("Locked " + response.getCount() + " terms");
// Unlock all terms
response = client.terms().unlockAll();List<String> labelIds = Arrays.asList("label-id-1", "label-id-2");
Term term = client.terms().setLabels("term-id", labelIds);Manage translation values for different locales.
Map<String, String> translations = client.translations().getByLocale("en");
// Returns: {"welcome.message": "Welcome!", "app.title": "My App", ...}Map<String, Map<String, String>> allTranslations = client.translations().getAll();
// Returns: {"en": {...}, "de": {...}, "fr": {...}}String value = client.translations().get("term-key", "en");Translation translation = client.translations().update(
"term-id",
"en",
"Updated translation value"
);Translation translation = client.translations().save(
"term-id",
"en",
"New translation value"
);client.translations().delete("term-id", "en");Map<String, String> translations = client.translations()
.getByLocale()
.locale("en")
.execute();Organize and categorize terms with labels.
List<Label> labels = client.labels().getAll();Label label = client.labels().get("label-id");Label label = client.labels().create(
"Feature Request", // Name
"#FF5733" // Color (hex code)
);Label updated = client.labels().update(
"label-id",
"Bug Fix", // New name (optional)
"#33FF57" // New color (optional)
);client.labels().delete("label-id");Manage project locales.
List<Language> languages = client.languages().getAll();Language language = client.languages().get("en");boolean supported = client.languages().isSupported("de");Locale locale = client.languages().createLocale("es", "Spanish");Export and import translations in various formats.
// Export single locale as JSON
String json = client.export().exportJson("en");
// Export multiple locales
List<String> locales = Arrays.asList("en", "de", "fr");
String export = client.export().exportAllJson(locales);
// Export with custom format
String csv = client.export().exportLocale("en", ExportFormat.CSV);
// Using builder for more control
String export = client.export().builder()
.locale("en")
.locale("de")
.format(ExportFormat.JSON_NESTED)
.includeEmpty(true)
.execute();// Import from file
ImportResponse response = client.importData().importFile(
Paths.get("/path/to/translations.json")
);
// Import from byte array
byte[] data = Files.readAllBytes(Paths.get("/path/to/file"));
ImportResponse response = client.importData().importData(
data,
"translations.json"
);
System.out.println("Imported: " + response.getImported() + " translations");LocalineClient client = LocalineClient.builder()
.baseUrl("http://localhost:3000") // For local development
.apiKey("your-api-key")
.projectId("your-project-id")
.build();LocalineClient client = LocalineClient.builder()
.baseUrl("https://api.localine.net")
.apiKey("your-api-key")
.projectId("your-project-id")
.timeout(60) // 60 seconds
.build();// Lock all terms before a release
BulkOperationResponse lockResponse = client.terms().lockAll();
System.out.println("Locked " + lockResponse.getCount() + " terms");
// Export all locales
List<String> allLocales = client.languages().getAll()
.stream()
.map(Language::getCode)
.collect(Collectors.toList());
String export = client.export().exportAllJson(allLocales);// Create labels for organization
Label bugLabel = client.labels().create("Bug", "#FF0000");
Label featureLabel = client.labels().create("Feature", "#00FF00");
// Tag terms with labels
List<String> labelIds = Arrays.asList(featureLabel.getId());
client.terms().setLabels("term-id", labelIds);
// Get all labels and filter
List<Label> labels = client.labels().getAll();
List<Label> redLabels = labels.stream()
.filter(l -> l.getColor().equals("#FF0000"))
.collect(Collectors.toList());All SDK methods throw LocalineException for API errors:
try {
Term term = client.terms().get("invalid-id");
} catch (LocalineException e) {
System.err.println("Error: " + e.getMessage());
// Handle error appropriately
}Common error scenarios:
- Authentication errors - Invalid API key
- Not found errors - Resource doesn't exist
- Permission errors - Insufficient permissions (e.g., editors trying to lock terms)
- Validation errors - Invalid input data
- Network errors - Connection issues
-
Always close the client when done to release resources:
try (LocalineClient client = /* ... */) { // Use client } // Auto-closes
-
Cache the client instance - Don't create a new client for every operation
-
Use meaningful term keys - Follow a consistent naming convention:
client.terms().create("app.screen.home.title", "Home screen title"); client.terms().create("app.button.submit", "Submit button");
-
Lock terms before releases to prevent accidental changes:
client.terms().lockAll();
-
Use labels to organize terms by feature, screen, or status
- Java 21+
- Maven 3.6+ or Gradle 7+
The SDK uses the following libraries:
- OkHttp 4.12.0 - HTTP client
- Gson 2.13.2 - JSON serialization
- Lombok 1.18.42 - Boilerplate reduction
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Documentation: API Documentation
- Issues: GitHub Issues
- Email: private.httxmxritz@gmail.com
- Discord: itzmxritz