akanjs 2.2.3 → 2.2.4-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/client/makePageProto.tsx +5 -2
- package/client/translator.ts +8 -0
- package/package.json +1 -1
- package/types/client/translator.d.ts +2 -0
- package/ui/System/Client.tsx +5 -1
package/CHANGELOG.md
CHANGED
package/client/makePageProto.tsx
CHANGED
|
@@ -25,8 +25,11 @@ const getPageInfo = (): { locale: string; path: string } => {
|
|
|
25
25
|
const localeSet = new Set(locales);
|
|
26
26
|
if (getEnv().side !== "server") {
|
|
27
27
|
const [, firstSegment = "", ...rest] = window.location.pathname.split("/");
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const hasLocalePrefix = localeSet.has(firstSegment);
|
|
29
|
+
|
|
30
|
+
const activeLocale = Translator.getActiveLocale();
|
|
31
|
+
const locale = activeLocale ?? (hasLocalePrefix ? firstSegment : defaultLocale);
|
|
32
|
+
return { locale, path: hasLocalePrefix ? `/${rest.join("/")}` : window.location.pathname };
|
|
30
33
|
}
|
|
31
34
|
const h = headers();
|
|
32
35
|
|
package/client/translator.ts
CHANGED
|
@@ -13,6 +13,14 @@ export class Translator {
|
|
|
13
13
|
static #langDictionaryMap = new Map<string, Dictionary>();
|
|
14
14
|
|
|
15
15
|
static #seededDicts = new WeakSet<object>();
|
|
16
|
+
|
|
17
|
+
static #activeLocale: string | undefined;
|
|
18
|
+
static setActiveLocale(lang: string | undefined) {
|
|
19
|
+
if (lang) Translator.#activeLocale = lang;
|
|
20
|
+
}
|
|
21
|
+
static getActiveLocale(): string | undefined {
|
|
22
|
+
return Translator.#activeLocale;
|
|
23
|
+
}
|
|
16
24
|
constructor(dictionary: Record<string, Record<string, Record<string, unknown>>>) {
|
|
17
25
|
Object.entries(dictionary).forEach(([lang, dictionary]) => {
|
|
18
26
|
this.#setDictionary(lang, dictionary);
|
package/package.json
CHANGED
|
@@ -8,6 +8,8 @@ export interface AllDictionary {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class Translator {
|
|
10
10
|
#private;
|
|
11
|
+
static setActiveLocale(lang: string | undefined): void;
|
|
12
|
+
static getActiveLocale(): string | undefined;
|
|
11
13
|
constructor(dictionary: Record<string, Record<string, Record<string, unknown>>>);
|
|
12
14
|
hasDictionary(lang: string): boolean;
|
|
13
15
|
static seed(lang: string, dict: Dictionary | undefined): void;
|
package/ui/System/Client.tsx
CHANGED
|
@@ -55,7 +55,11 @@ export const ClientWrapper = ({
|
|
|
55
55
|
reconnect = true,
|
|
56
56
|
}: ClientWrapperProps) => {
|
|
57
57
|
|
|
58
|
-
if (dictionary)
|
|
58
|
+
if (dictionary) {
|
|
59
|
+
Translator.seed(lang, dictionary);
|
|
60
|
+
|
|
61
|
+
if (typeof window !== "undefined") Translator.setActiveLocale(lang);
|
|
62
|
+
}
|
|
59
63
|
if (getEnv().renderMode === "ssr") {
|
|
60
64
|
}
|
|
61
65
|
useLayoutEffect(() => {
|