@application-kit/i18n 0.3.0 → 0.5.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 +12 -0
- package/README.md +6 -0
- package/dist/cjs/vue/index.d.ts +2 -0
- package/dist/cjs/vue/index.js +2 -0
- package/dist/cjs/vue/locale-channel.d.ts +13 -0
- package/dist/cjs/vue/locale-channel.js +21 -0
- package/dist/cjs/vue/use-locale-selection.d.ts +4 -0
- package/dist/cjs/vue/use-locale-selection.js +17 -0
- package/dist/esm/vue/index.d.ts +2 -0
- package/dist/esm/vue/index.js +2 -0
- package/dist/esm/vue/locale-channel.d.ts +13 -0
- package/dist/esm/vue/locale-channel.js +17 -0
- package/dist/esm/vue/use-locale-selection.d.ts +4 -0
- package/dist/esm/vue/use-locale-selection.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @application-kit/i18n
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b26b1a7: `useLocaleSelection(localeSet, cookie)` во входе `/vue` — модель переключателя языка: чтение с запасной локалью для значения вне набора, запись меняет локаль приложения и пишет cookie.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 2a51c82: Каналы значений «сервер → клиент». `vue-ssr`: опция `channels` у `createSsrEntry` и `hydrateSsrApplication`, контракт `SsrChannelInterface`, `PiniaPlugin`. Ломает: `describePage` заменена на `resolveLang`, значения `window.*` идут только каналами; `channels` обязательна у обеих функций, `beforeMount` стал необязательным. `i18n/vue`: `createLocaleChannel`. `feature-flags/vue`: `createFeatureFlagChannel`.
|
|
14
|
+
|
|
3
15
|
## 0.3.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -55,11 +55,17 @@ app.use(new I18nPlugin({
|
|
|
55
55
|
достаточно `getModules()`; словарь берётся у модуля с методом `getDictionary`.
|
|
56
56
|
- `useTranslate()` — перевод и локаль в `setup` компонента: `{ locale, t }`, область всегда глобальная, запись в
|
|
57
57
|
`locale` меняет язык всего приложения. Приложение импортирует его, а не `vue-i18n`: механизм словаря меняется в пакете.
|
|
58
|
+
- `createLocaleChannel(localeSet)` — канал локали для `createSsrEntry` и `hydrateSsrApplication` пакета
|
|
59
|
+
`@application-kit/vue-ssr`: клиент получает готовое решение сервера, не поддержанное набором значение с провода не
|
|
60
|
+
применяется. Пакет он не импортирует, совпадение — по форме.
|
|
58
61
|
- `setLocale(app, locale)`, `getLocaleReference(app)`, `getTranslate(app)` — локаль и перевод конкретного
|
|
59
62
|
экземпляра приложения для кода вне компонентов. Состояние хранится по `App` (`WeakMap`), а не в модуле:
|
|
60
63
|
на сервере модуль живёт между запросами, и язык одного пользователя не доезжает до другого.
|
|
61
64
|
- `writeLocaleCookie(locale, { name, maxAgeSeconds? })` — запоминает выбор языка для следующего запроса:
|
|
62
65
|
`Path=/`, `SameSite=Lax`, год по умолчанию, без `HttpOnly` (cookie пишет браузер, значение не секрет).
|
|
66
|
+
- `useLocaleSelection(localeSet, { name, maxAgeSeconds? })` — модель переключателя языка для `v-model`: читает локаль
|
|
67
|
+
приложения (вне набора — `localeSet.fallback`), запись меняет язык приложения и пишет cookie. Варианты и их подписи
|
|
68
|
+
строит приложение: компонент выбора остаётся за ним.
|
|
63
69
|
|
|
64
70
|
## Сервер
|
|
65
71
|
|
package/dist/cjs/vue/index.d.ts
CHANGED
package/dist/cjs/vue/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./i18n-plugin.js"), exports);
|
|
18
|
+
__exportStar(require("./locale-channel.js"), exports);
|
|
18
19
|
__exportStar(require("./locale-cookie.js"), exports);
|
|
19
20
|
__exportStar(require("./module-dictionary.js"), exports);
|
|
21
|
+
__exportStar(require("./use-locale-selection.js"), exports);
|
|
20
22
|
__exportStar(require("./use-translate.js"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import type { LocaleSetInterface } from '../define-locales.js';
|
|
3
|
+
export interface LocaleChannelInterface<L extends string> {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
restore(app: App, serialized: string | undefined): void;
|
|
6
|
+
withValue(locale: L): LocaleChannelValueInterface;
|
|
7
|
+
}
|
|
8
|
+
export interface LocaleChannelValueInterface {
|
|
9
|
+
apply(app: App): void;
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly serialized: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const createLocaleChannel: <L extends string>(localeSet: LocaleSetInterface<L>) => LocaleChannelInterface<L>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLocaleChannel = void 0;
|
|
4
|
+
const i18n_plugin_js_1 = require("./i18n-plugin.js");
|
|
5
|
+
const LOCALE_CHANNEL_KEY = 'ssrLocale';
|
|
6
|
+
const createLocaleChannel = (localeSet) => ({
|
|
7
|
+
key: LOCALE_CHANNEL_KEY,
|
|
8
|
+
restore: (app, serialized) => {
|
|
9
|
+
if (localeSet.isSupported(serialized)) {
|
|
10
|
+
(0, i18n_plugin_js_1.setLocale)(app, serialized);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
withValue: (locale) => ({
|
|
14
|
+
apply: (app) => {
|
|
15
|
+
(0, i18n_plugin_js_1.setLocale)(app, locale);
|
|
16
|
+
},
|
|
17
|
+
key: LOCALE_CHANNEL_KEY,
|
|
18
|
+
serialized: locale,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
exports.createLocaleChannel = createLocaleChannel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WritableComputedRef } from 'vue';
|
|
2
|
+
import type { LocaleSetInterface } from '../define-locales.js';
|
|
3
|
+
import type { LocaleCookieOptionsInterface } from './locale-cookie.js';
|
|
4
|
+
export declare const useLocaleSelection: <L extends string>(localeSet: LocaleSetInterface<L>, cookie: LocaleCookieOptionsInterface) => WritableComputedRef<L>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocaleSelection = void 0;
|
|
4
|
+
const vue_1 = require("vue");
|
|
5
|
+
const locale_cookie_js_1 = require("./locale-cookie.js");
|
|
6
|
+
const use_translate_js_1 = require("./use-translate.js");
|
|
7
|
+
const useLocaleSelection = (localeSet, cookie) => {
|
|
8
|
+
const { locale } = (0, use_translate_js_1.useTranslate)();
|
|
9
|
+
return (0, vue_1.computed)({
|
|
10
|
+
get: () => (localeSet.isSupported(locale.value) ? locale.value : localeSet.fallback),
|
|
11
|
+
set: (value) => {
|
|
12
|
+
locale.value = value;
|
|
13
|
+
(0, locale_cookie_js_1.writeLocaleCookie)(value, cookie);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.useLocaleSelection = useLocaleSelection;
|
package/dist/esm/vue/index.d.ts
CHANGED
package/dist/esm/vue/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import type { LocaleSetInterface } from '../define-locales.js';
|
|
3
|
+
export interface LocaleChannelInterface<L extends string> {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
restore(app: App, serialized: string | undefined): void;
|
|
6
|
+
withValue(locale: L): LocaleChannelValueInterface;
|
|
7
|
+
}
|
|
8
|
+
export interface LocaleChannelValueInterface {
|
|
9
|
+
apply(app: App): void;
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly serialized: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const createLocaleChannel: <L extends string>(localeSet: LocaleSetInterface<L>) => LocaleChannelInterface<L>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { setLocale } from './i18n-plugin.js';
|
|
2
|
+
const LOCALE_CHANNEL_KEY = 'ssrLocale';
|
|
3
|
+
export const createLocaleChannel = (localeSet) => ({
|
|
4
|
+
key: LOCALE_CHANNEL_KEY,
|
|
5
|
+
restore: (app, serialized) => {
|
|
6
|
+
if (localeSet.isSupported(serialized)) {
|
|
7
|
+
setLocale(app, serialized);
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
withValue: (locale) => ({
|
|
11
|
+
apply: (app) => {
|
|
12
|
+
setLocale(app, locale);
|
|
13
|
+
},
|
|
14
|
+
key: LOCALE_CHANNEL_KEY,
|
|
15
|
+
serialized: locale,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WritableComputedRef } from 'vue';
|
|
2
|
+
import type { LocaleSetInterface } from '../define-locales.js';
|
|
3
|
+
import type { LocaleCookieOptionsInterface } from './locale-cookie.js';
|
|
4
|
+
export declare const useLocaleSelection: <L extends string>(localeSet: LocaleSetInterface<L>, cookie: LocaleCookieOptionsInterface) => WritableComputedRef<L>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import { writeLocaleCookie } from './locale-cookie.js';
|
|
3
|
+
import { useTranslate } from './use-translate.js';
|
|
4
|
+
export const useLocaleSelection = (localeSet, cookie) => {
|
|
5
|
+
const { locale } = useTranslate();
|
|
6
|
+
return computed({
|
|
7
|
+
get: () => (localeSet.isSupported(locale.value) ? locale.value : localeSet.fallback),
|
|
8
|
+
set: (value) => {
|
|
9
|
+
locale.value = value;
|
|
10
|
+
writeLocaleCookie(value, cookie);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|