transformLocales.js 971 B

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