Slow build time due to tap:i18n json files

Hello,
We have 3 json files for our translations fr.i18n.json, de.i18n.json and en.i18n.json.
Each file is 4500 lines approx.
We use tap:18n

The build time on the development machine is long : 60 seconds

Is there a way to accelerate this at least during the development ?
Thanks

It seems that loading json files as assets is way faster.
This is my code :

Meteor.startup(function() {
  TAPi18n.conf.supported_languages = null; // null means all that are found in the directory root/lib/i18n
 // Dynamically load translations (do not use the file in /lib/i18n as it makes the build slower)
 // Do not forget to addAsset in package.js for new language
  Meteor.defer(function() {
    Object.keys(TAPi18n.getLanguages()).forEach(function(locale) {
      if (Meteor.isServer) {
        const fs = require('fs');
        fs.readFile(Assets.absoluteFilePath('private/i18n/' + locale + '.i18n.json'), 'utf8', function (err, jsonString) {
          if (err) {
            console.error(err);
            return;
          }
          TAPi18n.addResourceBundle(locale, 'project', JSON.parse(jsonString));
        });
      } else {
        // on the client
        const url = new URL('/packages/rationalk_core/private/i18n/' + locale + '.i18n.json', window.location.origin).href;
        fetch(url, {
          method: 'GET',
          headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
        }).then(function (response) {
          if (!response.ok) {
            console.error(response);
            return;
          }
          response.json().then(function (json) {
            TAPi18n.addResourceBundle(locale, 'project', json);
          });
        }).catch(function (err) {
          console.error(err);
        });
      }
    });
  });
});

Do you think this is a good idea ?

I had the same problem some time ago and solved it by changing the library to universe:i18n. It doesn’t take much work to do this, they are quite compatible.

2 Likes

Same here – we also switched to universe:i18n for the same reason. Great library, and the folks who developed it are very responsive.

3 Likes