From f1ddcc02f5f9af8f1c05b840a993e38af6c6bf1e Mon Sep 17 00:00:00 2001 From: Adrian Castro <22133246+castdrian@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:07:53 +0100 Subject: [PATCH] fix: country code mapping --- .../components/player/CaptionsSelector.tsx | 12 +- apps/expo/src/components/player/utils.ts | 193 ++++++++++++++++++ pnpm-lock.yaml | 32 ++- 3 files changed, 225 insertions(+), 12 deletions(-) diff --git a/apps/expo/src/components/player/CaptionsSelector.tsx b/apps/expo/src/components/player/CaptionsSelector.tsx index 710e166..ffb4da6 100644 --- a/apps/expo/src/components/player/CaptionsSelector.tsx +++ b/apps/expo/src/components/player/CaptionsSelector.tsx @@ -1,3 +1,4 @@ +import type { LanguageCode } from "iso-639-1"; import type { ContentCaption } from "subsrt-ts/dist/types/handler"; import { useState } from "react"; import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"; @@ -14,7 +15,10 @@ import { FlagIcon } from "../FlagIcon"; import { MWButton } from "../ui/Button"; import { Controls } from "./Controls"; import { Settings } from "./settings/Sheet"; -import { getPrettyLanguageNameFromLocale } from "./utils"; +import { + getCountryCodeFromLanguage, + getPrettyLanguageNameFromLocale, +} from "./utils"; const parseCaption = async ( caption: Stream["captions"][0], @@ -128,7 +132,11 @@ export const CaptionsSelector = () => { borderRadius="$5" overflow="hidden" > - + } title={getPrettyLanguageNameFromLocale(caption.language) ?? ""} diff --git a/apps/expo/src/components/player/utils.ts b/apps/expo/src/components/player/utils.ts index 6126ff3..b9d929b 100644 --- a/apps/expo/src/components/player/utils.ts +++ b/apps/expo/src/components/player/utils.ts @@ -1,3 +1,4 @@ +import type { LanguageCode } from "iso-639-1"; import iso from "iso-639-1"; export const mapMillisecondsToTime = (milliseconds: number): string => { @@ -22,3 +23,195 @@ export const mapMillisecondsToTime = (milliseconds: number): string => { export function getPrettyLanguageNameFromLocale(locale: string): string | null { return iso.getName(locale); } + +export const getCountryCodeFromLanguage = ( + languageCode: LanguageCode, +): string => { + return languageToCountryMap[languageCode] || ""; +}; + +const languageToCountryMap: Record = { + en: "US", // English - United States + es: "ES", // Spanish - Spain + fr: "FR", // French - France + zh: "CN", // Mandarin - China + ar: "SA", // Arabic - Saudi Arabia + de: "DE", // German - Germany + ru: "RU", // Russian - Russia + pt: "PT", // Portuguese - Portugal + it: "IT", // Italian - Italy + ja: "JP", // Japanese - Japan + ko: "KR", // Korean - South Korea + hi: "IN", // Hindi - India + sv: "SE", // Swedish - Sweden + nl: "NL", // Dutch - Netherlands + pl: "PL", // Polish - Poland + tr: "TR", // Turkish - Turkey + el: "GR", // Greek - Greece + he: "IL", // Hebrew - Israel + vi: "VN", // Vietnamese - Vietnam + th: "TH", // Thai - Thailand + cs: "CZ", // Czech - Czech Republic + da: "DK", // Danish - Denmark + fi: "FI", // Finnish - Finland + hu: "HU", // Hungarian - Hungary + no: "NO", // Norwegian - Norway + ro: "RO", // Romanian - Romania + sk: "SK", // Slovak - Slovakia + sl: "SI", // Slovenian - Slovenia + uk: "UA", // Ukrainian - Ukraine + bg: "BG", // Bulgarian - Bulgaria + hr: "HR", // Croatian - Croatia + lt: "LT", // Lithuanian - Lithuania + lv: "LV", // Latvian - Latvia + et: "EE", // Estonian - Estonia + sr: "RS", // Serbian - Serbia + bs: "BA", // Bosnian - Bosnia and Herzegovina + mk: "MK", // Macedonian - North Macedonia + sq: "AL", // Albanian - Albania + mt: "MT", // Maltese - Malta + is: "IS", // Icelandic - Iceland + ga: "IE", // Irish - Ireland + cy: "GB", // Welsh - United Kingdom + eu: "ES", // Basque - Spain + ca: "ES", // Catalan - Spain + gl: "ES", // Galician - Spain + af: "ZA", // Afrikaans - South Africa + sw: "TZ", // Swahili - Tanzania + am: "ET", // Amharic - Ethiopia + so: "SO", // Somali - Somalia + ha: "NG", // Hausa - Nigeria + ig: "NG", // Igbo - Nigeria + yo: "NG", // Yoruba - Nigeria + rw: "RW", // Kinyarwanda - Rwanda + ny: "MW", // Chichewa - Malawi + mg: "MG", // Malagasy - Madagascar + ln: "CD", // Lingala - Democratic Republic of the Congo + tg: "TJ", // Tajik - Tajikistan + uz: "UZ", // Uzbek - Uzbekistan + tk: "TM", // Turkmen - Turkmenistan + ky: "KG", // Kyrgyz - Kyrgyzstan + mn: "MN", // Mongolian - Mongolia + ps: "AF", // Pashto - Afghanistan + ur: "PK", // Urdu - Pakistan + fa: "IR", // Persian (Farsi) - Iran + ku: "IQ", // Kurdish - Iraq + sd: "PK", // Sindhi - Pakistan + ne: "NP", // Nepali - Nepal + si: "LK", // Sinhala - Sri Lanka + km: "KH", // Khmer - Cambodia + lo: "LA", // Lao - Laos + my: "MM", // Burmese - Myanmar + ka: "GE", // Georgian - Georgia + hy: "AM", // Armenian - Armenia + az: "AZ", // Azerbaijani - Azerbaijan + bm: "ML", // Bambara - Mali + ff: "SN", // Fulfulde - Senegal + ti: "ER", // Tigrinya - Eritrea + xh: "ZA", // Xhosa - South Africa + zu: "ZA", // Zulu - South Africa + ms: "MY", // Malay - Malaysia + id: "ID", // Indonesian - Indonesia + jv: "ID", // Javanese - Indonesia + su: "ID", // Sundanese - Indonesia + tl: "PH", // Tagalog - Philippines + ml: "IN", // Malayalam - India + te: "IN", // Telugu - India + ta: "IN", // Tamil - India + mr: "IN", // Marathi - India + bn: "BD", // Bengali - Bangladesh + gu: "IN", // Gujarati - India + kn: "IN", // Kannada - India + or: "IN", // Oriya - India + pa: "IN", // Punjabi - India + aa: "ET", // Afar - Ethiopia + ab: "GE", // Abkhazian - Georgia + ae: "IR", // Avestan - Iran + ak: "GH", // Akan - Ghana + an: "ES", // Aragonese - Spain + as: "IN", // Assamese - India + av: "RU", // Avaric - Russia + ay: "BO", // Aymara - Bolivia + ba: "RU", // Bashkir - Russia + be: "BY", // Belarusian - Belarus + bi: "VU", // Bislama - Vanuatu + bo: "CN", // Tibetan - China + br: "FR", // Breton - France + ce: "RU", // Chechen - Russia + ch: "GU", // Chamorro - Guam + co: "FR", // Corsican - France + cr: "CA", // Cree - Canada + cu: "RU", // Church Slavic - Russia + cv: "RU", // Chuvash - Russia + dv: "MV", // Dhivehi - Maldives + dz: "BT", // Dzongkha - Bhutan + ee: "GH", // Ewe - Ghana + eo: "—", // Esperanto - International (Constructed Language) + fj: "FJ", // Fijian - Fiji + fo: "FO", // Faroese - Faroe Islands + fy: "NL", // Western Frisian - Netherlands + gd: "GB", // Scottish Gaelic - United Kingdom + gn: "PY", // Guarani - Paraguay + gv: "IM", // Manx - Isle of Man + ho: "PG", // Hiri Motu - Papua New Guinea + ht: "HT", // Haitian Creole - Haiti + hz: "NA", // Herero - Namibia + ia: "—", // Interlingua - International (Constructed Language) + ie: "—", // Interlingue - International (Constructed Language) + ii: "CN", // Sichuan Yi - China + ik: "US", // Inupiaq - United States + io: "—", // Ido - International (Constructed Language) + iu: "CA", // Inuktitut - Canada + kg: "CG", // Kongo - Congo + ki: "KE", // Kikuyu - Kenya + kj: "AO", // Kuanyama - Angola + kk: "KZ", // Kazakh - Kazakhstan + kl: "GL", // Kalaallisut - Greenland + kr: "NE", // Kanuri - Niger + ks: "IN", // Kashmiri - India + kv: "RU", // Komi - Russia + kw: "GB", // Cornish - United Kingdom + la: "VA", // Latin - Vatican City + lb: "LU", // Luxembourgish - Luxembourg + lg: "UG", // Ganda - Uganda + li: "NL", // Limburgish - Netherlands + lu: "CD", // Luba-Katanga - Democratic Republic of the Congo + mh: "MH", // Marshallese - Marshall Islands + mi: "NZ", // Maori - New Zealand + na: "NR", // Nauru - Nauru + nb: "NO", // Norwegian Bokmål - Norway + nd: "ZW", // North Ndebele - Zimbabwe + ng: "NA", // Ndonga - Namibia + nn: "NO", // Norwegian Nynorsk - Norway + nr: "ZA", // South Ndebele - South Africa + nv: "US", // Navajo - United States + oc: "FR", // Occitan - France + oj: "CA", // Ojibwe - Canada + om: "ET", // Oromo - Ethiopia + os: "GE", // Ossetian - Georgia + pi: "IN", // Pali - India + qu: "PE", // Quechua - Peru + rm: "CH", // Romansh - Switzerland + rn: "BI", // Rundi - Burundi + sa: "IN", // Sanskrit - India + sc: "IT", // Sardinian - Italy + se: "NO", // Northern Sami - Norway + sg: "CF", // Sango - Central African Republic + sm: "WS", // Samoan - Samoa + sn: "ZW", // Shona - Zimbabwe + ss: "SZ", // Swati - Eswatini + st: "LS", // Southern Sotho - Lesotho + tn: "BW", // Tswana - Botswana + to: "TO", // Tonga - Tonga + ts: "ZA", // Tsonga - South Africa + tt: "RU", // Tatar - Russia + tw: "GH", // Twi - Ghana + ty: "PF", // Tahitian - French Polynesia + ug: "CN", // Uyghur - China + ve: "ZA", // Venda - South Africa + vo: "—", // Volapük - International (Constructed Language) + wa: "BE", // Walloon - Belgium + wo: "SN", // Wolof - Senegal + yi: "—", // Yiddish - International (Primarily spoken among Jewish communities) + za: "CN", // Zhuang - China +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8eb340e..5ab0634 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5191,7 +5191,7 @@ packages: '@typescript-eslint/type-utils': 6.20.0(eslint@8.56.0)(typescript@5.3.3) '@typescript-eslint/utils': 6.20.0(eslint@8.56.0)(typescript@5.3.3) '@typescript-eslint/visitor-keys': 6.20.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) eslint: 8.56.0 graphemer: 1.4.0 ignore: 5.3.1 @@ -5217,7 +5217,7 @@ packages: '@typescript-eslint/types': 6.20.0 '@typescript-eslint/typescript-estree': 6.20.0(typescript@5.3.3) '@typescript-eslint/visitor-keys': 6.20.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) eslint: 8.56.0 typescript: 5.3.3 transitivePeerDependencies: @@ -5243,7 +5243,7 @@ packages: dependencies: '@typescript-eslint/typescript-estree': 6.20.0(typescript@5.3.3) '@typescript-eslint/utils': 6.20.0(eslint@8.56.0)(typescript@5.3.3) - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) eslint: 8.56.0 ts-api-utils: 1.0.3(typescript@5.3.3) typescript: 5.3.3 @@ -5389,7 +5389,7 @@ packages: resolution: {integrity: sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==} engines: {node: '>= 14'} dependencies: - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: true @@ -6753,6 +6753,18 @@ packages: dependencies: ms: 2.1.2 + /debug@4.3.4(supports-color@5.5.0): + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.2 + supports-color: 5.5.0 + /decamelize@1.2.0: resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} engines: {node: '>=0.10.0'} @@ -8227,7 +8239,7 @@ packages: dependencies: basic-ftp: 5.0.4 data-uri-to-buffer: 6.0.1 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) fs-extra: 8.1.0 transitivePeerDependencies: - supports-color @@ -8548,7 +8560,7 @@ packages: engines: {node: '>= 14'} dependencies: agent-base: 7.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: true @@ -8568,7 +8580,7 @@ packages: engines: {node: '>= 14'} dependencies: agent-base: 7.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: true @@ -10672,7 +10684,7 @@ packages: dependencies: '@tootallnate/quickjs-emscripten': 0.23.0 agent-base: 7.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) get-uri: 6.0.2 http-proxy-agent: 7.0.0 https-proxy-agent: 7.0.2 @@ -11119,7 +11131,7 @@ packages: engines: {node: '>= 14'} dependencies: agent-base: 7.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) http-proxy-agent: 7.0.0 https-proxy-agent: 7.0.2 lru-cache: 7.18.3 @@ -12243,7 +12255,7 @@ packages: engines: {node: '>= 14'} dependencies: agent-base: 7.1.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@5.5.0) socks: 2.7.1 transitivePeerDependencies: - supports-color