File Format - Android XML

Learn how to use Localazy CLI for localization of your Android app.

Android XML format is fully supported including array-lists and plurals. No extra configuration is necessary.

For Android app localization, we recommend using the Localazy Gradle plugin that automatically handles uploads, downloads and adds code for OTA (over-the-air) updates.

The basic usage

Uploading the source language is easy and with a number of variables for the download part, including preformatted Android language ${langAndroidRes}, it’s also simple to store translated files to their correct destination.

{

  "writeKey": "your-apps-write-key", 
  "readKey": "your-apps-read-key",

  "upload": {
    "type": "android",   
    "files": "src/main/res/values/strings.xml"
  },

  "download": {
    "files": "src/main/res/values-${langAndroidRes}/${file}"
  }

}

Upload existing translations

For Android projects, you can rely on the auto-detection of the language from path/file.

{

  "writeKey": "your-apps-write-key", 
  "readKey": "your-apps-read-key",

  "upload": {
    "type": "android",
        
    "files": [

      // For repeated upload of the source language.
      // Path is not necessary, so we remove it.  
      {
        "pattern": "src/main/res/values/strings*.xml"
      },

      // For initial upload of all existing translations.
      // Run: `localazy upload all` to upload all translations.  
      {
        "group": "all",
        "pattern": "src/main/res/values-*/strings*.xml",
        "lang": "${autodetectLang}"
      }

    ]
  },

  // Place downloaded translations to the correct folder.
  "download": {
    "files": "src/main/res/values-${langAndroidRes}/${file}"
  }

}

Product flavors & build type

Localazy comes with full support for product flavors and build types. There are transformations androidBuildType and androidProductFlavors for detecting those from the standard project structure.

Also, with the preformatted variable ${androidFlavoredFolder}, it’s easy to place downloaded translations to the correct folders.

{

  "writeKey": "your-apps-write-key", 
  "readKey": "your-apps-read-key",
  
  // Use transformations to get product flavors and the build type from path.
  "transformations": [
    {
      "name": "product_flavors",
      "source": "${path}",
      "operations": [
        "androidProductFlavors: gp am, free full auto"
      ]
    },
    {
      "name": "build_type",
      "source": "${path}",
      "operations": [
        "androidBuildType: debug, release"
      ]
    }
  ],

  "upload": {
  
    "type": "android",
    
    "files": [
    
      // For repeated upload of the source language from all flavors and product types.
      // Path is not necessary, so we remove it. We can rebuild path from other variables.  
      {
        "pattern": "src/*/res/values/strings*.xml",
        "productFlavors": "${product_flavors}",
        "buildType": "${build_type}"
      },
      
      // For initial upload of all existing translations.
      // Run: `localazy upload all` to upload all translations. 
      {
        "group": "all",
        "pattern": "src/*/res/values-*/strings*.xml",
        "lang": "${autodetectLang}",
        "productFlavors": "${product_flavors}",
        "buildType": "${build_type}"
      }
      
    ]
  },

  // Place downloaded translations to the correct folder.
  "download": {
    "files": "src/${androidFlavoredFolder}/res/values-${langAndroidRes}/${file}"
  }

}

Strings uploaded with the Gradle plugin

The Gradle plugin uploads data in a very similar way as described above and so it’s possible to download translations using:

{

  // ... other parts omitted for brevity ...
  
  "download": {
    "files": "src/${androidFlavoredFolder}/res/values-${langAndroidRes}/${file}"
  }

}

Running with Gradle

We recommend using the Localazy Gradle plugin that automatically handles uploads, downloads and adds code for OTA (over-the-air) updates.

However, you can run the CLI tool directly from your Gradle build script. Just place the CLI binary to the app’s module folder along with the configuration file localazy.json and create task:

// Create task for running Localazy CLI. 
task downloadTranslations(type: Exec) {
    executable "./localazy"
    args "download", "-q"
} 

// Run the Localazy CLI task only for release versions. 
android.applicationVariants.all { variant ->
    if (!variant.buildType.debuggable) {
        variant.preBuildProvider.get().dependsOn(downloadTranslations)
    }
}