index.cjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const languages = [
  2. 'ar-SA',
  3. 'ca-ES',
  4. 'de-DE',
  5. 'en',
  6. 'es-VE',
  7. 'eu-ES',
  8. 'fr-FR',
  9. 'hu-HU',
  10. 'id-ID',
  11. 'it-IT',
  12. 'ja-JP',
  13. 'ko-KR',
  14. 'pl-PL',
  15. 'pt-BR',
  16. 'pt-PT',
  17. 'ru-RU',
  18. 'sv',
  19. 'tr-TR',
  20. 'zh-CN',
  21. 'zh-TW',
  22. ];
  23. const fs = require('fs');
  24. languages.forEach(language => {
  25. const json = require(`../../../resources/translations/${language}.json`);
  26. const outputJSON = flattenJSON(json);
  27. const output = JSON.stringify(outputJSON);
  28. const isExistDir = fs.existsSync('./src/appflowy_app/i18n/translations');
  29. if (!isExistDir) {
  30. fs.mkdirSync('./src/appflowy_app/i18n/translations');
  31. }
  32. fs.writeFile(`./src/appflowy_app/i18n/translations/${language}.json`, new Uint8Array(Buffer.from(output)), (res) => {
  33. if (res) {
  34. console.error(res);
  35. }
  36. })
  37. })
  38. function flattenJSON(obj, prefix = '') {
  39. let result = {};
  40. for (let key in obj) {
  41. if (typeof obj[key] === 'object' && obj[key] !== null) {
  42. const nestedKeys = flattenJSON(obj[key], `${prefix}${key}.`);
  43. result = { ...result, ...nestedKeys };
  44. } else {
  45. result[`${prefix}${key}`] = obj[key];
  46. }
  47. }
  48. return result;
  49. }