Skip to content

Commit

Permalink
example using web-dev-server to save missing translations
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Mar 6, 2023
1 parent cd108c9 commit 4287991
Show file tree
Hide file tree
Showing 18 changed files with 28,492 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/devserver-save-missing/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
21 changes: 21 additions & 0 deletions example/devserver-save-missing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions example/devserver-save-missing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example using web-dev-server to save missing translations
36 changes: 36 additions & 0 deletions example/devserver-save-missing/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const i18next = require('i18next');
const Backend = require('i18next-fs-backend');
const i18nextMiddleware = require('i18next-http-middleware');
const bodyParser = require('body-parser');

i18next
.use(Backend)
.use(i18nextMiddleware.LanguageDetector)
.init({
backend: {
loadPath: __dirname + '/public/locales/{{lng}}/{{ns}}.json',
addPath: __dirname + '/public/locales/{{lng}}/{{ns}}.missing.json',
},
fallbackLng: 'en',
// debug: true,
saveMissing: true,
});

module.exports = {
devServer: (configFunction) => (proxy, allowedHost) => {
const config = configFunction(proxy, allowedHost);
config.setupMiddlewares = (middlewares, devServer) => {
if (!devServer) throw new Error('webpack-dev-server is not defined');

devServer.app.post(
'/locales/:lng/:ns',
bodyParser.json(),
i18nextMiddleware.missingKeyHandler(i18next),
);
// addPath for client: http://localhost:3000/locales/{{lng}}/{{ns}}

return middlewares;
};
return config;
},
};
Loading

0 comments on commit 4287991

Please sign in to comment.