I have successfully implemented i18next, which, by the way, is a great library! Although I'm still looking for "best practice." This is the setup I have right now that I generally like:
var userLanguage = 'en';
In the DOM, I do this:
<span data-i18n="demo.myFirstExample">My first example</span>
And in JS, I do this:
return i18n.t('demo.mySecondExample', 'My second example');
This means that I support English translation inside the code itself. However, I support other languages ββusing separate translation.json files using i18next-parser:
gulp.task('i18next', function() { gulp.src('app/**') .pipe(i18next({ locales : ['nl','de'], output : '../locales' })) .pipe(gulp.dest('locales')); });
Everything works great. The only problem is that when I set 'en' as userLanguage , i18next insists on extracting the file /locales/en/translation.json , although it does not contain any translations. To prevent 404, I am currently serving an empty json object {} in this file.
Is there a way to prevent an empty .json file from loading at all?
source share