Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ exports = module.exports = function (opts) {
var paramLangName = opts.paramLangName || 'clang';
var siteLangs = opts.siteLangs || ['en'];
var textsVarName = opts.textsVarName || 'texts';
var autoReload = opts.autoReload !== false;

if (siteLangs.constructor !== Array) {
throw new Error('siteLangs must be an Array with supported langs.');
Expand All @@ -65,15 +66,17 @@ exports = module.exports = function (opts) {

i18nTranslations = loadLangJSONFiles(translationsPath, defaultLang);

fs.watch(translationsPath, function (event, filename) {
if (filename) {
try {
i18nTranslations = loadLangJSONFiles(translationsPath, defaultLang);
} catch (ee) {
// Some editors first empty the file and then save the content. This generate a "Unexpected end of input" error
if (autoReload === true) {
fs.watch(translationsPath, function (event, filename) {
if (filename) {
try {
i18nTranslations = loadLangJSONFiles(translationsPath, defaultLang);
} catch (ee) {
// Some editors first empty the file and then save the content. This generate a "Unexpected end of input" error
}
}
}
});
});
}

return function i18n (req, res, next) {
var alreadyTryCookie = false;
Expand Down