Commit fe6a6c7 1 parent 6875e37 commit fe6a6c7 Copy full SHA for fe6a6c7
File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 14
14
:value =" locale"
15
15
:title =" $t(`language.${locale}`)"
16
16
>
17
- {{ locale.toUpperCase( ) }}
17
+ {{ localeToFlag(locale ) }}
18
18
</b-form-select-option >
19
19
</b-form-select >
20
20
</b-input-group >
@@ -36,6 +36,26 @@ export default {
36
36
localStorage .setItem (' Locale' , value);
37
37
this .$i18n .locale = value;
38
38
},
39
+ localeToFlag : function (locale ) {
40
+ // Largely taken from wojtekmaj/country-code-to-flag-emoji. Adopted to be able to deal with locale codes as inputs.
41
+ // https://github.com/wojtekmaj/country-code-to-flag-emoji/blob/ff0d3d2dd9680b6f860d85fc9e713e93e396adb7/src/index.ts
42
+
43
+ let countryCode = locale .split (' -' ).pop ().toUpperCase ();
44
+ if (countryCode === ' EN' ) {
45
+ countryCode = ' US' ; // Sorry Britain!
46
+ } else if (countryCode === ' HI' ) {
47
+ countryCode = ' IN' ;
48
+ } else if (countryCode === ' JA' ) {
49
+ countryCode = ' JP' ;
50
+ } else if (countryCode === ' ZH' ) {
51
+ countryCode = ' CN' ;
52
+ }
53
+
54
+ return Array .from (countryCode)
55
+ .map ((letter ) => letter .toLowerCase ().charCodeAt (0 ) + 127365 )
56
+ .map ((charCode ) => String .fromCodePoint (charCode))
57
+ .join (' ' );
58
+ },
39
59
},
40
60
};
41
61
</script >
You can’t perform that action at this time.
0 commit comments