remix-i18next
Advanced tools
Comparing version 6.0.1 to 6.1.0
@@ -109,1 +109,18 @@ import type { Cookie, EntryContext, SessionStorage } from "@remix-run/server-runtime"; | ||
} | ||
/** | ||
* The LanguageDetector contains the logic to detect the user preferred language | ||
* fully server-side by using a SessionStorage, Cookie, URLSearchParams, or | ||
* Headers. | ||
*/ | ||
export declare class LanguageDetector { | ||
private options; | ||
constructor(options: LanguageDetectorOption); | ||
private isSessionOnly; | ||
private isCookieOnly; | ||
detect(request: Request): Promise<string>; | ||
private fromSearchParams; | ||
private fromCookie; | ||
private fromSessionStorage; | ||
private fromHeader; | ||
private fromSupported; | ||
} |
@@ -91,3 +91,8 @@ import { pick } from "accept-language-parser"; | ||
} | ||
class LanguageDetector { | ||
/** | ||
* The LanguageDetector contains the logic to detect the user preferred language | ||
* fully server-side by using a SessionStorage, Cookie, URLSearchParams, or | ||
* Headers. | ||
*/ | ||
export class LanguageDetector { | ||
options; | ||
@@ -123,3 +128,3 @@ constructor(options) { | ||
if (method === "searchParams") { | ||
locale = await this.fromSearchParams(request); | ||
locale = this.fromSearchParams(request); | ||
} | ||
@@ -133,3 +138,3 @@ if (method === "cookie") { | ||
if (method === "header") { | ||
locale = await this.fromHeader(request); | ||
locale = this.fromHeader(request); | ||
} | ||
@@ -141,3 +146,3 @@ if (locale) | ||
} | ||
async fromSearchParams(request) { | ||
fromSearchParams(request) { | ||
let url = new URL(request.url); | ||
@@ -153,4 +158,4 @@ if (!url.searchParams.has(this.options.searchParamKey ?? "lng")) { | ||
let cookie = this.options.cookie; | ||
let lng = (await cookie.parse(request.headers.get("Cookie"))) ?? ""; | ||
if (!lng) | ||
let lng = await cookie.parse(request.headers.get("Cookie")); | ||
if (typeof lng !== "string" || !lng) | ||
return null; | ||
@@ -168,3 +173,3 @@ return this.fromSupported(lng); | ||
} | ||
async fromHeader(request) { | ||
fromHeader(request) { | ||
let locales = getClientLocales(request); | ||
@@ -171,0 +176,0 @@ if (!locales) |
{ | ||
"name": "remix-i18next", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "The easiest way to translate your Remix apps", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -14,2 +14,5 @@ # remix-i18next | ||
> [!TIP] | ||
> If you're using Remix with Vite, check https://github.com/sergiodxa/remix-vite-i18next for an example application, if you have an issue compare your setup with the example. | ||
### Installation | ||
@@ -289,13 +292,2 @@ | ||
> **Warning** In latest versions you may find an error with `useChangeLanguage` hook, (see [#107](https://github.com/sergiodxa/remix-i18next/issues/107)), to solve it, you can deep import it from the package with `import { useChangeLanguage } from 'node_modules/remix-i18next/browser/react';`, or copy the code of `useChangeLanguage` to your own app and use it instead of the one provided by `remix-i18next`. | ||
```ts | ||
export function useChangeLanguage(locale: string) { | ||
let { i18n } = useTranslation(); | ||
useEffect(() => { | ||
i18n.changeLanguage(locale); | ||
}, [locale, i18n]); | ||
} | ||
``` | ||
Finally, in any route you want to translate, you can use the `t()` function, as per the [i18next documentation](https://www.i18next.com/overview/api#t) and use translations from the default namespace. | ||
@@ -302,0 +294,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
443352
495
0
377