Skip to content

Commit 7ea3ed3

Browse files
committed
add handy languagesList function to get all languages for translation of side apps
1 parent 8a800f4 commit 7ea3ed3

File tree

9 files changed

+61
-10
lines changed

9 files changed

+61
-10
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/10-i18n.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,35 @@ app.get(`${ADMIN_BASE_URL}/api/translations/`,
536536
);
537537
```
538538
539+
### Get language names
540+
541+
Also you can use handy method to get language names in native and English form with emoji flags:
542+
543+
544+
```typescript title="./api.ts"
545+
const languages = await admin.getPluginByClassName<I18nPlugin>('I18nPlugin').languagesList();
546+
```
547+
548+
Response will look like this:
549+
550+
```
551+
"languages": [
552+
{
553+
"code": "en",
554+
"nameOnNative": "English",
555+
"nameEnglish": "English",
556+
"emojiFlag": "🇪🇳"
557+
},
558+
{
559+
"code": "uk",
560+
"nameOnNative": "Українська",
561+
"nameEnglish": "Ukrainian",
562+
"emojiFlag": "🇺🇰"
563+
},
564+
{
565+
"code": "ar",
566+
"nameOnNative": "العربية",
567+
"nameEnglish": "Arabic",
568+
"emojiFlag": "🇦🇷"
569+
},
570+
```

adminforth/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adminforth",
3-
"version": "1.5.12-next.1",
3+
"version": "1.5.12-next.2",
44
"description": "OpenSource Vue3 powered forth-generation admin panel",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

adminforth/plugins/i18n/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Added
1515
- support for pluralization in Backend `tr` function
16+
- add handy languagesList function to get all languages for translation of side apps
1617

1718
## [1.0.22]
1819

adminforth/plugins/i18n/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,22 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
796796
return translations;
797797
}
798798

799+
async languagesList(): Promise<{
800+
code: LanguageCode;
801+
nameOnNative: string;
802+
nameEnglish: string;
803+
emojiFlag: string;
804+
}[]> {
805+
return this.options.supportedLanguages.map((lang) => {
806+
return {
807+
code: lang as LanguageCode,
808+
nameOnNative: iso6391.getNativeName(lang),
809+
nameEnglish: iso6391.getName(lang),
810+
emojiFlag: lang.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
811+
};
812+
});
813+
}
814+
799815
async feedCategoryTranslations(messages: {
800816
en_string: string;
801817
source: string;

adminforth/plugins/i18n/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/plugins/i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adminforth/i18n",
3-
"version": "1.0.23-next.1",
3+
"version": "1.0.23-next.2",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"type": "module",

dev-demo/custom/Dash.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
55
<div class="max-w-md w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-5" v-if="data" >
66
<div>
7-
<h5 class="leading-none text-3xl font-bold text-gray-900 dark:text-white pb-2">{{ data.totalApartsString }}</h5>
7+
<h5 class="leading-none text-3xl font-bold text-gray-900 dark:text-white pb-2">{{ $t('Apartments') }}</h5>
88
<p class="text-base font-normal text-gray-500 dark:text-gray-400">{{ $t('Apartment last 7 days | Apartments last 7 days', data.totalAparts) }}</p>
99
</div>
1010
<BarChart
@@ -160,7 +160,7 @@
160160

161161
</div>
162162

163-
<div class="flex justify-center items-center p-80 bg-white">
163+
<!-- <div class="flex justify-center items-center p-80 bg-white">
164164
<div class="border border-indigo-600 p-5 w-80 h-80 min-w-80 min-h-80 flex items-center flex-col">
165165
<Select
166166
class="w-full"
@@ -204,7 +204,7 @@
204204
</template>
205205
</Select>
206206
</div>
207-
</div>
207+
</div> -->
208208
</div>
209209
</template>
210210

dev-demo/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const admin = new AdminForth({
100100
customComponentsDir: './custom',
101101
globalInjections: {
102102
userMenu: '@@/login2.vue',
103-
header: '@@/PropertyCost.vue',
103+
// header: '@@/PropertyCost.vue',
104104
},
105105
customPages:[{
106106
path : '/login2',
@@ -407,6 +407,8 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
407407
totalListedPrice,
408408
totalUnlistedPrice,
409409
listedVsUnlistedPriceByDays,
410+
411+
languages: await admin.getPluginByClassName<I18nPlugin>('I18nPlugin').languagesList()
410412
});
411413
}
412414
)

0 commit comments

Comments
 (0)