1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Add ro, gl, pa to languages, fix flag logic when countries doesn't exist in tag

This commit is contained in:
William Oldham 2024-01-03 23:14:26 +00:00
parent c114baf002
commit a1962aeecf
2 changed files with 12 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import es from "@/assets/locales/es.json";
import et from "@/assets/locales/et.json";
import fa from "@/assets/locales/fa.json";
import fr from "@/assets/locales/fr.json";
import gl from "@/assets/locales/gl.json";
import gu from "@/assets/locales/gu.json";
import he from "@/assets/locales/he.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 ne from "@/assets/locales/ne.json";
import nl from "@/assets/locales/nl.json";
import pa from "@/assets/locales/pa.json";
import pirate from "@/assets/locales/pirate.json";
import pl from "@/assets/locales/pl.json";
import ptbr from "@/assets/locales/pt-BR.json";
import ro from "@/assets/locales/ro.json";
import ru from "@/assets/locales/ru.json";
import sl from "@/assets/locales/sl.json";
import sv from "@/assets/locales/sv.json";
@ -72,5 +75,8 @@ export const locales = {
ta,
"zh-HANT": zhhant,
ru,
gl,
pa,
ro,
};
export type Locales = keyof typeof locales;

View file

@ -18,6 +18,7 @@ const countryPriority: Record<string, string> = {
zh: "cn",
ko: "kr",
ta: "lk",
gl: "es",
};
// list of iso639_1 Alpha-2 codes used as default languages
@ -52,6 +53,7 @@ const defaultLanguageCodes: string[] = [
"sl-SI",
"ta-LK",
"ru-RU",
"gl-ES",
];
export interface LocaleInfo {
@ -134,14 +136,17 @@ export function sortLangCodes(langCodes: string[]) {
export function getCountryCodeForLocale(locale: string): string | null {
let output: LanguageObj | null = null as any as LanguageObj;
const tag = getTag(locale, true);
if (!tag?.language?.Subtag) return null;
// this function isnt async, so its garuanteed to work like this
countryLanguages.getLanguage(tag.language.Subtag, (_err, lang) => {
if (lang) output = lang;
});
if (!output) return null;
if (output.countries.length === 0) return null;
const priority = countryPriority[output.iso639_1.toLowerCase()];
if (output.countries.length === 0) {
return priority ?? null;
}
if (priority) {
const priotizedCountry = output.countries.find(
(v) => v.code_2.toLowerCase() === priority,