2023-07-12 03:54:50 +00:00
|
|
|
const languages = [
|
|
|
|
'ar-SA',
|
|
|
|
'ca-ES',
|
|
|
|
'de-DE',
|
|
|
|
'en',
|
|
|
|
'es-VE',
|
|
|
|
'eu-ES',
|
|
|
|
'fr-FR',
|
|
|
|
'hu-HU',
|
|
|
|
'id-ID',
|
|
|
|
'it-IT',
|
|
|
|
'ja-JP',
|
|
|
|
'ko-KR',
|
|
|
|
'pl-PL',
|
|
|
|
'pt-BR',
|
|
|
|
'pt-PT',
|
|
|
|
'ru-RU',
|
2023-11-08 06:13:17 +00:00
|
|
|
'sv-SE',
|
2023-11-23 04:40:09 +00:00
|
|
|
'th-TH',
|
2023-07-12 03:54:50 +00:00
|
|
|
'tr-TR',
|
|
|
|
'zh-CN',
|
|
|
|
'zh-TW',
|
|
|
|
];
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
languages.forEach(language => {
|
|
|
|
const json = require(`../../../resources/translations/${language}.json`);
|
|
|
|
const outputJSON = flattenJSON(json);
|
|
|
|
const output = JSON.stringify(outputJSON);
|
|
|
|
const isExistDir = fs.existsSync('./src/appflowy_app/i18n/translations');
|
|
|
|
if (!isExistDir) {
|
|
|
|
fs.mkdirSync('./src/appflowy_app/i18n/translations');
|
|
|
|
}
|
|
|
|
fs.writeFile(`./src/appflowy_app/i18n/translations/${language}.json`, new Uint8Array(Buffer.from(output)), (res) => {
|
|
|
|
if (res) {
|
|
|
|
console.error(res);
|
|
|
|
}
|
|
|
|
})
|
2023-12-04 02:33:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-07-12 03:54:50 +00:00
|
|
|
function flattenJSON(obj, prefix = '') {
|
|
|
|
let result = {};
|
2023-12-04 02:33:31 +00:00
|
|
|
const pluralsKey = ["one", "other", "few", "many", "two", "zero"];
|
2023-07-12 03:54:50 +00:00
|
|
|
|
|
|
|
for (let key in obj) {
|
|
|
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
2023-12-04 02:33:31 +00:00
|
|
|
|
2023-07-12 03:54:50 +00:00
|
|
|
const nestedKeys = flattenJSON(obj[key], `${prefix}${key}.`);
|
|
|
|
result = { ...result, ...nestedKeys };
|
|
|
|
} else {
|
2023-12-04 02:33:31 +00:00
|
|
|
let newKey = `${prefix}${key}`;
|
|
|
|
let replaceChar = '{'
|
|
|
|
if (pluralsKey.includes(key)) {
|
|
|
|
newKey = `${prefix.slice(0, -1)}_${key}`;
|
|
|
|
}
|
|
|
|
result[newKey] = obj[key].replaceAll('{', '{{').replaceAll('}', '}}');
|
2023-07-12 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|