Skip to content

Commit

Permalink
Merge pull request #92 from vordgi/nt-85
Browse files Browse the repository at this point in the history
nt-85 release 2.0.0
  • Loading branch information
vordgi authored May 12, 2024
2 parents 1e83e2e + 0548dc0 commit 6a010c4
Show file tree
Hide file tree
Showing 38 changed files with 1,281 additions and 727 deletions.
9 changes: 1 addition & 8 deletions examples/base/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
const withI18n = require('@nimpl/i18n/withI18n').default;

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = async (phase) => {
const withTranslation = await withI18n(phase);
return withTranslation(nextConfig);
};
module.exports = {};
32 changes: 18 additions & 14 deletions examples/base/nimpl-i18n.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const fs = require('fs/promises')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require("fs/promises");

const memo = {};

/** @type {import('@nimpl/i18n/configuration/types').Config} */
module.exports = {
load: async (lang) => {
const data = await fs.readFile(`./translates/${lang}.json`).then((data) => JSON.parse(data))
console.log('load ' + lang);
return { data };
},
/**
* In development mode, the data will be updated each 10 seconds to load changes in files,
* there is no need to track changes in files during the build and after it.
* For other situations, the option can be configured differently
*/
revalidate: process.env.NODE_ENV === 'development' ? 10 : false,
languages: ['de', 'fr', 'en'],
}
load: async (language) => {
memo[language] ||= fs
.readFile(`./translates/${language}.json`)
.then((data) => JSON.parse(data))
.then((data) => {
delete memo[language];
return data;
});
const dictionary = await memo[language];
return dictionary;
},
getLanguage: async ({ params }) => params.lang || "en",
languages: ["en", "fr", "de"],
};
2 changes: 1 addition & 1 deletion examples/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "next start"
},
"dependencies": {
"@nimpl/i18n": "latest",
"@nimpl/i18n": "2.0.0-canary.4",
"next": "latest",
"object-path": "0.11.8",
"react": "18.2.0",
Expand Down
Loading

0 comments on commit 6a010c4

Please sign in to comment.