@vue-sfc-i18n/composable 0.0.4 → 0.0.5

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/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export interface I18nSchema {
2
2
  }
3
3
  type TranslationKey = keyof I18nSchema extends never ? string : keyof I18nSchema;
4
+ type ParamsArg<K extends TranslationKey> = K extends keyof I18nSchema ? I18nSchema[K] extends string ? [] : [params: I18nSchema[K]] : [params?: Record<string, string | number>];
4
5
  type EntryLoader = () => Promise<Record<string, string>>;
5
6
  export declare const useI18n: () => {
6
- t: (key: TranslationKey) => string;
7
+ t: <K extends TranslationKey>(key: K, ...args: ParamsArg<K>) => string;
7
8
  };
8
9
  export declare const manager: {
9
10
  /** @private */
package/dist/index.js CHANGED
@@ -2,7 +2,12 @@ import { ref } from "vue";
2
2
  const translations = ref({});
3
3
  const language = ref(null);
4
4
  const entryLoaders = [];
5
- const t = (key) => translations.value[key] ?? key;
5
+ const interpolate = (str, params) => str.replace(/\{\s*(\w+)\s*\}/g, (_, k) => String(params[k] ?? `{${k}}`));
6
+ const t = (key, ...args) => {
7
+ const value = translations.value[key] ?? key;
8
+ const params = args[0];
9
+ return params ? interpolate(value, params) : value;
10
+ };
6
11
  export const useI18n = () => ({ t });
7
12
  export const manager = {
8
13
  /** @private */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-sfc-i18n/composable",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Vue composable for using i18n translations from Vue SFC custom blocks",
5
5
  "keywords": [
6
6
  "vue",
@@ -38,10 +38,12 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^24.12.2",
41
- "typescript": "^5.9.3"
41
+ "typescript": "^5.9.3",
42
+ "vitest": "^4.1.11"
42
43
  },
43
44
  "scripts": {
44
- "build": "tsc --noEmit false --declaration true --outDir dist",
45
- "type-check": "tsc --noEmit"
45
+ "build": "tsc --noEmit false --allowImportingTsExtensions false --declaration true --outDir dist",
46
+ "type-check": "tsc --noEmit",
47
+ "test": "vitest run"
46
48
  }
47
49
  }