i18next-hmr
Advanced tools
Comparing version 1.9.0 to 1.10.0
@@ -7,4 +7,10 @@ ### Changelog | ||
#### [v1.10.0](https://github.com/felixmosh/i18next-hmr/compare/v1.9.0...v1.10.0) | ||
- feat: Add support for watching multiple locales dirs, #116 [`5302b06`](https://github.com/felixmosh/i18next-hmr/commit/5302b06010725b0c280ef7fa5f679fd295634f5b) | ||
#### [v1.9.0](https://github.com/felixmosh/i18next-hmr/compare/v1.8.1...v1.9.0) | ||
> 11 August 2022 | ||
- feat: add support for options.lng, options.fallbackLng, options.supportedLngs as a language source [`fae8a57`](https://github.com/felixmosh/i18next-hmr/commit/fae8a57132350dd56e176a18ecb379adf063999f) | ||
@@ -11,0 +17,0 @@ - feat: add support for strict language detection [`ea6a877`](https://github.com/felixmosh/i18next-hmr/commit/ea6a877bd1a4047784cd45a819bbcce43ea5e306) |
module.exports = function (content) { | ||
this.addContextDependency(this.query.localesDir); | ||
this.query.localesDirs.forEach((dir) => this.addContextDependency(dir)); | ||
return ( | ||
@@ -4,0 +4,0 @@ content.replace(`'__PLACEHOLDER__'`, JSON.stringify(this.query.getChangedLang())) + |
@@ -8,2 +8,3 @@ const path = require('path'); | ||
localesDir: '', | ||
localesDirs: [], | ||
}; | ||
@@ -14,2 +15,5 @@ | ||
this.options = { ...DEFAULT_OPTIONS, ...options }; | ||
this.options.localesDirs = [] | ||
.concat(this.options.localesDirs, this.options.localesDir) | ||
.filter(Boolean); | ||
this.lastUpdate = { changedFiles: [] }; | ||
@@ -24,6 +28,12 @@ } | ||
compiler.hooks.beforeCompile.tapAsync(pluginName, (params, callback) => { | ||
if (fs.existsSync(this.options.localesDir)) { | ||
const noneExistsDirs = this.options.localesDirs.filter((dir) => !fs.existsSync(dir)); | ||
if (noneExistsDirs.length === 0) { | ||
return callback(); | ||
} | ||
throw new Error(`i18next-hmr: '${this.options.localesDir}' not found`); | ||
throw new Error( | ||
`i18next-hmr: \n'${noneExistsDirs.join(`',\n'`)}'${ | ||
noneExistsDirs.length > 1 ? '\nare' : '' | ||
} not found` | ||
); | ||
}); | ||
@@ -41,3 +51,5 @@ | ||
return ( | ||
file.includes(this.options.localesDir) && !!fileExt && changedTimes[file] > startTime | ||
this.options.localesDirs.some((dir) => file.startsWith(dir)) && | ||
!!fileExt && | ||
changedTimes[file] > startTime | ||
); | ||
@@ -52,6 +64,5 @@ }); | ||
const fileExt = path.extname(file); | ||
const dir = this.options.localesDirs.find((dir) => file.startsWith(dir)); | ||
return path | ||
.relative(this.options.localesDir, file) | ||
.slice(0, -1 * fileExt.length || undefined); // keep all when fileExt.length === 0 | ||
return path.relative(dir, file).slice(0, -1 * fileExt.length || undefined); // keep all when fileExt.length === 0 | ||
}); | ||
@@ -74,3 +85,3 @@ | ||
options: { | ||
localesDir: this.options.localesDir, | ||
localesDirs: this.options.localesDirs, | ||
getChangedLang: () => ({ ...this.lastUpdate }), | ||
@@ -77,0 +88,0 @@ }, |
{ | ||
"name": "i18next-hmr", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "I18Next HMR webpack plugin that allows reloading translation resources on the client & the server.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
export class I18NextHMRPlugin { | ||
static addListener(cb: (data: { lang: string; ns: string }) => void): void; | ||
constructor(options: { localesDir: string }); | ||
constructor(options: { localesDir: string; localesDirs: string[] }); | ||
} |
@@ -34,3 +34,6 @@ # i18next-hmr | ||
new I18NextHMRPlugin({ | ||
localesDir: path.resolve(__dirname, 'static/locales'), | ||
localesDir: path.resolve(__dirname, 'static/locales'), | ||
localesDirs: [ | ||
// use this property for multiple locales directories | ||
] | ||
}) | ||
@@ -37,0 +40,0 @@ ] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33957
259
109