Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/easy-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class EasyI18n {
const { distFile } = this.options;
try {
const data = Utils.noCacheRequire(distFile);
this.existedData = data.default || data;
this.existedData = Utils.extractLocaleFromExport(data);
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -188,7 +188,8 @@ class EasyI18n {

async check() {
const { distFile } = this.options;
const checkTarget = Utils.noCacheRequire(distFile);
let checkTarget = Utils.noCacheRequire(distFile);
checkTarget = Utils.extractLocaleFromExport(checkTarget);
const lines = [];
const lineOffset = await this._getLineOffset();
Object.keys(checkTarget).forEach((key, index) => {
Expand Down
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ Utils.noCacheRequire = function (resolvedPath) {
return require(resolvedPath);
};

Utils.extractLocaleFromExport = function (data) {
// 处理各类场景下的 i18n 数据
const exportValue = data.default || data;
const firstValue = Object.values(exportValue)[0];

if (typeof firstValue === 'object') {
return firstValue;
}

return exportValue;
};

module.exports = Utils;