mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-24 03:32:33 +01:00
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2015 Mike Fährmann
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
# published by the Free Software Foundation.
|
|
|
|
"""Conversion between language names and ISO 639-1 codes"""
|
|
|
|
|
|
def code_to_language(code, default="English"):
|
|
"""Map an ISO 639-1 language code to its actual name"""
|
|
return codes.get(code.lower(), default)
|
|
|
|
|
|
def language_to_code(lang, default="en"):
|
|
"""Map a language name to its ISO 639-1 code"""
|
|
lang = lang.capitalize()
|
|
for code, language in codes.items():
|
|
if language == lang:
|
|
return code
|
|
return default
|
|
|
|
|
|
codes = {
|
|
"ar": "Arabic",
|
|
"cs": "Czech",
|
|
"da": "Danish",
|
|
"de": "German",
|
|
"el": "Greek",
|
|
"en": "English",
|
|
"es": "Spanish",
|
|
"fi": "Finnish",
|
|
"fr": "French",
|
|
"he": "Hebrew",
|
|
"hu": "Hungarian",
|
|
"id": "Indonesian",
|
|
"it": "Italian",
|
|
"jp": "Japanese",
|
|
"ko": "Korean",
|
|
"ms": "Malay",
|
|
"nl": "Dutch",
|
|
"no": "Norwegian",
|
|
"pl": "Polish",
|
|
"pt": "Portuguese",
|
|
"ro": "Romanian",
|
|
"ru": "Russian",
|
|
"sv": "Swedish",
|
|
"th": "Thai",
|
|
"tr": "Turkish",
|
|
"vi": "Vietnamese",
|
|
"zh": "Chinese",
|
|
}
|