Skip to content

Commit 6bb5839

Browse files
committed
fix flags emoji
1 parent def0a9b commit 6bb5839

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

adminforth/plugins/i18n/index.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import path from 'path';
66
import fs from 'fs-extra';
77
import chokidar from 'chokidar';
88
import { AsyncQueue } from '@sapphire/async-queue';
9-
10-
119
console.log = (...args) => {
1210
process.stdout.write(args.join(" ") + "\n");
1311
};
@@ -28,6 +26,22 @@ const SLAVIC_PLURAL_EXAMPLES = {
2826
ru: 'яблок | яблоко | яблока | яблок', // zero | singular | 2-4 | 5+
2927
};
3028

29+
const countryISO31661ByLangISO6391 = {
30+
en: 'us', // English → United States
31+
zh: 'cn', // Chinese → China
32+
hi: 'in', // Hindi → India
33+
ar: 'sa', // Arabic → Saudi Arabia
34+
ko: 'kr', // Korean → South Korea
35+
ja: 'jp', // Japanese → Japan
36+
uk: 'ua', // Ukrainian → Ukraine
37+
ur: 'pk', // Urdu → Pakistan
38+
};
39+
40+
function getCountryCodeFromLangCode(langCode) {
41+
return countryISO31661ByLangISO6391[langCode] || langCode;
42+
}
43+
44+
3145
interface ICachingAdapter {
3246
get(key: string): Promise<any>;
3347
set(key: string, value: any): Promise<void>;
@@ -757,6 +771,22 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
757771
return translations;
758772
}
759773

774+
async languagesList(): Promise<{
775+
code: LanguageCode;
776+
nameOnNative: string;
777+
nameEnglish: string;
778+
emojiFlag: string;
779+
}[]> {
780+
return this.options.supportedLanguages.map((lang) => {
781+
return {
782+
code: lang as LanguageCode,
783+
nameOnNative: iso6391.getNativeName(lang),
784+
nameEnglish: iso6391.getName(lang),
785+
emojiFlag: getCountryCodeFromLangCode(lang).toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
786+
};
787+
});
788+
}
789+
760790
async feedCategoryTranslations(messages: {
761791
en_string: string;
762792
source: string;

0 commit comments

Comments
 (0)