Пример #1
0
def _find_usable_locale():
    try:
        locales = subprocess.Popen(["locale", "-a"],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE).communicate()[0]
    except OSError:
        locales = ""
    if isinstance(locales, bytes):
        locales = locales.decode("ascii", "replace")

    usable_locales = []
    for line in locales.splitlines():
        locale = line.strip()
        locale_name = locale.lower().replace("-", "")

        # C.UTF-8 is the best option, if supported
        if locale_name == "c.utf8":
            return locale

        if locale_name.endswith(".utf8"):
            # Make a preference of english locales
            if locale.startswith("en_"):
                usable_locales.insert(0, locale)
            else:
                usable_locales.append(locale)

    if not usable_locales:
        raise FatalError(
            "Support for Unicode filenames is required, but no suitable UTF-8 locale was found on your system."
            " Please refer to the manual for your operating system for details on locale reconfiguration."
        )

    return usable_locales[0]
Пример #2
0
def _find_usable_locale():
    try:
        locales = subprocess.Popen(['locale', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
    except OSError:
        locales = ''
    if isinstance(locales, bytes):
        locales = locales.decode('ascii', 'replace')

    usable_locales = []
    for line in locales.splitlines():
        locale = line.strip()
        locale_name = locale.lower().replace('-', '')

        # C.UTF-8 is the best option, if supported
        if locale_name == 'c.utf8':
            return locale

        if locale_name.endswith('.utf8'):
            # Make a preference of english locales
            if locale.startswith('en_'):
                usable_locales.insert(0, locale)
            else:
                usable_locales.append(locale)

    if not usable_locales:
        raise FatalError(
            'Support for Unicode filenames is required, but no suitable UTF-8 locale was found on your system.'
            ' Please refer to the manual for your operating system for details on locale reconfiguration.')

    return usable_locales[0]
Пример #3
0
def update_po(template_path, locale):
    po_path = prep_po_path(template_path, locale)
    if os.path.exists(po_path):
        subprocess.check_call(['msgmerge',
                               '-N',
                               '-o',
                               po_path,
                               po_path,
                               template_path])
    else:
        subprocess.check_call(['msginit',
                               '--locale="%s"' % locale,
                               '--no-translator',
                               '-o',
                               po_path,
                               '-i',
                               template_path])
        subprocess.check_call(['iconv', '-t', 'utf-8', po_path])
        with open(po_path, 'r+') as po_file:
            text = po_file.read()
            po_file.seek(0)
            po_file.truncate()
            po_file.write(CHARSET_RE.sub(r'\1UTF-8\2', text))

    if locale.startswith('en'):
        # Copy msgid to msgstr for English locale
        subprocess.check_call(['msgen', '-o', po_path, po_path])

    remove_obsolete(template_path, po_path)
    return po_path
Пример #4
0
def _check_mswin_locale_reverse(locale):
    for (loc, msloc) in _LOCALE_NAMES.items():
        if msloc and locale == msloc[0]:
            return (loc, msloc[1])
    #US English is the outlier, all other English locales want real English:
    if locale.startswith('English') and locale != 'English_United States':
        return ('en_GB', '1252')
    return (None, None)
Пример #5
0
def _check_mswin_locale_reverse(locale):
    for (loc, msloc) in _LOCALE_NAMES.items():
        if msloc and locale == msloc[0]:
            return (loc, msloc[1])
    #US English is the outlier, all other English locales want real English:
    if locale.startswith('English') and locale != 'English_United States':
        return ('en_GB', '1252')
    return (None, None)
Пример #6
0
def update_po(template_path, locale):
    po_path = prep_po_path(template_path, locale)
    if os.path.exists(po_path):
        subprocess.check_call(
            ['msgmerge', '-N', '-o', po_path, po_path, template_path])
    else:
        subprocess.check_call([
            'msginit',
            '--locale="%s"' % locale, '--no-translator', '-o', po_path, '-i',
            template_path
        ])
        subprocess.check_call(['iconv', '-t', 'utf-8', po_path])
        with open(po_path, 'r+') as po_file:
            text = po_file.read()
            po_file.seek(0)
            po_file.truncate()
            po_file.write(CHARSET_RE.sub(r'\1UTF-8\2', text))

    if locale.startswith('en'):
        # Copy msgid to msgstr for English locale
        subprocess.check_call(['msgen', '-o', po_path, po_path])

    remove_obsolete(template_path, po_path)
    return po_path
Пример #7
0
if not Path(  # Check if languages file exists
        resourcesFolder +
        "/langs.json").is_file():  # Initial miner executable section
    url = "https://raw.githubusercontent.com/revoxhere/duino-coin/master/Resources/PC_Miner_langs.json"
    r = requests.get(url)
    with open(resourcesFolder + "/langs.json", "wb") as f:
        f.write(r.content)

with open(f"{resourcesFolder}/langs.json", "r", encoding="utf8") as lang_file:
    lang_file = json.load(lang_file)

if not Path(  # Check if miner is configured, if it isn't, autodetect language
        resourcesFolder + "/Miner_config.cfg").is_file():
    locale = locale.getdefaultlocale()[0]
    if locale.startswith("es"):
        lang = "spanish"

    elif locale.startswith("pl"):
        lang = "polish"

    elif locale.startswith("fr"):
        lang = "french"

    elif locale.startswith("ru"):
        lang = "russian"

    elif locale.startswith("de"):
        lang = "german"

    else: