@application-kit/i18n 0.4.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @application-kit/i18n
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b26b1a7: `useLocaleSelection(localeSet, cookie)` во входе `/vue` — модель переключателя языка: чтение с запасной локалью для значения вне набора, запись меняет локаль приложения и пишет cookie.
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -63,6 +63,9 @@ app.use(new I18nPlugin({
63
63
  на сервере модуль живёт между запросами, и язык одного пользователя не доезжает до другого.
64
64
  - `writeLocaleCookie(locale, { name, maxAgeSeconds? })` — запоминает выбор языка для следующего запроса:
65
65
  `Path=/`, `SameSite=Lax`, год по умолчанию, без `HttpOnly` (cookie пишет браузер, значение не секрет).
66
+ - `useLocaleSelection(localeSet, { name, maxAgeSeconds? })` — модель переключателя языка для `v-model`: читает локаль
67
+ приложения (вне набора — `localeSet.fallback`), запись меняет язык приложения и пишет cookie. Варианты и их подписи
68
+ строит приложение: компонент выбора остаётся за ним.
66
69
 
67
70
  ## Сервер
68
71
 
@@ -2,4 +2,5 @@ export * from './i18n-plugin.js';
2
2
  export * from './locale-channel.js';
3
3
  export * from './locale-cookie.js';
4
4
  export * from './module-dictionary.js';
5
+ export * from './use-locale-selection.js';
5
6
  export * from './use-translate.js';
@@ -18,4 +18,5 @@ __exportStar(require("./i18n-plugin.js"), exports);
18
18
  __exportStar(require("./locale-channel.js"), exports);
19
19
  __exportStar(require("./locale-cookie.js"), exports);
20
20
  __exportStar(require("./module-dictionary.js"), exports);
21
+ __exportStar(require("./use-locale-selection.js"), exports);
21
22
  __exportStar(require("./use-translate.js"), exports);
@@ -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;
@@ -2,4 +2,5 @@ export * from './i18n-plugin.js';
2
2
  export * from './locale-channel.js';
3
3
  export * from './locale-cookie.js';
4
4
  export * from './module-dictionary.js';
5
+ export * from './use-locale-selection.js';
5
6
  export * from './use-translate.js';
@@ -2,4 +2,5 @@ export * from './i18n-plugin.js';
2
2
  export * from './locale-channel.js';
3
3
  export * from './locale-cookie.js';
4
4
  export * from './module-dictionary.js';
5
+ export * from './use-locale-selection.js';
5
6
  export * from './use-translate.js';
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@application-kit/i18n",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Локали, словари и плагин vue-i18n для SSR-приложений на Vue и серверный резолв локали запроса",
5
5
  "keywords": [
6
6
  "i18n",