The traditional translation process is to run out of the Chinese documents in the project, send the documents to the translator, translate the documents back to the research and development, and then replace the research and development in the project. (Generally given to the translator is excel or TXT, also need to script conversion to json format);

Further, multiple translators can translate at the same time when the documents to be translated are uploaded to an online document.

Furthermore, use specialized translation collaboration platforms such as Transifex, Lokalise, and Crowdin, which generally integrate github, GitLab, and other repositories and support API access.

Because these platforms charge a lot of money (enterprise 5000 dollars/year), today I introduce the open source Weblate, based on its open source project can build their own collaboration platform.

The installation

  1. Install the docker, docker – compose

  2. Download weblate

git clone https://github.com/WeblateOrg/docker-compose.git weblate-docker
cd weblate-docker && vi docker-compose.override.yml
Copy the code
version: '3'services: weblate: ports: - 80:8080 environment: WEBLATE_EMAIL_HOST: Smtp.example.com // Email address for sending emails WEBLATE_EMAIL_HOST_USER: user // Email username WEBLATE_EMAIL_HOST_PASSWORD: *** // Email password WEBLATE_ALLOWED_HOSTS: weblate.example.com // Must be configured to access WEBLATE_ADMIN_PASSWORD using weblate.example.com: *** // Administrator password WEBLATE_SITE_DOMAIN: weblate.example.com // Site domain name WEBLATE_ADMIN_EMAIL: [email protected] // Administrator email addressCopy the code
Docker-compose up // stop docker-compose DownCopy the code

Attached is the official installation procedure

Integrated git

  1. Add SSH keys to git repository

  1. Configure the Git address in component Settings

  1. Setting a File Template

Official version control integration document

API access

If in doubt about weblate’s security,weblate also provides API access

  1. Uploading official documentation gives an example:
curl -X POST \
    -F [email protected] \
    -H "Authorization: Token TOKEN" \
    http://example.com/api/translations/hello/android/cs/file/
Copy the code

However, I tried many times and failed. For a time, I suspected there was something wrong with the configuration. Later, I found that method was missing and method: replace could be added

Here are the key steps to implement with Node

const program = require("commander");
const axios = require("axios");
const fsExtra = require("fs-extra");
const FormData = require("form-data");

// Get related parameters
program
  .option("-p, --path <path>"."Translation file path")
  .option("-o, --organization <organization>"."Organization")
  .parse(process.argv);

/ / create axiosBase
const axiosBase = axios.create({
  baseURL: "http://xxx/api/".headers: {
    "Content-Disposition": "attachment"."Content-Type": "multipart/form-data".Authorization: "Token xxx",}});// Get all files that need to be uploaded
const files = fsExtra.readdirSync(uploadPath);

/ / assembly formdata
let formData = new FormData();
formData.append("method"."replace");
formData.append("file", file);
formData.append("filename", fileName);
const headers = formData.getHeaders();

// Upload the file
await axiosBase.post(
  `translations/${organization}/${componentName}/${fileLang}/file/`,
  formData,
  { headers }
);
Copy the code
  1. After translators complete the translation on the platform, they pull the copy into the project through scripts.
// Get all the languages in the target folder that need to be downloaded
const fileList = await fsExtra.readdirSync(outputPath);

// Download files in all languages
fileList.forEach(async (file) => {
  let [fileName] = file.split(".");
  const res = await axiosBase(
    `translations/${organization}/${componentName}/${fileName}/file/`
  );
});

// Write the file locally
await fsExtra.outputFileSync(
  `${outputPath}/${fileName}.json`.JSON.stringify(res.data, null.2),
  "utf8"
);
Copy the code

If kiwi is used for internationalization, it can also be supported. The general idea is to convert the exported TXT to JSON and upload it, and then convert it to TXT after translation. The key package is D3-DSV.