mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: web and tauri project (#4996)
* chore: web and tauri project fix: clippy * fix: update version
This commit is contained in:
43
frontend/appflowy_web_app/scripts/create-symlink.cjs
Normal file
43
frontend/appflowy_web_app/scripts/create-symlink.cjs
Normal file
@ -0,0 +1,43 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const sourcePath = process.argv[2];
|
||||
const targetPath = process.argv[3];
|
||||
|
||||
// ensure source and target paths are provided
|
||||
if (!sourcePath || !targetPath) {
|
||||
console.error(chalk.red('source and target paths are required'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const fullSourcePath = path.resolve(sourcePath);
|
||||
const fullTargetPath = path.resolve(targetPath);
|
||||
// ensure source path exists
|
||||
if (!fs.existsSync(fullSourcePath)) {
|
||||
console.error(chalk.red(`source path does not exist: ${fullSourcePath}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// ensure target path exists
|
||||
if (!fs.existsSync(fullTargetPath)) {
|
||||
console.error(chalk.red(`target path does not exist: ${fullTargetPath}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (fs.existsSync(fullTargetPath)) {
|
||||
// unlink existing symlink
|
||||
console.log(chalk.yellow(`unlinking existing symlink: `) + chalk.blue(`${fullTargetPath}`));
|
||||
fs.unlinkSync(fullTargetPath);
|
||||
}
|
||||
|
||||
// create symlink
|
||||
fs.symlink(fullSourcePath, fullTargetPath, 'junction', (err) => {
|
||||
if (err) {
|
||||
console.error(chalk.red(`error creating symlink: ${err.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(chalk.green(`symlink created: `) + chalk.blue(`${fullSourcePath}`) + ' -> ' + chalk.blue(`${fullTargetPath}`));
|
||||
|
||||
});
|
63
frontend/appflowy_web_app/scripts/i18n.cjs
Normal file
63
frontend/appflowy_web_app/scripts/i18n.cjs
Normal file
@ -0,0 +1,63 @@
|
||||
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',
|
||||
'sv-SE',
|
||||
'th-TH',
|
||||
'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/@types/translations');
|
||||
if (!isExistDir) {
|
||||
fs.mkdirSync('./src/@types/translations');
|
||||
}
|
||||
fs.writeFile(`./src/@types/translations/${language}.json`, new Uint8Array(Buffer.from(output)), (res) => {
|
||||
if (res) {
|
||||
console.error(res);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
function flattenJSON(obj, prefix = '') {
|
||||
let result = {};
|
||||
const pluralsKey = ["one", "other", "few", "many", "two", "zero"];
|
||||
|
||||
for (let key in obj) {
|
||||
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||
|
||||
const nestedKeys = flattenJSON(obj[key], `${prefix}${key}.`);
|
||||
result = { ...result, ...nestedKeys };
|
||||
} else {
|
||||
let newKey = `${prefix}${key}`;
|
||||
let replaceChar = '{'
|
||||
if (pluralsKey.includes(key)) {
|
||||
newKey = `${prefix.slice(0, -1)}_${key}`;
|
||||
}
|
||||
result[newKey] = obj[key].replaceAll('{', '{{').replaceAll('}', '}}');
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user