i18n.py (2754B)
1 #!/usr/bin/env python 2 # 3 # Electrum - lightweight Bitcoin client 4 # Copyright (C) 2012 thomasv@gitorious 5 # 6 # Permission is hereby granted, free of charge, to any person 7 # obtaining a copy of this software and associated documentation files 8 # (the "Software"), to deal in the Software without restriction, 9 # including without limitation the rights to use, copy, modify, merge, 10 # publish, distribute, sublicense, and/or sell copies of the Software, 11 # and to permit persons to whom the Software is furnished to do so, 12 # subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be 15 # included in all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 # SOFTWARE. 25 import os 26 27 import gettext 28 29 LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') 30 language = gettext.translation('electrum', LOCALE_DIR, fallback=True) 31 32 33 # note: f-strings cannot be translated! see https://stackoverflow.com/q/49797658 34 # So this does not work: _(f"My name: {name}") 35 # instead use .format: _("My name: {}").format(name) 36 def _(x): 37 global language 38 return language.gettext(x) 39 40 41 def set_language(x): 42 global language 43 if x: 44 language = gettext.translation('electrum', LOCALE_DIR, fallback=True, languages=[x]) 45 46 47 languages = { 48 '': _('Default'), 49 'ar_SA': _('Arabic'), 50 'bg_BG': _('Bulgarian'), 51 'cs_CZ': _('Czech'), 52 'da_DK': _('Danish'), 53 'de_DE': _('German'), 54 'el_GR': _('Greek'), 55 'eo_UY': _('Esperanto'), 56 'en_UK': _('English'), 57 'es_ES': _('Spanish'), 58 'fa_IR': _('Persian'), 59 'fr_FR': _('French'), 60 'hu_HU': _('Hungarian'), 61 'hy_AM': _('Armenian'), 62 'id_ID': _('Indonesian'), 63 'it_IT': _('Italian'), 64 'ja_JP': _('Japanese'), 65 'ky_KG': _('Kyrgyz'), 66 'lv_LV': _('Latvian'), 67 'nb_NO': _('Norwegian Bokmal'), 68 'nl_NL': _('Dutch'), 69 'pl_PL': _('Polish'), 70 'pt_BR': _('Brasilian'), 71 'pt_PT': _('Portuguese'), 72 'ro_RO': _('Romanian'), 73 'ru_RU': _('Russian'), 74 'sk_SK': _('Slovak'), 75 'sl_SI': _('Slovenian'), 76 'sv_SE': _('Swedish'), 77 'ta_IN': _('Tamil'), 78 'th_TH': _('Thai'), 79 'tr_TR': _('Turkish'), 80 'uk_UA': _('Ukrainian'), 81 'vi_VN': _('Vietnamese'), 82 'zh_CN': _('Chinese Simplified'), 83 'zh_TW': _('Chinese Traditional') 84 }