Class TranslateArbExtension

java.lang.Object
de.haumacher.autotranslate.gradle.TranslateArbExtension

public class TranslateArbExtension extends Object
Extension for configuring ARB translation in Gradle build scripts.

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 Details

    • TranslateArbExtension

      public TranslateArbExtension(org.gradle.api.Project project)
  • Method Details

    • getApiKey

      public org.gradle.api.provider.Property<String> 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

      public void setApiKey(String apiKey)
      Sets the DeepL API key directly.
      Parameters:
      apiKey - The DeepL API key
    • getServerId

      public org.gradle.api.provider.Property<String> getServerId()
      Gets the server ID property for retrieving API key from gradle.properties.

      The API key will be read from the property: <serverId>.apiKey For example, if serverId is "deepl", the plugin will look for deepl.apiKey in gradle.properties.

    • setServerId

      public void setServerId(String serverId)
      Sets the server ID for retrieving API key from gradle.properties.
      Parameters:
      serverId - The server ID (defaults to "deepl")
    • getSourceFile

      public org.gradle.api.provider.Property<File> 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

      public void setSourceFile(File sourceFile)
      Sets the source ARB file.
      Parameters:
      sourceFile - The source ARB file
    • getTargetLangs

      public org.gradle.api.provider.ListProperty<String> 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

      public void setTargetLangs(Iterable<String> targetLangs)
      Sets the list of target language codes.
      Parameters:
      targetLangs - List of target language codes (e.g., ["de", "fr", "es"])
    • getLanguageMappings

      public org.gradle.api.provider.MapProperty<String,String> 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-US
      • pt → pt-PT
    • setLanguageMappings

      public void setLanguageMappings(Map<String,String> languageMappings)
      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

      public org.gradle.api.provider.Property<File> 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>.tsv using base language codes (e.g. en-de.tsv). Each line is sourceTerm<TAB>targetTerm and pins how a term is translated, so the same source word is rendered consistently across resources and runs.

    • setGlossaryDir

      public void setGlossaryDir(File glossaryDir)
      Sets the glossary directory. When unset, translation runs without glossaries.
      Parameters:
      glossaryDir - Directory with <source>-<target>.tsv glossary files