-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to customize the context locale (custom directory structure) #8
Labels
Comments
Interesting. This seems partly related to a suggestion from @unconfident re: I'm trying to get a better idea of how. Can you please share an example of how you'd leverage the |
Here is my configuration for your plugin: eleventyConfig.addPlugin(require('eleventy-plugin-i18n'), {
translations: glob.sync('./translations/*.json')
.map(pathname => ({ key: path.basename(pathname, '.json'), contents: require(pathname) }))
.reduce((prev, curr) => ({...prev, [curr.key]: curr.contents }), {}),
fallbackLocales: {
'*': 'it'
},
contextLocale: (page, config) => {
// Test if string starts with a locale prefix (i.e. /en/ or /fr/ with a leading slash)
const isLocalizedUrl = /^\/([\w]{2})\//g.exec((page && page.url) || '');
if (isLocalizedUrl) {
return isLocalizedUrl[1];
}
// ... otherwise assume it's the fallback locale
return config.fallbackLocales['*'];
},
}); |
@adamduncan any update on this? Have you seen my PR, what do you think? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My directory structure doesn't have the folder named "it" (my default / fallback locale) because I'd like to not prefixing my default locale. The plugin, however, will complain about
undefined
locale,Here the products is simple the page url (
/prodotti
).I'll make a PR for it.
The text was updated successfully, but these errors were encountered: