Skip to content

Commit

Permalink
Upgrade to use React Router v7 (#223)
Browse files Browse the repository at this point in the history
Upgrade remix-i18next to drop Remix and use React Router v7 instead.

Fixes #220

---------

Co-authored-by: Sergio Xalambrí <[email protected]>
  • Loading branch information
AlemTuzlak and sergiodxa authored Nov 22, 2024
1 parent 938bef1 commit b5e8119
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/coverage
/docs
/node_modules
*.log
*.log
Binary file modified bun.lockb
Binary file not shown.
33 changes: 4 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.0",
"@biomejs/biome": "^1.9.2",
"@remix-run/cloudflare": "^2.0.0",
"@remix-run/deno": "^2.0.0",
"@remix-run/dev": "^2.12.1",
"@remix-run/node": "^2.0.0",
"@remix-run/react": "^2.0.0",
"@remix-run/server-runtime": "^2.12.1",
"@total-typescript/tsconfig": "^1.0.4",
"@types/accept-language-parser": "^1.5.6",
"@types/bun": "^1.1.9",
Expand All @@ -27,15 +21,13 @@
"i18next": "^23.1.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-i18next": "^13.0.0 || ^14.0.0 || ^15.0.0",
"react-router": "^7.0.0",
"typedoc": "^0.26.7",
"typedoc-plugin-mdn-links": "^3.3.0",
"typescript": "^5.6.2"
},
"peerDependencies": {
"@remix-run/cloudflare": "^2.0.0",
"@remix-run/deno": "^2.0.0",
"@remix-run/node": "^2.0.0",
"@remix-run/react": "^2.0.0",
"react-router": "^7.0.0",
"i18next": "^23.1.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-i18next": "^13.0.0 || ^14.0.0 || ^15.0.0"
Expand All @@ -49,31 +41,14 @@
"bugs": {
"url": "https://github.com/sergiodxa/remix-i18next/issues"
},
"description": "The easiest way to translate your Remix apps",
"description": "The easiest way to translate your FullStack React Router apps",
"engines": {
"node": ">=20.0.0"
},
"funding": "https://github.com/sponsors/sergiodxa",
"homepage": "https://github.com/sergiodxa/remix-i18next#readme",
"keywords": [
"remix",
"i18n",
"i18next",
"ssr",
"csr"
],
"keywords": ["remix", "i18n", "i18next", "ssr", "csr"],
"license": "MIT",
"peerDependenciesMeta": {
"@remix-run/cloudflare": {
"optional": true
},
"@remix-run/deno": {
"optional": true
},
"@remix-run/node": {
"optional": true
}
},
"scripts": {
"build": "tsc",
"typecheck": "tsc --noEmit",
Expand Down
12 changes: 10 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import type { UNSAFE_RouteModules } from "react-router";

declare global {
interface Window {
__reactRouterRouteModules: UNSAFE_RouteModules;
}
}

/**
* Get the list of namespaces used by the application server-side so you could
* set it on i18next init options.
Expand All @@ -8,15 +16,15 @@
* })
*/
export function getInitialNamespaces(): string[] {
let namespaces = Object.values(window.__remixRouteModules).flatMap(
let namespaces = Object.values(window.__reactRouterRouteModules).flatMap(
(route) => {
if (typeof route?.handle !== "object") return [];
if (!route.handle) return [];
if (!("i18n" in route.handle)) return [];
if (typeof route.handle.i18n === "string") return [route.handle.i18n];
if (
Array.isArray(route.handle.i18n) &&
route.handle.i18n.every((value) => typeof value === "string")
route.handle.i18n.every((value: unknown) => typeof value === "string")
) {
return route.handle.i18n as string[];
}
Expand Down
2 changes: 1 addition & 1 deletion src/react.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMatches } from "@remix-run/react";
import * as React from "react";
import { useTranslation } from "react-i18next";
import { useMatches } from "react-router";

/**
* Get the locale returned by the root route loader under the `locale` key.
Expand Down
2 changes: 1 addition & 1 deletion src/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { createCookie, createMemorySessionStorage } from "@remix-run/node";
import type { BackendModule, FormatterModule } from "i18next";
import { createCookie, createMemorySessionStorage } from "react-router";
import { RemixI18Next } from "./server.js";

describe(RemixI18Next.name, () => {
Expand Down
6 changes: 1 addition & 5 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import type {
Cookie,
EntryContext,
SessionStorage,
} from "@remix-run/server-runtime";
import {
type BackendModule,
type DefaultNamespace,
Expand All @@ -15,6 +10,7 @@ import {
type TFunction,
createInstance,
} from "i18next";
import type { Cookie, EntryContext, SessionStorage } from "react-router";
import { getClientLocales } from "./lib/get-client-locales.js";
import { pick } from "./lib/parser.js";

Expand Down

0 comments on commit b5e8119

Please sign in to comment.