Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build-scripts/gulp/download_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function hasHtml(data) {
function recursiveCheckHasHtml(file, data, errors, recKey) {
Object.keys(data).forEach(function(key) {
if (typeof data[key] === "object") {
nextRecKey = recKey ? `${recKey}.${key}` : key;
const nextRecKey = recKey ? `${recKey}.${key}` : key;
recursiveCheckHasHtml(file, data[key], errors, nextRecKey);
} else if (hasHtml(data[key])) {
errors.push(`HTML found in ${file.path} at key ${recKey}.${key}`);
Expand All @@ -23,7 +23,7 @@ function recursiveCheckHasHtml(file, data, errors, recKey) {
}

function checkHtml() {
let errors = [];
const errors = [];

return mapStream(function(file, cb) {
const content = file.contents;
Expand Down
24 changes: 13 additions & 11 deletions build-scripts/gulp/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ function recursiveFlatten(prefix, data) {
let output = {};
Object.keys(data).forEach(function(key) {
if (typeof data[key] === "object") {
output = Object.assign(
{},
output,
recursiveFlatten(prefix + key + ".", data[key])
);
output = {
...output,
...recursiveFlatten(prefix + key + ".", data[key]),
};
} else {
output[prefix + key] = data[key];
}
Expand Down Expand Up @@ -99,18 +98,16 @@ function recursiveEmpty(data) {
* @link https://docs.lokalise.co/article/KO5SZWLLsy-key-referencing
*/
const re_key_reference = /\[%key:([^%]+)%\]/;
function lokalise_transform(data, original) {
function lokaliseTransform(data, original, file) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We so much need to re-do this file in a non-stream way so we can actually see what's going on .

const output = {};
Object.entries(data).forEach(([key, value]) => {
if (value instanceof Object) {
output[key] = lokalise_transform(value, original);
output[key] = lokaliseTransform(value, original, file);
} else {
output[key] = value.replace(re_key_reference, (match, key) => {
const replace = key.split("::").reduce((tr, k) => tr[k], original);
if (typeof replace !== "string") {
throw Error(
`Invalid key placeholder ${key} in src/translations/en.json`
);
throw Error(`Invalid key placeholder ${key} in ${file.path}`);
}
return replace;
});
Expand Down Expand Up @@ -183,7 +180,7 @@ gulp.task(
.src("src/translations/en.json")
.pipe(
transform(function(data, file) {
return lokalise_transform(data, data);
return lokaliseTransform(data, data, file);
})
)
.pipe(rename("translationMaster.json"))
Expand All @@ -198,6 +195,11 @@ gulp.task(
gulp.series("build-master-translation", function() {
return gulp
.src([inDir + "/*.json", workDir + "/test.json"], { allowEmpty: true })
.pipe(
transform(function(data, file) {
return lokaliseTransform(data, data, file);
})
)
.pipe(
foreach(function(stream, file) {
// For each language generate a merged json file. It begins with the master
Expand Down
12 changes: 7 additions & 5 deletions script/translations_download
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ mkdir -p ${LOCAL_DIR}
docker run \
-v ${LOCAL_DIR}:/opt/dest/locale \
--rm \
lokalise/lokalise-cli@sha256:b8329d20280263cad04f65b843e54b9e8e6909a348a678eac959550b5ef5c75f lokalise \
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d lokalise2 \
--token ${LOKALISE_TOKEN} \
export ${PROJECT_ID} \
--export_empty skip \
--type json \
--unzip_to /opt/dest
--project-id ${PROJECT_ID} \
file download \
--export-empty-as skip \
--format json \
--original-filenames=false \
--unzip-to /opt/dest

./node_modules/.bin/gulp check-downloaded-translations
11 changes: 6 additions & 5 deletions script/translations_upload_base
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ fi

docker run \
-v ${LOCAL_FILE}:/opt/src/${LOCAL_FILE} \
lokalise/lokalise-cli@sha256:2198814ebddfda56ee041a4b427521757dd57f75415ea9693696a64c550cef21 lokalise \
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d lokalise2 \
--token ${LOKALISE_TOKEN} \
import ${PROJECT_ID} \
--project-id ${PROJECT_ID} \
file upload \
--file /opt/src/${LOCAL_FILE} \
--lang_iso ${LANG_ISO} \
--convert_placeholders 0 \
--replace 1
--lang-iso ${LANG_ISO} \
--convert-placeholders=false \
--replace-modified=true
4 changes: 2 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@
"found": "I found the following for you:",
"error": "Oops, an error has occurred",
"how_can_i_help": "How can I help?",
"label": "Type a question and press <Enter>",
"label_voice": "Type and press <Enter> or tap the microphone icon to speak"
"label": "Type a question and press 'Enter'",
"label_voice": "Type and press 'Enter' or tap the microphone to speak"
},
"confirmation": {
"cancel": "Cancel",
Expand Down
Loading