Skip to content

Commit 7be29bb

Browse files
committed
feat: update frontend i18n interface
1 parent 8e832ea commit 7be29bb

File tree

13 files changed

+315
-70
lines changed

13 files changed

+315
-70
lines changed

Diff for: frontend/package-lock.json

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: frontend/src/App.vue

+3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { bus, BUS_EVENT } from 'src/utils/bus';
1111
import { useUserStore } from 'src/stores/user';
1212
import { i18n } from 'src/boot/i18n';
1313
import { supportLanguages } from 'src/i18n';
14+
import { useMenuStore } from 'src/stores/menu';
1415
// import { testSatisfies } from 'src/utils/version';
1516
1617
export default {
1718
setup() {
1819
const appStore = useAppStore();
1920
const websocketStore = useSocketStore();
2021
const userStore = useUserStore();
22+
const menuStore = useMenuStore();
2123
2224
let terminusLanguage = '';
2325
let terminusLanguageInfo: any = document.querySelector(
@@ -39,6 +41,7 @@ export default {
3941
4042
onMounted(async () => {
4143
await appStore.prefetch();
44+
await menuStore.init();
4245
if (!appStore.isPublic) {
4346
// testSatisfies();
4447
websocketStore.start();

Diff for: frontend/src/api/language.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import axios from 'axios';
2+
import globalConfig from 'src/api/config';
3+
import { MenuData } from 'src/constants/constants';
4+
5+
export async function getMenuData(): Promise<MenuData | null> {
6+
try {
7+
const { data }: any = await axios.get(
8+
globalConfig.url + '/app-store/v1/applications/menutypes'
9+
);
10+
console.log('getMenuData');
11+
console.log(data);
12+
return data ? data : null;
13+
} catch (e) {
14+
console.log(e);
15+
return null;
16+
}
17+
}
18+
19+
export async function getAppMultiLanguage() {
20+
try {
21+
const { data }: any = await axios.get(
22+
globalConfig.url + '/app-store/v1/applications/i18ns'
23+
);
24+
console.log('getAppMultiLanguage');
25+
console.log(data);
26+
return data ? data : [];
27+
} catch (e) {
28+
console.log(e);
29+
return [];
30+
}
31+
}

Diff for: frontend/src/components/appcard/AppCard.vue

+10-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@
128128

129129
<div class="application_right column justify-center items-start">
130130
<div class="application_title_layout row justify-start items-baseline">
131-
<div class="application_title text-ink-1">{{ item.title }}</div>
131+
<div class="application_title text-ink-1">
132+
{{ getAppFieldI18n(item, APP_FIELD.TITLE) }}
133+
</div>
132134
<div v-if="version" class="application_version">
133135
{{ item.versionName }}
134136
</div>
@@ -142,7 +144,7 @@
142144
: 'application_content'
143145
"
144146
>
145-
{{ item.desc }}
147+
{{ getAppFieldI18n(item, APP_FIELD.DESCRIPTION) }}
146148
</div>
147149
<span
148150
v-if="!appStore.isPublic"
@@ -175,7 +177,12 @@
175177

176178
<script lang="ts" setup>
177179
import { onMounted, PropType, ref } from 'vue';
178-
import { AppStoreInfo, TRANSACTION_PAGE } from 'src/constants/constants';
180+
import {
181+
AppStoreInfo,
182+
getAppFieldI18n,
183+
APP_FIELD,
184+
TRANSACTION_PAGE
185+
} from 'src/constants/constants';
179186
import InstallButton from 'components/appcard/InstallButton.vue';
180187
import { useRouter } from 'vue-router';
181188
import { useAppStore } from 'src/stores/app';

Diff for: frontend/src/components/appcard/AppSmallCard.vue

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
<div
3535
class="app-small-card__right__text__title text-subtitle2 text-ink-1"
3636
>
37-
{{ item.title }}
37+
{{ getAppFieldI18n(item, APP_FIELD.TITLE) }}
3838
</div>
3939
<div class="app-small-card__right__text__content text-body3 text-ink-2">
40-
{{ item.desc }}
40+
{{ getAppFieldI18n(item, APP_FIELD.DESCRIPTION) }}
4141
</div>
4242
</div>
4343
<install-button v-if="!appStore.isPublic" :item="item" />
@@ -53,7 +53,12 @@
5353

5454
<script lang="ts" setup>
5555
import { onMounted, PropType, ref } from 'vue';
56-
import { AppStoreInfo, TRANSACTION_PAGE } from 'src/constants/constants';
56+
import {
57+
APP_FIELD,
58+
AppStoreInfo,
59+
getAppFieldI18n,
60+
TRANSACTION_PAGE
61+
} from 'src/constants/constants';
5762
import InstallButton from 'src/components/appcard/InstallButton.vue';
5863
import { useRouter } from 'vue-router';
5964
import { useAppStore } from 'src/stores/app';

Diff for: frontend/src/components/appcard/MyAppCard.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<div class="my-application-info column justify-start items-start">
4040
<div class="my-application-title-layout row justify-start items-center">
4141
<div class="my-application-title text-h6 text-ink-1">
42-
{{ item.title }}
42+
{{ getAppFieldI18n(item, APP_FIELD.TITLE) }}
4343
</div>
4444
<div
4545
v-if="version"
@@ -50,7 +50,7 @@
5050
</div>
5151

5252
<div class="my-application-content text-body3 text-ink-3">
53-
{{ item.desc }}
53+
{{ getAppFieldI18n(item, APP_FIELD.DESCRIPTION) }}
5454
</div>
5555

5656
<div
@@ -136,7 +136,9 @@
136136
<script lang="ts" setup>
137137
import { onMounted, PropType, ref } from 'vue';
138138
import {
139+
APP_FIELD,
139140
AppStoreInfo,
141+
getAppFieldI18n,
140142
SOURCE_TYPE,
141143
TRANSACTION_PAGE
142144
} from 'src/constants/constants';

Diff for: frontend/src/components/appintro/AppTitleBar.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</template>
2020
</q-img>
2121
<div class="q-ml-md text-h5 text-ink-1">
22-
{{ item.title }}
22+
{{ getAppFieldI18n(item, APP_FIELD.TITLE) }}
2323
</div>
2424
<div class="q-ml-sm text-h6 text-ink-1">{{ item.versionName }}</div>
2525
</div>
@@ -37,7 +37,11 @@
3737
<script lang="ts" setup>
3838
import InstallButton from 'components/appcard/InstallButton.vue';
3939
import { PropType } from 'vue';
40-
import { AppStoreInfo } from 'src/constants/constants';
40+
import {
41+
APP_FIELD,
42+
AppStoreInfo,
43+
getAppFieldI18n
44+
} from 'src/constants/constants';
4145
import { useRouter } from 'vue-router';
4246
import { useAppStore } from 'src/stores/app';
4347

Diff for: frontend/src/components/topic/AppStoreRecItem.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
<img :src="item ? item.icon : ''" class="application_top_logo" />
88
</div>
99
<div class="modal_application_text">
10-
<p class="modal_application_title">{{ item ? item.title : '' }}</p>
10+
<p class="modal_application_title">
11+
{{ item ? getAppFieldI18n(item, APP_FIELD.TITLE) : '' }}
12+
</p>
1113
<p class="modal_application_content">
12-
{{ item ? item.desc : '' }}
14+
{{ item ? getAppFieldI18n(item, APP_FIELD.DESCRIPTION) : '' }}
1315
</p>
1416
</div>
1517
<div class="modal_application_install">
@@ -46,7 +48,11 @@
4648
<script lang="ts" setup>
4749
import { PropType } from 'vue';
4850
import { useAppStore } from 'src/stores/app';
49-
import { AppStoreInfo } from 'src/constants/constants';
51+
import {
52+
APP_FIELD,
53+
AppStoreInfo,
54+
getAppFieldI18n
55+
} from 'src/constants/constants';
5056
5157
defineProps({
5258
item: {

Diff for: frontend/src/constants/constants.ts

+76
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CFG_TYPE } from 'src/constants/config';
2+
import { i18n } from 'src/boot/i18n';
23

34
export interface AppStoreInfo {
45
id: string;
@@ -207,6 +208,17 @@ export enum ROLE_TYPE {
207208
Admin = 'platform-admin'
208209
}
209210

211+
export interface MenuType {
212+
label: string;
213+
key: string;
214+
icon: string;
215+
}
216+
217+
export interface MenuData {
218+
menuTypes: MenuType[];
219+
i18n: any;
220+
}
221+
210222
export enum TRANSACTION_PAGE {
211223
App = 'App',
212224
List = 'List',
@@ -321,3 +333,67 @@ export enum PERMISSION_SYSDATA_GROUP {
321333
secret_infisical = 'secret.infisical',
322334
secret_vault = 'secret.vault'
323335
}
336+
337+
export enum APP_FIELD {
338+
TITLE = 'title',
339+
ENTRANCES_TITLE = 'entrances?_title',
340+
ENTRANCES_NAME = 'entrances?_name',
341+
DESCRIPTION = 'description',
342+
FULL_DESCRIPTION = 'fullDescription',
343+
UPGRADE_DESCRIPTION = 'upgradeDescription'
344+
}
345+
346+
export function getAppFieldI18n(
347+
app: AppStoreInfo,
348+
field: APP_FIELD,
349+
index = -1
350+
) {
351+
let key = '';
352+
switch (field) {
353+
case APP_FIELD.DESCRIPTION:
354+
case APP_FIELD.TITLE:
355+
case APP_FIELD.FULL_DESCRIPTION:
356+
case APP_FIELD.UPGRADE_DESCRIPTION:
357+
key = app.name + '_' + field;
358+
break;
359+
case APP_FIELD.ENTRANCES_NAME:
360+
case APP_FIELD.ENTRANCES_TITLE:
361+
if (index !== -1) {
362+
key =
363+
app.name +
364+
'_' +
365+
APP_FIELD.ENTRANCES_NAME.replace('?', index.toString());
366+
}
367+
break;
368+
}
369+
if (key) {
370+
const exist = i18n.global.te(key);
371+
// console.log(key, exist);
372+
if (exist) {
373+
return i18n.global.t(key);
374+
}
375+
}
376+
377+
switch (field) {
378+
case APP_FIELD.DESCRIPTION:
379+
return app.desc;
380+
case APP_FIELD.TITLE:
381+
case APP_FIELD.FULL_DESCRIPTION:
382+
case APP_FIELD.UPGRADE_DESCRIPTION:
383+
return app[field];
384+
case APP_FIELD.ENTRANCES_NAME:
385+
if (index !== -1) {
386+
const array1 = app.entrances;
387+
return array1[index].name;
388+
} else {
389+
return '';
390+
}
391+
case APP_FIELD.ENTRANCES_TITLE:
392+
if (index !== -1) {
393+
const array2 = app.entrances;
394+
return array2[index].title;
395+
} else {
396+
return '';
397+
}
398+
}
399+
}

Diff for: frontend/src/layouts/MainLayout.vue

+14-49
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
</template>
105105

106106
<script lang="ts" setup>
107-
import { onMounted, ref, watch } from 'vue';
107+
import { computed, onMounted, ref, watch } from 'vue';
108108
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router';
109109
import { useMenuStore } from 'src/stores/menu';
110110
import { MENU_TYPE, TRANSACTION_PAGE } from '../constants/constants';
@@ -113,54 +113,6 @@ import { useAppStore } from 'src/stores/app';
113113
import { useI18n } from 'vue-i18n';
114114
115115
const { t } = useI18n();
116-
const itemsRef = ref([
117-
{
118-
label: t('base.extensions'),
119-
key: 'Application',
120-
children: [
121-
{
122-
label: t('main.discover'),
123-
key: MENU_TYPE.Application.Home,
124-
icon: 'sym_r_radar'
125-
},
126-
{
127-
label: t('main.productivity'),
128-
key: MENU_TYPE.Application.Productivity,
129-
icon: 'sym_r_business_center'
130-
},
131-
{
132-
label: t('main.utilities'),
133-
key: MENU_TYPE.Application.Utilities,
134-
icon: 'sym_r_extension'
135-
},
136-
{
137-
label: t('main.entertainment'),
138-
key: MENU_TYPE.Application.Entertainment,
139-
icon: 'sym_r_interests'
140-
},
141-
{
142-
label: t('main.social_network'),
143-
key: MENU_TYPE.Application.SocialNetwork,
144-
icon: 'sym_r_group'
145-
},
146-
{
147-
label: t('main.blockchain'),
148-
key: MENU_TYPE.Application.Blockchain,
149-
icon: 'sym_r_stack'
150-
},
151-
{
152-
label: t('main.recommendation'),
153-
key: MENU_TYPE.Application.Recommendation,
154-
icon: 'sym_r_featured_play_list'
155-
}
156-
// {
157-
// label: t('main.models'),
158-
// key: MENU_TYPE.Application.Models,
159-
// icon: 'sym_r_neurology'
160-
// }
161-
]
162-
}
163-
]);
164116
const leftDrawerOpen = ref(false);
165117
const menuStore = useMenuStore();
166118
const Router = useRouter();
@@ -174,6 +126,19 @@ const appStore = useAppStore();
174126
const updateCount = ref(0);
175127
const showBarShadow = ref(false);
176128
129+
const itemsRef = computed(() => {
130+
if (menuStore.menuList.length === 0) {
131+
return [];
132+
}
133+
return [
134+
{
135+
label: t('base.extensions'),
136+
key: 'Application',
137+
children: menuStore.menuList
138+
}
139+
];
140+
});
141+
177142
const changeItemMenu = (data: any): void => {
178143
const type = data.key;
179144
menuStore.changeItemMenu(type);

0 commit comments

Comments
 (0)