Skip to content

Commit

Permalink
feat: add LocaleSwitcher component
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Jul 26, 2023
1 parent 27f2e7f commit 499f96a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/admin/autoResolver/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare module 'vue' {
NDivider: typeof import('@celeris/ca-components')['NDivider']
NDrawer: typeof import('@celeris/ca-components')['NDrawer']
NDrawerContent: typeof import('@celeris/ca-components')['NDrawerContent']
NDropdown: typeof import('@celeris/ca-components')['NDropdown']
NForm: typeof import('@celeris/ca-components')['NForm']
NFormItem: typeof import('@celeris/ca-components')['NFormItem']
NGlobalStyle: typeof import('@celeris/ca-components')['NGlobalStyle']
Expand Down
5 changes: 3 additions & 2 deletions apps/admin/src/AppConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LocalesEngine } from "@celeris/locale";
import { createDiscreteApi } from "@celeris/ca-components";
import { field, logger } from "@celeris/utils";
import { useUserStoreWithOut } from "~/store/modules/user";
import { useNaiveUIConfigProvider } from "~/composables";
import { useAppSetting, useNaiveUIConfigProvider } from "~/composables";

const { configProviderProps } = useNaiveUIConfigProvider();

Expand Down Expand Up @@ -67,6 +67,7 @@ function initializeHttpRequest() {
}

function initializeI18n() {
const { getLocale } = useAppSetting();
const messages = Object.fromEntries(
Object.entries(
import.meta.glob<{ default: any }>("./locales/*.json", { eager: true }),
Expand All @@ -75,7 +76,7 @@ function initializeI18n() {
}),
);
LocalesEngine.initLocales(() => ({
locale: "zh",
locale: getLocale.value,
fallbackLocale: "zh",
messagesHandler: () => {
return messages;
Expand Down
31 changes: 31 additions & 0 deletions apps/admin/src/layouts/header/components/LocaleSwitcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { LocalesEngine, languagesNameList, useI18n } from "@celeris/locale";
import IconButtonWithToolTip from "~/layouts/header/components/IconButtonWithToolTip.vue";
import { useAppSetting } from "~/composables";
const { getLocale, setProjectSetting } = useAppSetting();
const { locale, availableLocales, t } = useI18n();

Check warning on line 8 in apps/admin/src/layouts/header/components/LocaleSwitcher.vue

View workflow job for this annotation

GitHub Actions / LINT

't' is assigned a value but never used. Allowed unused vars must match /^_/u
const options = computed(
() => availableLocales.map(item => ({
label: languagesNameList.find(languagesName => languagesName.code === item)?.nativeName,
key: item,
})),
);
const handleSelect = (key: string) => {
setProjectSetting({ locale: key });
locale.value = key;
LocalesEngine.setLocale(key);
};
</script>

<template>
<NDropdown :options="options" trigger="click" :value="getLocale" @select="handleSelect">
<IconButtonWithToolTip tooltip-text="Switch Locale" icon="i-tabler-language" color="gray" />
</NDropdown>
</template>

<style scoped>
</style>
4 changes: 4 additions & 0 deletions apps/admin/src/layouts/header/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import CollapseButton from "~/layouts/header/components/CollapseButton.vue";
import FullScreenButton from "~/layouts/header/components/FullScreenButton.vue";
import LocaleSwitcher from "~/layouts/header/components/LocaleSwitcher.vue";
import UserInfoButton from "~/layouts/header/components/UserInfoButton.vue";
import SettingButton from "~/layouts/setting/index.vue";
Expand All @@ -20,6 +21,9 @@ defineOptions({
<div class="px-2">
<FullScreenButton />
</div>
<div class="px-2">
<LocaleSwitcher />
</div>
</div>
</div>
<div class="hidden md:block px-4">
Expand Down

2 comments on commit 499f96a

@vercel
Copy link

@vercel vercel bot commented on 499f96a Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

celeris-web-api – ./services/admin

celeris-web-api-kirklin.vercel.app
celeris-web-api-git-master-kirklin.vercel.app
celeris-web-api.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 499f96a Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

celeris-web – ./apps/admin

celeris-web-git-master-kirklin.vercel.app
celeris-web.vercel.app
celeris-web-kirklin.vercel.app

Please sign in to comment.