Skip to content

Commit

Permalink
fix: sync vite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Sep 18, 2024
1 parent 1cd282e commit 9295289
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 725 deletions.
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
strict-peer-dependencies=false
auto-install-peers=true
link-workspace-packages=false
registry=https://registry.npmjs.org/
ignore-workspace-root-check=true
hoist=false
hoist-workspace-packages=false
shamefully-hoist=true
14 changes: 7 additions & 7 deletions playground/remix-flat-routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
"i18next-browser-languagedetector": "^8.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^15.0.1",
"react-i18next": "^15.0.2",
"react-router-dom": "6.26.0",
"zustand": "^4.5.5"
"zustand": "^5.0.0-rc.2"
},
"devDependencies": {
"@minko-fe/postcss-config": "^1.0.1",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"postcss": "^8.4.45",
"tailwindcss": "^3.4.11",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.12",
"typescript": "^5.6.2",
"vite": "^5.4.4",
"vite": "^5.4.6",
"vite-plugin-i18n-ally": "workspace:*",
"vite-plugin-remix-flat-routes": "^3.4.1"
"vite-plugin-remix-flat-routes": "^3.5.3"
}
}
6 changes: 3 additions & 3 deletions playground/remix-ssr/app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const i18nChangeLanguage = i18next.changeLanguage

async function hydrate() {
const { asyncLoadResource } = i18nAlly({
namespaces: [...resolveNamespace(), ...i18nOptions.defaultNS],
namespaces: [...resolveNamespace()],
fallbackLng: i18nOptions.fallbackLng,
async onInit({ language }) {
await i18next.use(initReactI18next).init({
Expand All @@ -20,7 +20,7 @@ async function hydrate() {
fallbackLng: i18nOptions.fallbackLng,
keySeparator: i18nOptions.keySeparator,
nsSeparator: i18nOptions.nsSeparator,
ns: [...resolveNamespace(), ...i18nOptions.defaultNS] as string[],
ns: [...resolveNamespace()] as string[],
debug: import.meta.env.DEV,
})
},
Expand Down Expand Up @@ -54,7 +54,7 @@ async function hydrate() {

i18next.changeLanguage = async (lng?: string, ...args) => {
await asyncLoadResource(lng || i18next.language, {
namespaces: [...resolveNamespace(), ...i18nOptions.defaultNS],
namespaces: [...resolveNamespace()],
})
return i18nChangeLanguage(lng, ...args)
}
Expand Down
11 changes: 8 additions & 3 deletions playground/remix-ssr/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ export default async function handleRequest(
const callbackName = isbotRequest ? 'onAllReady' : 'onShellReady'

const i18nInstance = createInstance()
const lng = new URL(request.url).pathname.split('/').filter(Boolean)[0] || (await i18nServer.getLocale(request))
const ns = i18nServer.getRouteNamespaces(remixContext)

const localeFromPath = new URL(request.url).pathname.split('/').filter(Boolean)[0]
const lng = i18nServerOptions.supportedLngs.includes(localeFromPath)
? localeFromPath
: await i18nServer.getLocale(request)

await i18nInstance.use(initReactI18next).init({
...i18nServerOptions,
lng,
ns: [...ns, ...i18nServerOptions.defaultNS],
ns: i18nServerOptions.resources[lng]
? Object.keys(i18nServerOptions.resources[lng])
: [...i18nServerOptions.defaultNS],
})

return new Promise((resolve, reject) => {
Expand Down
3 changes: 2 additions & 1 deletion playground/remix-ssr/app/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function resolveNamespace(pathname = window.location.pathname): string[]
?.map((route) => route.route.handle)
.filter((t) => t?.i18n)
.map((t) => t.i18n)
.flat() || []
.flat()
.concat(defaultNS) || defaultNS
)
}
4 changes: 2 additions & 2 deletions playground/remix-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"husky": "^9.1.6",
"postcss": "^8.4.47",
"prettier-plugin-tailwindcss": "^0.6.6",
"remix-development-tools": "^4.5.1",
"remix-development-tools": "^4.5.2",
"remix-flat-routes": "^0.6.5",
"simple-git-hooks": "^2.11.1",
"tailwind-antd-preset": "^0.0.4",
Expand All @@ -71,7 +71,7 @@
"vite-plugin-i18n-ally": "workspace:*",
"vite-plugin-istanbul-widget": "^1.9.0",
"vite-plugin-public-typescript": "^4.0.0",
"vite-plugin-remix-flat-routes": "^3.5.0"
"vite-plugin-remix-flat-routes": "^3.5.4"
},
"simple-git-hooks": {
"commit-msg": "npm run commitlint",
Expand Down
10 changes: 5 additions & 5 deletions playground/vscode-setting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"preview": "vite preview"
},
"dependencies": {
"i18next": "^23.14.0",
"i18next": "^23.15.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^15.0.1",
"react-i18next": "^15.0.2",
"vite-plugin-i18n-ally": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"cross-env": "^7.0.3",
"typescript": "^5.5.4",
"vite": "^5.4.3"
"typescript": "^5.6.2",
"vite": "^5.4.6"
}
}
10 changes: 5 additions & 5 deletions playground/with-namespace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"preview": "vite preview"
},
"dependencies": {
"i18next": "^23.14.0",
"i18next": "^23.15.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^15.0.1",
"react-i18next": "^15.0.2",
"vite-plugin-i18n-ally": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"cross-env": "^7.0.3",
"typescript": "^5.5.4",
"vite": "^5.4.3"
"typescript": "^5.6.2",
"vite": "^5.4.6"
}
}
10 changes: 5 additions & 5 deletions playground/without-namespace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"preview": "vite preview"
},
"dependencies": {
"i18next": "^23.14.0",
"i18next": "^23.15.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^15.0.1",
"react-i18next": "^15.0.2",
"vite-plugin-i18n-ally": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"cross-env": "^7.0.3",
"typescript": "^5.5.4",
"vite": "^5.4.3"
"typescript": "^5.6.2",
"vite": "^5.4.6"
}
}
Loading

0 comments on commit 9295289

Please sign in to comment.