mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Add ro, gl, pa to languages, fix flag logic when countries doesn't exist in tag
This commit is contained in:
parent
c114baf002
commit
a1962aeecf
2 changed files with 12 additions and 1 deletions
|
@ -9,6 +9,7 @@ import es from "@/assets/locales/es.json";
|
||||||
import et from "@/assets/locales/et.json";
|
import et from "@/assets/locales/et.json";
|
||||||
import fa from "@/assets/locales/fa.json";
|
import fa from "@/assets/locales/fa.json";
|
||||||
import fr from "@/assets/locales/fr.json";
|
import fr from "@/assets/locales/fr.json";
|
||||||
|
import gl from "@/assets/locales/gl.json";
|
||||||
import gu from "@/assets/locales/gu.json";
|
import gu from "@/assets/locales/gu.json";
|
||||||
import he from "@/assets/locales/he.json";
|
import he from "@/assets/locales/he.json";
|
||||||
import hi from "@/assets/locales/hi.json";
|
import hi from "@/assets/locales/hi.json";
|
||||||
|
@ -20,9 +21,11 @@ import lv from "@/assets/locales/lv.json";
|
||||||
import minion from "@/assets/locales/minion.json";
|
import minion from "@/assets/locales/minion.json";
|
||||||
import ne from "@/assets/locales/ne.json";
|
import ne from "@/assets/locales/ne.json";
|
||||||
import nl from "@/assets/locales/nl.json";
|
import nl from "@/assets/locales/nl.json";
|
||||||
|
import pa from "@/assets/locales/pa.json";
|
||||||
import pirate from "@/assets/locales/pirate.json";
|
import pirate from "@/assets/locales/pirate.json";
|
||||||
import pl from "@/assets/locales/pl.json";
|
import pl from "@/assets/locales/pl.json";
|
||||||
import ptbr from "@/assets/locales/pt-BR.json";
|
import ptbr from "@/assets/locales/pt-BR.json";
|
||||||
|
import ro from "@/assets/locales/ro.json";
|
||||||
import ru from "@/assets/locales/ru.json";
|
import ru from "@/assets/locales/ru.json";
|
||||||
import sl from "@/assets/locales/sl.json";
|
import sl from "@/assets/locales/sl.json";
|
||||||
import sv from "@/assets/locales/sv.json";
|
import sv from "@/assets/locales/sv.json";
|
||||||
|
@ -72,5 +75,8 @@ export const locales = {
|
||||||
ta,
|
ta,
|
||||||
"zh-HANT": zhhant,
|
"zh-HANT": zhhant,
|
||||||
ru,
|
ru,
|
||||||
|
gl,
|
||||||
|
pa,
|
||||||
|
ro,
|
||||||
};
|
};
|
||||||
export type Locales = keyof typeof locales;
|
export type Locales = keyof typeof locales;
|
||||||
|
|
|
@ -18,6 +18,7 @@ const countryPriority: Record<string, string> = {
|
||||||
zh: "cn",
|
zh: "cn",
|
||||||
ko: "kr",
|
ko: "kr",
|
||||||
ta: "lk",
|
ta: "lk",
|
||||||
|
gl: "es",
|
||||||
};
|
};
|
||||||
|
|
||||||
// list of iso639_1 Alpha-2 codes used as default languages
|
// list of iso639_1 Alpha-2 codes used as default languages
|
||||||
|
@ -52,6 +53,7 @@ const defaultLanguageCodes: string[] = [
|
||||||
"sl-SI",
|
"sl-SI",
|
||||||
"ta-LK",
|
"ta-LK",
|
||||||
"ru-RU",
|
"ru-RU",
|
||||||
|
"gl-ES",
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface LocaleInfo {
|
export interface LocaleInfo {
|
||||||
|
@ -134,14 +136,17 @@ export function sortLangCodes(langCodes: string[]) {
|
||||||
export function getCountryCodeForLocale(locale: string): string | null {
|
export function getCountryCodeForLocale(locale: string): string | null {
|
||||||
let output: LanguageObj | null = null as any as LanguageObj;
|
let output: LanguageObj | null = null as any as LanguageObj;
|
||||||
const tag = getTag(locale, true);
|
const tag = getTag(locale, true);
|
||||||
|
|
||||||
if (!tag?.language?.Subtag) return null;
|
if (!tag?.language?.Subtag) return null;
|
||||||
// this function isnt async, so its garuanteed to work like this
|
// this function isnt async, so its garuanteed to work like this
|
||||||
countryLanguages.getLanguage(tag.language.Subtag, (_err, lang) => {
|
countryLanguages.getLanguage(tag.language.Subtag, (_err, lang) => {
|
||||||
if (lang) output = lang;
|
if (lang) output = lang;
|
||||||
});
|
});
|
||||||
if (!output) return null;
|
if (!output) return null;
|
||||||
if (output.countries.length === 0) return null;
|
|
||||||
const priority = countryPriority[output.iso639_1.toLowerCase()];
|
const priority = countryPriority[output.iso639_1.toLowerCase()];
|
||||||
|
if (output.countries.length === 0) {
|
||||||
|
return priority ?? null;
|
||||||
|
}
|
||||||
if (priority) {
|
if (priority) {
|
||||||
const priotizedCountry = output.countries.find(
|
const priotizedCountry = output.countries.find(
|
||||||
(v) => v.code_2.toLowerCase() === priority,
|
(v) => v.code_2.toLowerCase() === priority,
|
||||||
|
|
Loading…
Reference in a new issue