Skip to content

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
typed-sigterm committed Jul 31, 2024
1 parent ec2ac3b commit 4ea32e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 0 additions & 2 deletions components/settings/language.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const options: DropdownOption[] = [
];
function handleSelect(key: string) {
if (i18n.locale.value === key)
return;
switchLanguage(i18n, key);
}
</script>
Expand Down
9 changes: 7 additions & 2 deletions i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import en from './locales/en';
import zhCN from './locales/zh-CN';

export default defineI18nConfig(() => ({
fallbackLocale: 'en',
missingWarn: false,
fallbackWarn: false,
messages: {
en,
'zh-CN': zhCN,
},
}));
10 changes: 0 additions & 10 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,4 @@ export default defineNuxtConfig({
},

compatibilityDate: '2024-07-03',

i18n: {
locales: [
{ code: 'en', file: 'en.ts' },
{ code: 'zh-CN', file: 'zh-CN.ts' },
],
langDir: 'locales',
lazy: true,
defaultLocale: 'en',
},
});
6 changes: 3 additions & 3 deletions utils/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const createNotInAppError = () => createError('Please download the app to

export const DEFAULT_LANG = 'en';

export async function switchLanguage(i18n: ReturnType<typeof useI18n>, lang: string) {
await i18n.loadLocaleMessages(lang);
i18n.setLocale(lang);
export function switchLanguage(i18n: ReturnType<typeof useI18n>, lang: string) {
if (i18n.locale.value !== lang)
i18n.setLocale(lang);
useHead({
htmlAttrs: { lang },
});
Expand Down

0 comments on commit 4ea32e9

Please sign in to comment.