| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
"""I18N and L10N support""" |
| 22 |
|
| 23 |
import gettext as _gettext |
| 24 |
import os |
| 25 |
import sys |
| 26 |
|
| 27 |
_null_translation = _gettext.NullTranslations() |
| 28 |
_translation = _null_translation |
| 29 |
|
| 30 |
|
| 31 |
def gettext(s): |
| 32 |
return _translation.gettext(s) |
| 33 |
|
| 34 |
|
| 35 |
def ngettext(s, p, n): |
| 36 |
return _translation.ngettext(s, p, n) |
| 37 |
|
| 38 |
|
| 39 |
def N_(s): |
| 40 |
return s |
| 41 |
|
| 42 |
|
| 43 |
def install(): |
| 44 |
global _translation |
| 45 |
if not os.environ.get('LANGUAGE'): |
| 46 |
from breezy import config |
| 47 |
lang = config.GlobalConfig().get_user_option('language') |
| 48 |
if lang: |
| 49 |
os.environ['LANGUAGE'] = lang |
| 50 |
if sys.platform == 'win32': |
| 51 |
_check_win32_locale() |
| 52 |
_translation = _gettext.translation('qbrz', localedir=_get_locale_dir(), fallback=True) |
| 53 |
|
| 54 |
|
| 55 |
def uninstall(): |
| 56 |
global _translation |
| 57 |
_translation = _null_translation |
| 58 |
|
| 59 |
|
| 60 |
def _get_locale_dir(): |
| 61 |
localedir = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..', 'locale') |
| 62 |
if sys.platform.startswith('linux'): |
| 63 |
if not os.access(localedir, os.R_OK | os.X_OK): |
| 64 |
localedir = '/usr/share/locale' |
| 65 |
return localedir |
| 66 |
|
| 67 |
|
| 68 |
def _check_win32_locale(): |
| 69 |
for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'): |
| 70 |
if os.environ.get(i): |
| 71 |
break |
| 72 |
else: |
| 73 |
lang = None |
| 74 |
import locale |
| 75 |
try: |
| 76 |
import ctypes |
| 77 |
except ImportError: |
| 78 |
|
| 79 |
lang = locale.getdefaultlocale()[0] |
| 80 |
else: |
| 81 |
|
| 82 |
lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID() |
| 83 |
lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID() |
| 84 |
if lcid_user != lcid_system: |
| 85 |
lcid = [lcid_user, lcid_system] |
| 86 |
else: |
| 87 |
lcid = [lcid_user] |
| 88 |
lang = [locale.windows_locale.get(i) for i in lcid] |
| 89 |
lang = ':'.join([i for i in lang if i]) |
| 90 |
|
| 91 |
if lang: |
| 92 |
os.environ['LANGUAGE'] = lang |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
if 0: |
| 97 |
|
| 98 |
N_('file') |
| 99 |
N_('directory') |
| 100 |
N_('symlink') |
| 101 |
|
| 102 |
N_('fixed') |
| 103 |
|
| 104 |
N_('View text file') |
| 105 |
N_('View image file') |
| 106 |
N_('View binary file') |
| 107 |
N_('View symlink') |
| 108 |
N_('View directory') |
| 109 |
|
| 110 |
N_("No changes selected to commit") |
| 111 |
N_("No changes selected to revert") |