crowdin_sync.py
================
Introduction
------------
This script is forked and modified from LineageOS and CarbonROM. It is used to synchronize AICP translations with Crowdin.
It can handle automatic commiting to Gerrit, submitting open commits on Gerrit as well as pushing/downloading to/from Crowdin.
Prerequisites
-------------
1. Python version >3.6.x is needed to execute this script (as it is necessary for building the sources anyway).
2. The package "python-lxml" is used for removing empty or faulty translations after download. So it needs to be installed on the system. (also see: https://lxml.de/)
3. The package "python-yaml" must be installed as it is used for parsing the YAML configuration files for determining which files to push.
4. The package "python-git" is used for Git integration and must be installed (also see: https://gitpython.readthedocs.io/en/stable/).
5. The install of the package "python-gitdb" with its dependencies via a package manager or via pip install gitdb for python 3.x.x.
6. A prebuilt java version of crowdin-cli >= 3.2.x or a packaged version (see: https://support.crowdin.com/cli-tool/) is required for
this script to work.
It can be downloaded and installed for different Linux distributions as described on the mentioned webpage.
*Note: The current limitation is that the script will search for an executable (alias) using the "which" command on a Linux/macOS installation.*
7. Currently the crowdin-cli tool requires either Windows10 WSL2, macOS or Linux and an appropiate Java version >= 1.8.xx to work.
8. /config/crowdin.xml must be copied to /s12.1/platform/manifest/crowdin.xml of each "AICP-version" tree.
This makes sure you will sync all the translatable and extra packages.
Please remember that you should comment out the packages you already have in your local aicp_manifest.xml file
as these are device dependent.
Executing
---------
Export the needed environment variables to set the API key and the base path to your **.zshrc**, **.bashrc** or **.bash-profile**.
The base path should contain all AICP trees in subfolders, named after AICP branches.
Needed directory structure:
home/
your_username/
aicp/
crowdin_sync.py #Python script for the crowdin-CLI tool
config/s12.1.yml #Configuration file for the translatable repositories
s12.1/
platform_manifest/crowdin.xml #Manifest file (used by the script)
Enviroment variables to export:
export AICP_CROWDIN_PROJECT_ID=aicp_project-id
export AICP_CROWDIN_API_TOKEN=your_aicp_personal-access-token #must be generated by you and will be displayed ONLY ONCE afterwards!
export AICP_CROWDIN_BASE_PATH_s12_1=your_base_path_and_branch
Example:
export AICP_CROWDIN_PROJECT_ID=123123 #Open project settings and go to API section on the project website
export AICP_CROWDIN_API_TOKEN=68f83--your-personal-token--... #Open profile settings and go to API & SSO > New Token > create Token
export AICP_CROWDIN_BASE_PATH_s12_1=/home/your_username/aicp/s12.1 #This is dependent on the real path to your source tree
Execute:
The python script "crowdin_sync.py" and the "config" directory should be copied into the base folder structure, e.g. /home/your_username/aicp, like shown above.
./crowdin_sync.py --username your_gerrit_username --branch AICP_version [--upload-sources] [--upload-translations] [--download] [--local-download] [--submit]
The script's incorporated commandline arguments that can be invoked are:
usage: crowdin_sync.py --username USERNAME --branch BRANCH [--config CONFIG] [--upload-sources] [--upload-translations] [--download] [--local-download] [--submit]
Synchronising AICP translations with Crowdin
optional arguments:
--username USERNAME Gerrit username
--branch BRANCH AICP branch
--config CONFIG Custom yml config file to use
--upload-sources Upload sources to AICP Crowdin
--upload-translations Upload AICP translations to Crowdin
--download Download AICP translations from Crowdin
--local-download Local download AICP translations from Crowdin to PC
--submit Merge open AICP translations on Gerrit
--owner Specify an owner of the commits on merging via Gerrit
Examples:
./crowdin_sync.py --username Gerrit-Username --branch s12.1 --upload-sources
Will upload specified local files from the YAML-config to Crowdin. Translations already there will be preserved.
./crowdin_sync.py --username Gerrit-Username --branch s12.1 --upload-translations
Will upload local translations to Crowdin, based on YAML-config and from your local sources.
./crowdin_sync.py --username Gerrit-Username --branch s12.1 --download
Will download translations from Crowdin of the specified branch (s12.1), based on YAML-config, to your local sources,
delete empty translations and upload updated or new translations to AICP Gerrit for review.
./crowdin_sync.py --branch s12.1 --local-download
Will download translations from Crowdin of the specified branch (s12.1), based on YAML-config, to your local sources
and delete empty translations. This is useful to perform local builds and test the imported translations.
./crowdin_sync.py --username Gerrit-Username --branch s12.1 --submit
./crowdin_sync.py --username Gerrit-Username --branch s12.1 --submit --owner "Name"
Will search for open translations commits on AICP's Gerrit on the specified branch (s12.1) and
automatically review, verify and submit them into the repositories. This is useful after successful builds and requires
Gerrit Admin rights to preform this action.
The optional "--owner" option filters the submitted files, so we can make sure that no accidental merges happen.
Notes:
------
- The script and the crowdin-cli JAR file provide some output that show off the actions performed
in the terminal, so you can follow the execution of the commands.
- The crowdin JAR file will display a message in the terminal, if it is outdated and found a
newer version available for download. This is not an error, just a reminder for you!
- When committing a translation fails, the reason of it cannot be determined everytime. The script will
simply display the message "Failed" or "Nothing to commit" or an error message mentioning the specific file/commit.
The script will continue when this happens and display "Finished! Nothing to do or commit anymore.".