Uploading complex Android project with CLI

If you don’t want to rely on the Localazy Gradle plugin, you can use CLI for uploading/downloading strings for your Android app.

My app is rather complex with several libraries and its structure is like this:

FloatingApps/
 - app/src/...
 - lib_vlc/src/...
 - lib_calendar/src/...
 - lib_colors/src/...
 - lib_common/src/...
 ...

I want a solution that is able to upload all my strings from all libraries as well as the app module. Also, I want it to be flexible and adaptable - e.q., I don’t want to change it when a new library is added to the project.

There are more files in some values folders such as strings_main.xml, strings_help.xml, etc. And, of course, I want to be able to decide whether to upload only the source language files - aka those in the values folder - or all existing translations (when I migrate the library with existing content).

Here comes my localazy.json where I use path to remember where to place the file inside the module and module for remembering the app/library.

{

  "writeKey": "--write-key--",
  "readKey": "--read-key--",
  
  "transformations": [
  
    {
      "name": "android_module",
      "source": "${path}",
      "operations": [
        "substringBefore: /src",
        "substringAfter: ./"
      ]
    },
    
    {
      "name": "android_folder",
      "source": "${path}",
      "operations": [
        "substringBefore: /res",
        "substringAfter: src/"
      ]
    },
    
    {
      "name": "android_lang",
      "source": "${path}",
      "operations": [
        "detectLang: android"
      ]
    }
    
  ],

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

      {
        "pattern": "*/src/*/res/values/strings*.xml",
        "path": "${android_folder}",
        "module": "${android_module}"
      },

      {
        "group": "all",
        "pattern": "*/src/*/res/values-*/strings*.xml",
        "conditions": "!equals: ${android_lang}, inherited",    
        "lang": "${android_lang}",     
        "path": "${android_folder}",
        "module": "${android_module}"
      }

    ]
  },

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

If you want to suggest improvements or have a question on how it works, feel free to ask me :wink:

1 Like