Skip to content

Commit d1abdaf

Browse files
committed
feat(vue-i18n): code improvements
1 parent 7c390b7 commit d1abdaf

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

packages/plugin-vue-i18n/src/localize.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ const localizePlugin: PluginFunc<LocalizePluginOptions> = (pluginOptions, Enum)
3737
const { t: translate } = useI18n(useI18nOptions);
3838
t = translate;
3939
} catch (error) {
40-
console.warn(
41-
`An error occurred in useI18n! Fallback to instance.t if instance is provided. The error is:`,
42-
error
43-
);
40+
console.warn(`An error occurred in useI18n! Fallback to instance.t if instance is provided.`);
41+
console.warn(`The error is:`, error);
4442
t = ((localeKey: string, named: Record<string, unknown>, options: TranslateOptions) => {
4543
if (instance) {
4644
return (instance.global as Composer).t(localeKey, named, options);

packages/plugin-vue-i18n/test/localization.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import viTestBrowser from '@enum-plus/test/engines/vitest-browser';
33
import i18n from './data/i18n';
44
import legacyI18n from './data/legacy-i18n';
55
import testLocalization from './test-suites/localization';
6-
7-
// @ts-expect-error: because env is not defined in some environments
8-
const isLegacy = import.meta.env && import.meta.env.VITE_LEGACY === '1';
6+
import { isLegacy } from './utils';
97

108
testLocalization(viTestBrowser, isLegacy ? legacyI18n : i18n);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @ts-expect-error: because env is not defined in some environments
2+
export const isLegacy = import.meta.env && import.meta.env.VITE_LEGACY === '1';

packages/plugin-vue-i18n/test/vitest.setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { config } from '@vue/test-utils';
22
import { beforeAll } from 'vitest';
33
import i18n from './data/i18n';
44
import legacyI18n from './data/legacy-i18n';
5+
import { isLegacy } from './utils';
56

6-
// @ts-expect-error: because env is not defined in some environments
7-
const isLegacy = import.meta.env && import.meta.env.VITE_LEGACY === '1';
87
beforeAll(() => {
98
if (isLegacy) {
109
config.global.plugins = [legacyI18n];

0 commit comments

Comments
 (0)