Skip to content

Commit

Permalink
♻️ [dcs] migrate component to composition API
Browse files Browse the repository at this point in the history
  • Loading branch information
jxn-30 committed Jul 16, 2023
1 parent 68115e2 commit 73bb730
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 258 deletions.
21 changes: 20 additions & 1 deletion src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createI18n } from 'vue-i18n-composable';
import VueI18n from 'vue-i18n';
import { createI18n, useI18n as useI18nHelper } from 'vue-i18n-composable';

import type { VueConstructor } from 'vue/types/vue';

Expand Down Expand Up @@ -64,3 +64,22 @@ export default async (Vue: VueConstructor): Promise<VueI18n> => {

return i18n;
};

const useI18n = (scope: string) => {
const { t, tc } = useI18nHelper();
return {
$t: t,
$tc: tc,
$m: (key: VueI18n.Path, args?: VueI18n.Values) =>
t(`${scope}.${key}`, args),
$mc: (
key: VueI18n.Path,
choice?: VueI18n.Choice,
args?: VueI18n.Values
) => tc(`${scope}.${key}`, choice, args),
};
};

const useI18nModule = (module: string) => useI18n(`modules.${module}`);

export { useI18n, useI18nModule };
Loading

0 comments on commit 73bb730

Please sign in to comment.