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);
});
}
});
});
});
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.