Skip to content

Commit

Permalink
Fix pathnames with trailing slash (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca authored Dec 12, 2019
1 parent cd69557 commit 5d321f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-translate",
"version": "0.1.7",
"version": "0.1.8",
"description": "Next.js utility to translate pages without the need of a server (static i18n pages generator).",
"license": "MIT",
"keywords": [
Expand Down
8 changes: 6 additions & 2 deletions src/appWithI18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function getLang(ctx, config) {
return startsWithLang ? asPath.split('/')[1] : config.defaultLanguage
}

function removeTrailingSlash(path = '') {
return path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path
}

export default function appWithI18n(AppToTranslate, config = {}) {
function AppWithTranslations(props) {
const { lang, namespaces } = props
Expand All @@ -33,9 +37,9 @@ export default function appWithI18n(AppToTranslate, config = {}) {
Component, ctx, lang
})) || {}
}

const page = removeTrailingSlash(ctx.pathname)
const { pages = {} } = config
const namespaces = pages[ctx.pathname] || []
const namespaces = pages[page] || []
const pageNamespaces = await Promise.all(
namespaces.map(ns =>
typeof config.loadLocaleFrom === 'function'
Expand Down

0 comments on commit 5d321f1

Please sign in to comment.