mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
perf: dont fs.open if plugin doesnt have language namespace (#9893)
closes #9892
This commit is contained in:
committed by
GitHub
parent
b0a24d6dd5
commit
1feb111ade
@@ -99,7 +99,12 @@ async function buildNamespaceLanguage(lang, namespace, plugins) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addPlugin(translations, pluginData, lang, namespace) {
|
async function addPlugin(translations, pluginData, lang, namespace) {
|
||||||
const pluginLanguages = path.join(paths.nodeModules, pluginData.id, pluginData.languages);
|
// if plugin doesn't have this namespace no need to continue
|
||||||
|
if (pluginData.languageData && !pluginData.languageData.namespaces.includes(namespace)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathToPluginLanguageFolder = path.join(paths.nodeModules, pluginData.id, pluginData.languages);
|
||||||
const defaultLang = pluginData.defaultLang || 'en-GB';
|
const defaultLang = pluginData.defaultLang || 'en-GB';
|
||||||
|
|
||||||
// for each plugin, fallback in this order:
|
// for each plugin, fallback in this order:
|
||||||
@@ -116,7 +121,7 @@ async function addPlugin(translations, pluginData, lang, namespace) {
|
|||||||
|
|
||||||
for (const language of langs) {
|
for (const language of langs) {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
await assignFileToTranslations(translations, path.join(pluginLanguages, language, `${namespace}.json`));
|
await assignFileToTranslations(translations, path.join(pathToPluginLanguageFolder, language, `${namespace}.json`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const file = require('../file');
|
const file = require('../file');
|
||||||
@@ -245,9 +246,8 @@ Data.getLanguageData = async function getLanguageData(pluginData) {
|
|||||||
languages.push(language);
|
languages.push(language);
|
||||||
namespaces.push(namespace);
|
namespaces.push(namespace);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
languages,
|
languages: _.uniq(languages),
|
||||||
namespaces,
|
namespaces: _.uniq(namespaces),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ module.exports = function (Plugins) {
|
|||||||
if (results.languageData) {
|
if (results.languageData) {
|
||||||
Plugins.languageData.languages = _.union(Plugins.languageData.languages, results.languageData.languages);
|
Plugins.languageData.languages = _.union(Plugins.languageData.languages, results.languageData.languages);
|
||||||
Plugins.languageData.namespaces = _.union(Plugins.languageData.namespaces, results.languageData.namespaces);
|
Plugins.languageData.namespaces = _.union(Plugins.languageData.namespaces, results.languageData.namespaces);
|
||||||
|
pluginData.languageData = results.languageData;
|
||||||
}
|
}
|
||||||
Plugins.pluginsData[pluginData.id] = pluginData;
|
Plugins.pluginsData[pluginData.id] = pluginData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user