Skip to content
Snippets Groups Projects
Commit 00ec1bf6 authored by Tom Robinson's avatar Tom Robinson
Browse files

Add POEditor scripts, remove unused update-translation(s) scripts

parent be40b6dc
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
set -eu
POEDITOR_PROJECT_ID="200535"
echo "Uploading metabase.pot to POEditor..."
curl -X POST https://api.poeditor.com/v2/projects/upload \
-F api_token="${POEDITOR_API_TOKEN}" \
-F id="${POEDITOR_PROJECT_ID}" \
-F updating="terms" \
-F file=@"locales/metabase.pot"
#!/usr/bin/env node
// USAGE:
//
// POEDITOR_API_TOKEN=TOKEN ./bin/i18n/import-po-from-poeditor [LANG...]
//
// If no arguments are provided it updates existing locales in ./locales
const fs = require("fs");
const fsp = fs.promises;
const https = require("https");
const fetch = require("isomorphic-fetch");
const url = require("url");
const POEDITOR_API_TOKEN = process.env["POEDITOR_API_TOKEN"];
const POEDITOR_PROJECT_ID = "200535"; // Metabae POEditor project
// currently we don't support variants of language
const aliases = {
"pt-br": "pt",
"zh-CN": "zh",
};
async function main(args) {
const wanted = new Set(args.length > 0 ? args : await getExistingLanguages());
const other = [];
// list available languages
const { result: { languages } } = await poeditor("languages/list");
for (const language of languages) {
const code = aliases[language.code] || language.code;
if (wanted.has(code)) {
wanted.delete(code);
console.log(`Downloading: ${code} (${language.percentage}%)`);
// start an export
const { result: { url } } = await poeditor("projects/export", {
language: language.code,
type: "po",
});
// download the exported file
https.get(url, res =>
res.pipe(fs.createWriteStream(`./locales/${code}.po`)),
);
} else {
other.push(language);
}
}
// log others with large percentage complete
for (const language of other
.filter(l => l.percentage > 50)
.sort((a, b) => b.percentage - a.percentage)) {
console.log(`Other: ${language.code} (${language.percentage}%)`);
}
// log languages that are wanted but missing in POEditor
for (const code of wanted) {
console.log(`Missing: ${code}`);
}
if (wanted.size > 0) {
throw new Error("Some wanted language not found");
}
}
// simple API client for poeditor
function poeditor(command, params = {}) {
const uri = url.format({
protocol: "https",
hostname: "api.poeditor.com",
pathname: `/v2/${command}`,
});
const query = {
api_token: POEDITOR_API_TOKEN,
id: POEDITOR_PROJECT_ID,
...params,
};
return fetch(uri, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: url.format({ query }).replace(/^\?/, ""),
}).then(res => res.json());
}
async function getExistingLanguages() {
return (await fsp.readdir("./locales"))
.filter(f => /\.po$/.test(f))
.map(f => f.replace(/\.po$/, ""));
}
main(process.argv.slice(2)).then(null, console.warn);
#!/bin/sh
set -eu
# gettext installed via homebrew is "keg-only", add it to the PATH
if [ -d "/usr/local/opt/gettext/bin" ]; then
export PATH="/usr/local/opt/gettext/bin:$PATH"
fi
POT_NAME="locales/metabase.pot"
PO_NAME="locales/$1.po"
if [ $# -lt 1 ]; then
echo "USAGE: update-translation en_US"
exit 1
fi
if [ -f "$PO_NAME" ]; then
exec msgmerge -U "$PO_NAME" "$POT_NAME"
else
exec msginit -i "$POT_NAME" -o "$PO_NAME" -l "$1"
fi
#!/bin/sh
set -eu
./bin/i18n/update-translation-template
find locales -name "*.po" -exec sh -c './bin/i18n/update-translation $(basename {} .po)' \;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment