transformLocales.js 930 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require('fs')
  2. const LANGUAGES = [
  3. 'cs',
  4. 'da',
  5. 'de',
  6. 'en',
  7. 'es',
  8. 'fi',
  9. 'fr',
  10. 'it',
  11. 'ja',
  12. 'ko',
  13. 'nl',
  14. 'no',
  15. 'pl',
  16. 'pt',
  17. 'ru',
  18. 'sv',
  19. 'tr',
  20. 'zh-CN'
  21. ]
  22. const LOCALES = {}
  23. LANGUAGES.forEach(loadLocales)
  24. function loadLocales(language) {
  25. LOCALES[language] = require(`../../locales/${language}.json`)
  26. }
  27. function transformLocales(mapping, transformLocale) {
  28. Object.entries(LOCALES).forEach(([language, translatedLocales]) => {
  29. Object.entries(mapping).forEach(([localeKey, spec]) => {
  30. const locale = translatedLocales[localeKey]
  31. if (!locale) {
  32. // This locale is not translated yet.
  33. return
  34. }
  35. translatedLocales[localeKey] = transformLocale(locale, spec)
  36. })
  37. fs.writeFileSync(
  38. `${__dirname}/../../locales/${language}.json`,
  39. JSON.stringify(translatedLocales, null, 2) + '\n'
  40. )
  41. })
  42. }
  43. module.exports = {
  44. transformLocales
  45. }