Skip to content

Commit 7159eae

Browse files
Merge pull request #1 from filipko99/FIX-NOT-3407
FIX-NOT-3407: changed fallbackLng to preload
2 parents 10fd34d + 5070681 commit 7159eae

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

demo/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import router from './api'
66
import errorMiddleware from './middlewares/errorMiddleware'
77

88
const i18NextConfig = {
9-
preload: ['sk'],
9+
preload: ['en', 'sk'],
1010
fallbackLng: ['en', 'sk'],
1111
ns: ['translation', 'error', 'success', 'email', 'joi'],
1212
defaultNS: 'translation',

demo/src/middlewares/schemaMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import joiErrorMessages from "./../../locales/joiErrorMessages";
66

77
// In common projects is exported like const i18NextConfig: any = config.get('i18next')
88
const i18NextConfig = {
9-
fallbackLng: ['en', 'sk']
9+
preload: ['en', 'sk']
1010
}
1111

1212
// It's necessary to check if joiErrorMessages were found
@@ -15,7 +15,7 @@ if (!joiErrorMessages) {
1515
console.log('WARNING: joiErrorMessages not found.\nTry to check weather you are importing correct file and he was generated'.yellow)
1616
} else {
1717
Object.keys(joiErrorMessages).forEach((lang) => {
18-
if (!i18NextConfig.fallbackLng.includes(lang)) {
18+
if (!i18NextConfig.preload.includes(lang)) {
1919
console.log(
2020
`WARNING: Missing language key: ${lang} in joiErrorMessages.ts\nRunning script for Joi error messages generating may fix this problem`.yellow
2121
)

lib/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ try {
5050
catch {
5151
console.log(`WARNING: i18next is missing in config module`.yellow);
5252
}
53-
const languages = i18NextConfig?.fallbackLng || ['en', 'sk'];
53+
const languages = i18NextConfig?.preload || ['en', 'sk'];
5454
if (languages.length < 1) {
55-
console.log(`WARNING: 'i18next.fallbackLng' was not found in module 'config'.\nWARNING: Please try to define some, otherwise will be used default: en, sk`.yellow);
55+
console.log(`WARNING: 'i18next.preload' was not found in module 'config'.\nWARNING: Please try to define some, otherwise will be used default: en, sk`.yellow);
5656
}
5757
const init = async () => {
58+
var _a;
5859
const messagePromises = files.map(async (typeName) => {
60+
var _a;
5961
// Import dynamically one by one all type files from joi/lib/types
60-
const type = await Promise.resolve().then(() => __importStar(require(`joi/lib/types/${typeName}`)));
62+
const type = await (_a = `joi/lib/types/${typeName}`, Promise.resolve().then(() => __importStar(require(_a))));
6163
// Check if Joi type has error messages of this type and save them
6264
// By default each type should have error messages
6365
const prototype = Object.getPrototypeOf(type?.default);
@@ -71,7 +73,7 @@ const init = async () => {
7173
const messages = await Promise.all(messagePromises);
7274
const result = {};
7375
// Importing actual data otherwise use an empty object
74-
const actualData = fs_1.default.existsSync(savePath) ? (await Promise.resolve().then(() => __importStar(require(savePath)))).default : {};
76+
const actualData = fs_1.default.existsSync(savePath) ? (await (_a = savePath, Promise.resolve().then(() => __importStar(require(_a))))).default : {};
7577
let newErrorMessagesCount = 0;
7678
// Get all possible messages. If some are generated, replace them with existing ones
7779
languages.forEach((lang) => {

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ try {
2626
} catch {
2727
console.log(`WARNING: i18next is missing in config module`.yellow)
2828
}
29-
const languages: string[] = i18NextConfig?.fallbackLng || ['en', 'sk']
29+
const languages: string[] = i18NextConfig?.preload || ['en', 'sk']
3030

3131
if (languages.length < 1) {
32-
console.log(`WARNING: 'i18next.fallbackLng' was not found in module 'config'.\nWARNING: Please try to define some, otherwise will be used default: en, sk`.yellow)
32+
console.log(`WARNING: 'i18next.preload' was not found in module 'config'.\nWARNING: Please try to define some, otherwise will be used default: en, sk`.yellow)
3333
}
3434

3535
const init = async () => {

0 commit comments

Comments
 (0)