Include backend translations in Lokalise download (#13981)
parent
1442f6d546
commit
8444fe0a07
|
@ -1,17 +1,12 @@
|
||||||
const del = require("del");
|
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const mapStream = require("map-stream");
|
const mapStream = require("map-stream");
|
||||||
|
|
||||||
const inDirFrontend = "translations/frontend";
|
const inDirFrontend = "translations/frontend";
|
||||||
const inDirBackend = "translations/backend";
|
const inDirBackend = "translations/backend";
|
||||||
const downloadDir = "translations/downloads";
|
|
||||||
const srcMeta = "src/translations/translationMetadata.json";
|
const srcMeta = "src/translations/translationMetadata.json";
|
||||||
|
|
||||||
const encoding = "utf8";
|
const encoding = "utf8";
|
||||||
|
|
||||||
const tasks = [];
|
|
||||||
|
|
||||||
function hasHtml(data) {
|
function hasHtml(data) {
|
||||||
return /<[a-z][\s\S]*>/i.test(data);
|
return /<[a-z][\s\S]*>/i.test(data);
|
||||||
}
|
}
|
||||||
|
@ -46,20 +41,12 @@ function checkHtml() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let taskName = "clean-downloaded-translations";
|
// Backend translations do not currently pass HTML check so are excluded here for now
|
||||||
gulp.task(taskName, function () {
|
gulp.task("check-translations-html", function () {
|
||||||
return del([`${downloadDir}/**`]);
|
return gulp.src([`${inDirFrontend}/*.json`]).pipe(checkHtml());
|
||||||
});
|
});
|
||||||
tasks.push(taskName);
|
|
||||||
|
|
||||||
taskName = "check-translations-html";
|
gulp.task("check-all-files-exist", function () {
|
||||||
gulp.task(taskName, function () {
|
|
||||||
return gulp.src(`${downloadDir}/*.json`).pipe(checkHtml());
|
|
||||||
});
|
|
||||||
tasks.push(taskName);
|
|
||||||
|
|
||||||
taskName = "check-all-files-exist";
|
|
||||||
gulp.task(taskName, function () {
|
|
||||||
const file = fs.readFileSync(srcMeta, { encoding });
|
const file = fs.readFileSync(srcMeta, { encoding });
|
||||||
const meta = JSON.parse(file);
|
const meta = JSON.parse(file);
|
||||||
Object.keys(meta).forEach((lang) => {
|
Object.keys(meta).forEach((lang) => {
|
||||||
|
@ -72,24 +59,8 @@ gulp.task(taskName, function () {
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
tasks.push(taskName);
|
|
||||||
|
|
||||||
taskName = "move-downloaded-translations";
|
|
||||||
gulp.task(taskName, function () {
|
|
||||||
return gulp.src(`${downloadDir}/*.json`).pipe(gulp.dest(inDirFrontend));
|
|
||||||
});
|
|
||||||
tasks.push(taskName);
|
|
||||||
|
|
||||||
taskName = "check-downloaded-translations";
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
taskName,
|
"check-downloaded-translations",
|
||||||
gulp.series(
|
gulp.series("check-translations-html", "check-all-files-exist")
|
||||||
"check-translations-html",
|
|
||||||
"move-downloaded-translations",
|
|
||||||
"check-all-files-exist",
|
|
||||||
"clean-downloaded-translations"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
tasks.push(taskName);
|
|
||||||
|
|
||||||
module.exports = tasks;
|
|
||||||
|
|
|
@ -20,24 +20,28 @@ fi
|
||||||
# Load token from file if not already in the environment
|
# Load token from file if not already in the environment
|
||||||
[ -z "${LOKALISE_TOKEN-}" ] && LOKALISE_TOKEN="$(<.lokalise_token)"
|
[ -z "${LOKALISE_TOKEN-}" ] && LOKALISE_TOKEN="$(<.lokalise_token)"
|
||||||
|
|
||||||
PROJECT_ID="3420425759f6d6d241f598.13594006"
|
declare -A PROJECT_ID=( \
|
||||||
LOCAL_DIR="$(pwd)/translations/downloads"
|
[frontend]="3420425759f6d6d241f598.13594006" \
|
||||||
FILE_FORMAT=json
|
[backend]="130246255a974bd3b5e8a1.51616605" \
|
||||||
|
)
|
||||||
|
|
||||||
mkdir -p ${LOCAL_DIR}
|
for project in ${!PROJECT_ID[*]}; do
|
||||||
|
LOCAL_DIR=`pwd`/translations/${project}
|
||||||
docker run \
|
rm -f ${LOCAL_DIR}/* || mkdir -p ${LOCAL_DIR}
|
||||||
-v ${LOCAL_DIR}:/opt/dest/locale \
|
docker run \
|
||||||
--rm \
|
-v ${LOCAL_DIR}:/opt/dest/locale \
|
||||||
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d lokalise2 \
|
--rm \
|
||||||
--token ${LOKALISE_TOKEN} \
|
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d \
|
||||||
--project-id ${PROJECT_ID} \
|
lokalise2 \
|
||||||
file download \
|
--token ${LOKALISE_TOKEN} \
|
||||||
--export-empty-as skip \
|
--project-id ${PROJECT_ID[${project}]} \
|
||||||
--format json \
|
file download \
|
||||||
--json-unescaped-slashes=true \
|
--export-empty-as skip \
|
||||||
--replace-breaks=false \
|
--format json \
|
||||||
--original-filenames=false \
|
--json-unescaped-slashes=true \
|
||||||
--unzip-to /opt/dest
|
--replace-breaks=false \
|
||||||
|
--original-filenames=false \
|
||||||
|
--unzip-to /opt/dest
|
||||||
|
done
|
||||||
|
|
||||||
./node_modules/.bin/gulp check-downloaded-translations
|
./node_modules/.bin/gulp check-downloaded-translations
|
Loading…
Reference in New Issue