Exemple #1
0
def load_strings(default="en"):
    global strings
    p = helpers.get_platform()

    # find locale dir
    if p == 'Linux' or p == 'Tails':
        locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale')
    elif p == 'Darwin':
        locale_dir = os.path.join(helpers.osx_resources_dir, 'locale')
    else:
        locale_dir = os.path.join(
            os.path.dirname(helpers.get_onionshare_dir()), 'locale')

    # load all translations
    translated = {}
    for filename in os.listdir(locale_dir):
        abs_filename = os.path.join(locale_dir, filename)
        lang, ext = os.path.splitext(filename)
        if abs_filename.endswith('.json'):
            translated[lang] = json.loads(open(abs_filename).read())

    strings = translated[default]
    lc, enc = locale.getdefaultlocale()
    if lc:
        lang = lc[:2]
        if lang in translated:
            # if a string doesn't exist, fallback to English
            for key in translated[default]:
                if key in translated[lang]:
                    strings[key] = translated[lang][key]
def load_strings(default="en"):
    global strings

    # find locale dir
    if platform.system() == 'Linux':
        locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale')
    else:
        locale_dir = os.path.join(os.path.dirname(helpers.get_onionshare_dir()), 'locale')

    # load all translations
    translated = {}
    for filename in os.listdir(locale_dir):
        abs_filename = os.path.join(locale_dir, filename)
        lang, ext = os.path.splitext(filename)
        if abs_filename.endswith('.json'):
            translated[lang] = json.loads(open(abs_filename).read())

    strings = translated[default]
    lc, enc = locale.getdefaultlocale()
    if lc:
        lang = lc[:2]
        if lang in translated:
            # if a string doesn't exist, fallback to English
            for key in translated[default]:
                if key in translated[lang]:
                    strings[key] = translated[lang][key]
Exemple #3
0
def load_strings(default="en"):
    """
    Loads translated strings and fallback to English
    if the translation does not exist.
    """
    global strings
    p = helpers.get_platform()

    # find locale dir
    if p == 'Linux':
        locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale')
    elif p == 'Darwin':
        locale_dir = os.path.join(helpers.osx_resources_dir, 'locale')
    else:
        locale_dir = os.path.join(os.path.dirname(helpers.get_onionshare_dir()), 'locale')

    # load all translations
    translations = {}
    for filename in os.listdir(locale_dir):
        abs_filename = os.path.join(locale_dir, filename)
        lang, ext = os.path.splitext(filename)
        if abs_filename.endswith('.json'):
            translations[lang] = json.loads(open(abs_filename).read())

    strings = translations[default]
    lc, enc = locale.getdefaultlocale()
    if lc:
        lang = lc[:2]
        if lang in translations:
            # if a string doesn't exist, fallback to English
            for key in translations[default]:
                if key in translations[lang]:
                    strings[key] = translations[lang][key]
Exemple #4
0
def load_strings(default="en"):
    global strings
    translated = json.loads(open('{0}/strings.json'.format(helpers.get_onionshare_dir())).read())
    strings = translated[default]
    lc, enc = locale.getdefaultlocale()
    if lc:
        lang = lc[:2]
        if lang in translated:
            # if a string doesn't exist, fallback to English
            for key in translated[default]:
                if key in translated[lang]:
                    strings[key] = translated[lang][key]
Exemple #5
0
def index(slug_candidate):
    if not helpers.constant_time_compare(slug.encode('ascii'), slug_candidate.encode('ascii')):
        abort(404)

    add_request(REQUEST_LOAD, request.path)
    return render_template_string(
        open('{0}/index.html'.format(helpers.get_onionshare_dir())).read(),
        slug=slug,
        file_info=file_info,
        filename=os.path.basename(zip_filename).decode("utf-8"),
        filesize=zip_filesize,
        filesize_human=helpers.human_readable_filesize(zip_filesize),
        strings=strings.strings
    )
Exemple #6
0
def index(slug_candidate):
    if not helpers.constant_time_compare(slug.encode('ascii'),
                                         slug_candidate.encode('ascii')):
        abort(404)

    add_request(REQUEST_LOAD, request.path)
    return render_template_string(
        open('{0}/index.html'.format(helpers.get_onionshare_dir())).read(),
        slug=slug,
        file_info=file_info,
        filename=os.path.basename(zip_filename).decode("utf-8"),
        filesize=zip_filesize,
        filesize_human=helpers.human_readable_filesize(zip_filesize),
        strings=strings.strings)
Exemple #7
0
def page_not_found(e):
    add_request(REQUEST_OTHER, request.path)
    return render_template_string(open('{0}/404.html'.format(helpers.get_onionshare_dir())).read())
Exemple #8
0
def page_not_found(e):
    add_request(REQUEST_OTHER, request.path)
    return render_template_string(
        open('{0}/404.html'.format(helpers.get_onionshare_dir())).read())