laget-se / narp

A workflow utility to ease localization in JS(X) apps
Apache License 2.0
13 stars 1 forks source link

Why Merge translations from different languages into a json file ? #9

Open YaoKaiLun opened 5 years ago

YaoKaiLun commented 5 years ago

Hi! I'm curious about the code below

/**
 * Fetches all translations available and parses them into one big
 * object with locales as keys and gettext-parser PO JSON as values.
 */
export const fetchTranslations = (options, credentials = {}) => {
  const { project } = options;

  feedback.step('Fetching available languages from POEditor...');

  return fetchLanguages({ project }, credentials)
    .then(languages => {
      feedback.step(`Fetching translations for languages: ${languages} ...`);
      return languages;
    })
    .then(languages => Promise.all(
      languages.map(language =>
        fetchTranslationsForLang({ project, language }, credentials)
      )
    ))
    .then(translations => translations.reduce((aggr, poJson) => ({
      ...aggr,
      [poJson.headers.language]: poJson,
    }), {}))
    .catch(err => feedback.kill(err));
};

I found that the translations from different locales are merged into a json file. it will generate a huge file if i have many languages. It also makes coding splitting difficult. So, could you tell me Why you do this?

YaoKaiLun commented 5 years ago

I think this is better for the websites which change language and refresh at the same time.