Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // load your translations
- // add whatever number namespaces you need
- const localesNSContent = {
- 'en':[
- {
- content:fs.readFileSync(`src/locales/en/translations.json`, 'utf8'),
- ns:'translations'
- }
- ],
- 'pt':[
- {
- content:fs.readFileSync(`src/locales/pt/translations.json`, 'utf8'),
- ns:'translations'
- }
- ],
- };
- const availableLocales = [
- { value: 'en', text: 'English' },
- { value: 'de', text: 'Deutsch' }
- ]
- exports.onCreatePage = async (props) => {
- const { page, actions: { createPage, deletePage, createRedirect } } = props;
- deletePage(page);
- if (page.path.includes('404')) {
- createPage({
- ...page,
- context: {
- locale: 'en-us',
- data: localesNSContent['en-us']
- }
- })
- }
- if (page.path === '/') {
- createPage({
- ...page,
- context: {
- availableLocales
- }
- });
- } else {
- availableLocales.map(({ value }) => {
- let newPath = `/${value}${page.path}`;
- if (page.path === '/homepage/') {
- newPath = `/${value}`
- }
- const localePage = {
- ...page,
- originalPath: page.path,
- path: newPath,
- context: {
- availableLocales,
- locale: value,
- routed: true,
- data: localesNSContent[value],
- originalPath: page.path
- },
- }
- createPage(localePage)
- });
- }
- }
Add Comment
Please, Sign In to add comment