navigator.language list of all languages

前端 未结 5 1305
无人共我
无人共我 2021-02-12 05:02

Where i can see the list of languages and their codes?

I want to compare languages and auto-select required language in template.

Are they cross-browser equal?

相关标签:
5条回答
  • 2021-02-12 05:06

    Or if you need an enum of languages without locale in typescript or plaint object in javascript for copy-paste purposes

    export enum ISOLanguages {
      AF = 'af',
      SQ = 'sq',
      AR = 'ar',
      EU = 'eu',
      BG = 'bg',
      BE = 'be',
      CA = 'ca',
      ZH = 'zh',
      HR = 'hr',
      CS = 'cs',
      DA = 'da',
      NL = 'nl',
      EN = 'en',
      ET = 'et',
      FO = 'fo',
      FA = 'fa',
      FI = 'fi',
      FR = 'fr',
      GD = 'gd',
      DE = 'de',
      EL = 'el',
      HE = 'he',
      HI = 'hi',
      HU = 'hu',
      IS = 'is',
      ID = 'id',
      IT = 'it',
      JA = 'ja',
      KO = 'ko',
      LV = 'lv',
      LT = 'lt',
      MK = 'mk',
      MT = 'mt',
      NO = 'no',
      PL = 'pl',
      PT = 'pt',
      RM = 'rm',
      RO = 'ro',
      RU = 'ru',
      SZ = 'sz',
      SR = 'sr',
      SK = 'sk',
      SL = 'sl',
      SB = 'sb',
      ES = 'es',
      SX = 'sx',
      SV = 'sv',
      TH = 'th',
      TS = 'ts',
      TN = 'tn',
      TR = 'tr',
      UK = 'uk',
      UR = 'ur',
      VE = 've',
      VI = 'vi',
      XH = 'xh',
      JI = 'ji',
      ZU = 'zu',
    }
    
    0 讨论(0)
  • 2021-02-12 05:18

    For copy and pasting purposes:

    ["af", "sq", "ar-SA", "ar-IQ", "ar-EG", "ar-LY", "ar-DZ", "ar-MA", "ar-TN", "ar-OM",
     "ar-YE", "ar-SY", "ar-JO", "ar-LB", "ar-KW", "ar-AE", "ar-BH", "ar-QA", "eu", "bg",
     "be", "ca", "zh-TW", "zh-CN", "zh-HK", "zh-SG", "hr", "cs", "da", "nl", "nl-BE", "en",
     "en-US", "en-EG", "en-AU", "en-GB", "en-CA", "en-NZ", "en-IE", "en-ZA", "en-JM",
     "en-BZ", "en-TT", "et", "fo", "fa", "fi", "fr", "fr-BE", "fr-CA", "fr-CH", "fr-LU",
     "gd", "gd-IE", "de", "de-CH", "de-AT", "de-LU", "de-LI", "el", "he", "hi", "hu", 
     "is", "id", "it", "it-CH", "ja", "ko", "lv", "lt", "mk", "mt", "no", "pl",
     "pt-BR", "pt", "rm", "ro", "ro-MO", "ru", "ru-MI", "sz", "sr", "sk", "sl", "sb",
     "es", "es-AR", "es-GT", "es-CR", "es-PA", "es-DO", "es-MX", "es-VE", "es-CO", 
     "es-PE", "es-EC", "es-CL", "es-UY", "es-PY", "es-BO", "es-SV", "es-HN", "es-NI", 
     "es-PR", "sx", "sv", "sv-FI", "th", "ts", "tn", "tr", "uk", "ur", "ve", "vi", "xh",
     "ji", "zu"];
    
    0 讨论(0)
  • 2021-02-12 05:19

    This list is defined by the ISO : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

    0 讨论(0)
  • 2021-02-12 05:21

    In some case, navigator.language can return something like "sr-Latn-RS"

    According to MDN (https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language) navigator.language can return every value valid in BCP-47: https://tools.ietf.org/html/bcp47

    0 讨论(0)
  • 2021-02-12 05:26

    If anyone also needs the name of the language for user selection (created from here using query selector so it's accurate):

    [
        ['Abkhazian', 'ab'],
        ['Afar', 'aa'],
        ['Afrikaans', 'af'],
        ['Akan', 'ak'],
        ['Albanian', 'sq'],
        ['Amharic', 'am'],
        ['Arabic', 'ar'],
        ['Aragonese', 'an'],
        ['Armenian', 'hy'],
        ['Assamese', 'as'],
        ['Avaric', 'av'],
        ['Avestan', 'ae'],
        ['Aymara', 'ay'],
        ['Azerbaijani', 'az'],
        ['Bambara', 'bm'],
        ['Bashkir', 'ba'],
        ['Basque', 'eu'],
        ['Belarusian', 'be'],
        ['Bengali (Bangla)', 'bn'],
        ['Bihari', 'bh'],
        ['Bislama', 'bi'],
        ['Bosnian', 'bs'],
        ['Breton', 'br'],
        ['Bulgarian', 'bg'],
        ['Burmese', 'my'],
        ['Catalan', 'ca'],
        ['Chamorro', 'ch'],
        ['Chechen', 'ce'],
        ['Chichewa, Chewa, Nyanja', 'ny'],
        ['Chinese', 'zh'],
        ['Chinese (Simplified)', 'zh-Hans'],
        ['Chinese (Traditional)', 'zh-Hant'],
        ['Chuvash', 'cv'],
        ['Cornish', 'kw'],
        ['Corsican', 'co'],
        ['Cree', 'cr'],
        ['Croatian', 'hr'],
        ['Czech', 'cs'],
        ['Danish', 'da'],
        ['Divehi, Dhivehi, Maldivian', 'dv'],
        ['Dutch', 'nl'],
        ['Dzongkha', 'dz'],
        ['English', 'en'],
        ['Esperanto', 'eo'],
        ['Estonian', 'et'],
        ['Ewe', 'ee'],
        ['Faroese', 'fo'],
        ['Fijian', 'fj'],
        ['Finnish', 'fi'],
        ['French', 'fr'],
        ['Fula, Fulah, Pulaar, Pular', 'ff'],
        ['Galician', 'gl'],
        ['Gaelic (Scottish)', 'gd'],
        ['Gaelic (Manx)', 'gv'],
        ['Georgian', 'ka'],
        ['German', 'de'],
        ['Greek', 'el'],
        ['Greenlandic', 'kl'],
        ['Guarani', 'gn'],
        ['Gujarati', 'gu'],
        ['Haitian Creole', 'ht'],
        ['Hausa', 'ha'],
        ['Hebrew', 'he'],
        ['Herero', 'hz'],
        ['Hindi', 'hi'],
        ['Hiri Motu', 'ho'],
        ['Hungarian', 'hu'],
        ['Icelandic', 'is'],
        ['Ido', 'io'],
        ['Igbo', 'ig'],
        ['Indonesian', 'id, in'],
        ['Interlingua', 'ia'],
        ['Interlingue', 'ie'],
        ['Inuktitut', 'iu'],
        ['Inupiak', 'ik'],
        ['Irish', 'ga'],
        ['Italian', 'it'],
        ['Japanese', 'ja'],
        ['Javanese', 'jv'],
        ['Kalaallisut, Greenlandic', 'kl'],
        ['Kannada', 'kn'],
        ['Kanuri', 'kr'],
        ['Kashmiri', 'ks'],
        ['Kazakh', 'kk'],
        ['Khmer', 'km'],
        ['Kikuyu', 'ki'],
        ['Kinyarwanda (Rwanda)', 'rw'],
        ['Kirundi', 'rn'],
        ['Kyrgyz', 'ky'],
        ['Komi', 'kv'],
        ['Kongo', 'kg'],
        ['Korean', 'ko'],
        ['Kurdish', 'ku'],
        ['Kwanyama', 'kj'],
        ['Lao', 'lo'],
        ['Latin', 'la'],
        ['Latvian (Lettish)', 'lv'],
        ['Limburgish ( Limburger)', 'li'],
        ['Lingala', 'ln'],
        ['Lithuanian', 'lt'],
        ['Luga-Katanga', 'lu'],
        ['Luganda, Ganda', 'lg'],
        ['Luxembourgish', 'lb'],
        ['Manx', 'gv'],
        ['Macedonian', 'mk'],
        ['Malagasy', 'mg'],
        ['Malay', 'ms'],
        ['Malayalam', 'ml'],
        ['Maltese', 'mt'],
        ['Maori', 'mi'],
        ['Marathi', 'mr'],
        ['Marshallese', 'mh'],
        ['Moldavian', 'mo'],
        ['Mongolian', 'mn'],
        ['Nauru', 'na'],
        ['Navajo', 'nv'],
        ['Ndonga', 'ng'],
        ['Northern Ndebele', 'nd'],
        ['Nepali', 'ne'],
        ['Norwegian', 'no'],
        ['Norwegian bokmål', 'nb'],
        ['Norwegian nynorsk', 'nn'],
        ['Nuosu', 'ii'],
        ['Occitan', 'oc'],
        ['Ojibwe', 'oj'],
        ['Old Church Slavonic, Old Bulgarian', 'cu'],
        ['Oriya', 'or'],
        ['Oromo (Afaan Oromo)', 'om'],
        ['Ossetian', 'os'],
        ['Pāli', 'pi'],
        ['Pashto, Pushto', 'ps'],
        ['Persian (Farsi)', 'fa'],
        ['Polish', 'pl'],
        ['Portuguese', 'pt'],
        ['Punjabi (Eastern)', 'pa'],
        ['Quechua', 'qu'],
        ['Romansh', 'rm'],
        ['Romanian', 'ro'],
        ['Russian', 'ru'],
        ['Sami', 'se'],
        ['Samoan', 'sm'],
        ['Sango', 'sg'],
        ['Sanskrit', 'sa'],
        ['Serbian', 'sr'],
        ['Serbo-Croatian', 'sh'],
        ['Sesotho', 'st'],
        ['Setswana', 'tn'],
        ['Shona', 'sn'],
        ['Sichuan Yi', 'ii'],
        ['Sindhi', 'sd'],
        ['Sinhalese', 'si'],
        ['Siswati', 'ss'],
        ['Slovak', 'sk'],
        ['Slovenian', 'sl'],
        ['Somali', 'so'],
        ['Southern Ndebele', 'nr'],
        ['Spanish', 'es'],
        ['Sundanese', 'su'],
        ['Swahili (Kiswahili)', 'sw'],
        ['Swati', 'ss'],
        ['Swedish', 'sv'],
        ['Tagalog', 'tl'],
        ['Tahitian', 'ty'],
        ['Tajik', 'tg'],
        ['Tamil', 'ta'],
        ['Tatar', 'tt'],
        ['Telugu', 'te'],
        ['Thai', 'th'],
        ['Tibetan', 'bo'],
        ['Tigrinya', 'ti'],
        ['Tonga', 'to'],
        ['Tsonga', 'ts'],
        ['Turkish', 'tr'],
        ['Turkmen', 'tk'],
        ['Twi', 'tw'],
        ['Uyghur', 'ug'],
        ['Ukrainian', 'uk'],
        ['Urdu', 'ur'],
        ['Uzbek', 'uz'],
        ['Venda', 've'],
        ['Vietnamese', 'vi'],
        ['Volapük', 'vo'],
        ['Wallon', 'wa'],
        ['Welsh', 'cy'],
        ['Wolof', 'wo'],
        ['Western Frisian', 'fy'],
        ['Xhosa', 'xh'],
        ['Yiddish', 'yi, ji'],
        ['Yoruba', 'yo'],
        ['Zhuang, Chuang', 'za'],
        ['Zulu', 'zu'],
    ]
    
    0 讨论(0)
提交回复
热议问题