Skip to content

Commit 5ba4ca1

Browse files
committed
refactor: improve i18n path resolution to support custom locales and enhance logging
1 parent 5b77e48 commit 5ba4ca1

File tree

1 file changed

+14
-12
lines changed
  • apps/nestjs-backend/src/utils

1 file changed

+14
-12
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import fs from 'fs';
22
import path from 'path';
33

4-
export const getI18nPath = () => {
5-
const isDev = process.env.NODE_ENV !== 'production';
6-
7-
const resultPath = isDev
8-
? path.join(__dirname, '../../../packages/common-i18n/src/locales')
9-
: path.join(__dirname, './node_modules/@teable/common-i18n/src/locales');
4+
const localPaths = [
5+
process.env.I18N_LOCALES_PATH || '',
6+
path.join(__dirname, '../../../packages/common-i18n/src/locales'),
7+
];
108

11-
if (!fs.existsSync(resultPath)) {
12-
console.error('nestjs-backend I18n path not found', isDev, __dirname, resultPath);
13-
return null;
14-
}
15-
console.log('nestjs-backend I18n path found', isDev, __dirname, resultPath);
16-
return resultPath;
9+
export const getI18nPath = () => {
10+
console.log('nestjs-backend I18n path checking', __dirname, 'localPaths', localPaths);
11+
return localPaths.find((str) => {
12+
const exists = fs.existsSync(str);
13+
console.log(`nestjs-backend I18n path checking exists ${exists} ${str} `);
14+
if (exists) {
15+
console.log('nestjs-backend I18n path found', str);
16+
}
17+
return exists;
18+
});
1719
};

0 commit comments

Comments
 (0)