Skip to content

Commit

Permalink
fix namespaces in Next.js +11 after history.back()
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Jul 4, 2022
1 parent 051cc51 commit 68483af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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": "1.5.0-canary.3",
"version": "1.5.0-canary.4",
"description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
"license": "MIT",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions src/I18nProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function I18nProvider({
const { locale, defaultLocale } = useRouter() || {}
const internal = useContext(InternalContext)
const allNamespaces: Record<string, I18nDictionary> = {
...initialBrowserNamespaces(),
...internal.ns,
...namespaces,
}
Expand All @@ -35,3 +36,8 @@ export default function I18nProvider({
</I18nContext.Provider>
)
}

function initialBrowserNamespaces() {
if (typeof window === 'undefined') return {}
return window.__NEXT_DATA__?.props?.__namespaces || {}
}

0 comments on commit 68483af

Please sign in to comment.