Class TranslateArbExtension
This extension allows users to configure the ARB translation plugin using a declarative DSL in their build.gradle file.
Example configuration:
translateArb {
apiKey = System.getenv('DEEPL_API_KEY')
sourceFile = file('lib/l10n/app_en.arb')
targetLangs = ['de', 'fr', 'es']
}
Alternative using serverId (recommended for security):
// In gradle.properties or ~/.gradle/gradle.properties:
// deepl.apiKey=YOUR_DEEPL_API_KEY
translateArb {
serverId = 'deepl' // defaults to 'deepl'
sourceFile = file('lib/l10n/app_en.arb')
targetLangs = ['de', 'fr', 'es']
}
Custom language mappings for DeepL API compatibility:
translateArb {
serverId = 'deepl'
sourceFile = file('lib/l10n/app_en.arb')
targetLangs = ['de', 'fr', 'en']
languageMappings = [
'en': 'en-GB', // Override default en-US with British English
'pt': 'pt-BR' // Override default pt-PT with Brazilian Portuguese
]
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.gradle.api.provider.Property<String> Gets the DeepL API key property.org.gradle.api.provider.Property<File> Gets the optional glossary directory property.Gets the language mappings for DeepL API compatibility.org.gradle.api.provider.Property<String> Gets the server ID property for retrieving API key from gradle.properties.org.gradle.api.provider.Property<File> Gets the source ARB file property.org.gradle.api.provider.ListProperty<String> Gets the list of target language codes.voidSets the DeepL API key directly.voidsetGlossaryDir(File glossaryDir) Sets the glossary directory.voidsetLanguageMappings(Map<String, String> languageMappings) Sets custom language mappings for DeepL API compatibility.voidsetServerId(String serverId) Sets the server ID for retrieving API key from gradle.properties.voidsetSourceFile(File sourceFile) Sets the source ARB file.voidsetTargetLangs(Iterable<String> targetLangs) Sets the list of target language codes.
-
Constructor Details
-
TranslateArbExtension
public TranslateArbExtension(org.gradle.api.Project project)
-
-
Method Details
-
getApiKey
Gets the DeepL API key property.If set, this API key will be used directly for authentication. If not set, the plugin will attempt to retrieve the API key from gradle.properties using the serverId.
-
setApiKey
Sets the DeepL API key directly.- Parameters:
apiKey- The DeepL API key
-
getServerId
Gets the server ID property for retrieving API key from gradle.properties.The API key will be read from the property:
<serverId>.apiKeyFor example, if serverId is "deepl", the plugin will look fordeepl.apiKeyin gradle.properties. -
setServerId
Sets the server ID for retrieving API key from gradle.properties.- Parameters:
serverId- The server ID (defaults to "deepl")
-
getSourceFile
Gets the source ARB file property.The source file must follow the naming convention:
basename_lang.arb(e.g.,app_en.arb,messages_de.arb). -
setSourceFile
Sets the source ARB file.- Parameters:
sourceFile- The source ARB file
-
getTargetLangs
Gets the list of target language codes.Target files will be created in the same directory as the source file with the appropriate language suffix.
-
setTargetLangs
Sets the list of target language codes.- Parameters:
targetLangs- List of target language codes (e.g., ["de", "fr", "es"])
-
getLanguageMappings
Gets the language mappings for DeepL API compatibility.Language mappings allow you to specify how generic language codes should be mapped to DeepL-specific variants. For example, "en" can be mapped to "en-US" or "en-GB".
Default mappings:
en→en-USpt→pt-PT
-
setLanguageMappings
Sets custom language mappings for DeepL API compatibility.These mappings override the defaults. For example, to use British English or Brazilian Portuguese:
languageMappings = ['en': 'en-GB', 'pt': 'pt-BR']
- Parameters:
languageMappings- Map from user language codes to DeepL API language codes
-
getGlossaryDir
Gets the optional glossary directory property.The directory is expected to contain one tab-separated file per source/target language pair, named
<source>-<target>.tsvusing base language codes (e.g.en-de.tsv). Each line issourceTerm<TAB>targetTermand pins how a term is translated, so the same source word is rendered consistently across resources and runs. -
setGlossaryDir
Sets the glossary directory. When unset, translation runs without glossaries.- Parameters:
glossaryDir- Directory with<source>-<target>.tsvglossary files
-