@application-kit/i18n 0.2.0 → 0.3.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.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 61cb664: `useTranslate()` во входе `@application-kit/i18n/vue` — перевод и локаль для компонента без импорта `vue-i18n`. Пресет `@application-kit/lint-config` запрещает импорт `vue-i18n` в `src/libs` и `src/modules`.
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -53,6 +53,8 @@ app.use(new I18nPlugin({
53
53
  - `I18nPlugin` — ставит `vue-i18n` (Composition API), стартовая и запасная локаль — `localeSet.fallback`.
54
54
  - `collectModuleDictionaries(registry)` — словари модулей реестра в порядке регистрации. Реестр структурный:
55
55
  достаточно `getModules()`; словарь берётся у модуля с методом `getDictionary`.
56
+ - `useTranslate()` — перевод и локаль в `setup` компонента: `{ locale, t }`, область всегда глобальная, запись в
57
+ `locale` меняет язык всего приложения. Приложение импортирует его, а не `vue-i18n`: механизм словаря меняется в пакете.
56
58
  - `setLocale(app, locale)`, `getLocaleReference(app)`, `getTranslate(app)` — локаль и перевод конкретного
57
59
  экземпляра приложения для кода вне компонентов. Состояние хранится по `App` (`WeakMap`), а не в модуле:
58
60
  на сервере модуль живёт между запросами, и язык одного пользователя не доезжает до другого.
@@ -1,3 +1,4 @@
1
1
  export * from './i18n-plugin.js';
2
2
  export * from './locale-cookie.js';
3
3
  export * from './module-dictionary.js';
4
+ export * from './use-translate.js';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./i18n-plugin.js"), exports);
18
18
  __exportStar(require("./locale-cookie.js"), exports);
19
19
  __exportStar(require("./module-dictionary.js"), exports);
20
+ __exportStar(require("./use-translate.js"), exports);
@@ -0,0 +1,7 @@
1
+ import type { WritableComputedRef } from 'vue';
2
+ import type { TranslateFunction } from '../translate-function.js';
3
+ export interface TranslateComposableInterface {
4
+ locale: WritableComputedRef<string>;
5
+ t: TranslateFunction;
6
+ }
7
+ export declare const useTranslate: () => TranslateComposableInterface;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTranslate = void 0;
4
+ const vue_i18n_1 = require("vue-i18n");
5
+ const useTranslate = () => {
6
+ const { locale, t } = (0, vue_i18n_1.useI18n)({ useScope: 'global' });
7
+ return { locale, t: (key, named) => t(key, named ?? {}) };
8
+ };
9
+ exports.useTranslate = useTranslate;
@@ -1,3 +1,4 @@
1
1
  export * from './i18n-plugin.js';
2
2
  export * from './locale-cookie.js';
3
3
  export * from './module-dictionary.js';
4
+ export * from './use-translate.js';
@@ -1,3 +1,4 @@
1
1
  export * from './i18n-plugin.js';
2
2
  export * from './locale-cookie.js';
3
3
  export * from './module-dictionary.js';
4
+ export * from './use-translate.js';
@@ -0,0 +1,7 @@
1
+ import type { WritableComputedRef } from 'vue';
2
+ import type { TranslateFunction } from '../translate-function.js';
3
+ export interface TranslateComposableInterface {
4
+ locale: WritableComputedRef<string>;
5
+ t: TranslateFunction;
6
+ }
7
+ export declare const useTranslate: () => TranslateComposableInterface;
@@ -0,0 +1,5 @@
1
+ import { useI18n } from 'vue-i18n';
2
+ export const useTranslate = () => {
3
+ const { locale, t } = useI18n({ useScope: 'global' });
4
+ return { locale, t: (key, named) => t(key, named ?? {}) };
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@application-kit/i18n",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Локали, словари и плагин vue-i18n для SSR-приложений на Vue и серверный резолв локали запроса",
5
5
  "keywords": [
6
6
  "i18n",