Пример #1
0
def load_legal_doc(doc_name, locale):
    """
    Return the HTML content of a legal doc in the requested locale.

    :param doc_name: name of the legal doc folder
    :param locale: preferred language version of the doc
    :return: dict containing string content of the file (or None), a boolean
             value indicating whether the file is localized into the specified
             locale, and a dict of all available locales for that document
    """
    # for file access convert bedrock locale to legal-docs equivalent
    if locale in BEDROCK_LOCALES_TO_LEGAL_DOCS:
        locale = BEDROCK_LOCALES_TO_LEGAL_DOCS[locale]

    source_dir = path.join(LEGAL_DOCS_PATH, doc_name)
    source_file = path.join(source_dir, locale + '.md')
    output = StringIO.StringIO()
    locales = [
        f.replace('.md', '') for f in listdir(source_dir) if f.endswith('.md')
    ]
    # convert legal-docs locales to bedrock equivalents
    locales = [LEGAL_DOCS_LOCALES_TO_BEDROCK.get(l, l) for l in locales]
    # filter out non-production locales and convert to dict with names
    translations = get_translations_native_names(locales)
    localized = locale != settings.LANGUAGE_CODE

    # it's possible the legal-docs repo changed the filename to match our locale.
    # this makes it work for mapped locales even if the map becomes superfluous.
    if not path.exists(
            source_file) and locale in LEGAL_DOCS_LOCALES_TO_BEDROCK:
        locale = LEGAL_DOCS_LOCALES_TO_BEDROCK[locale]
        source_file = path.join(source_dir, locale + '.md')

    if not path.exists(source_file):
        source_file = path.join(LEGAL_DOCS_PATH, doc_name, 'en-US.md')
        localized = False

    try:
        # Parse the Markdown file
        md.markdownFromFile(input=source_file,
                            output=output,
                            extensions=[
                                'attr_list', 'headerid',
                                OutlineExtension((('wrapper_cls', ''), ))
                            ])
        content = output.getvalue().decode('utf8')
    except IOError:
        content = None
        localized = False
    finally:
        output.close()

    return {
        'content': content,
        'localized': localized,
        'translations': translations,
    }
Пример #2
0
def load_legal_doc(doc_name, locale):
    """
    Return the HTML content of a legal doc in the requested locale.

    :param doc_name: name of the legal doc folder
    :param locale: preferred language version of the doc
    :return: dict containing string content of the file (or None), a boolean
             value indicating whether the file is localized into the specified
             locale, and a dict of all available locales for that document
    """
    # for file access convert bedrock locale to legal-docs equivalent
    if locale in BEDROCK_LOCALES_TO_LEGAL_DOCS:
        locale = BEDROCK_LOCALES_TO_LEGAL_DOCS[locale]

    source_dir = path.join(LEGAL_DOCS_PATH, doc_name)
    source_file = path.join(source_dir, locale + '.md')
    output = StringIO.StringIO()
    locales = [f.replace('.md', '') for f in listdir(source_dir) if f.endswith('.md')]
    # convert legal-docs locales to bedrock equivalents
    locales = [LEGAL_DOCS_LOCALES_TO_BEDROCK.get(l, l) for l in locales]
    # filter out non-production locales and convert to dict with names
    translations = get_translations_native_names(locales)
    localized = locale != settings.LANGUAGE_CODE

    # it's possible the legal-docs repo changed the filename to match our locale.
    # this makes it work for mapped locales even if the map becomes superfluous.
    if not path.exists(source_file) and locale in LEGAL_DOCS_LOCALES_TO_BEDROCK:
        locale = LEGAL_DOCS_LOCALES_TO_BEDROCK[locale]
        source_file = path.join(source_dir, locale + '.md')

    if not path.exists(source_file):
        source_file = path.join(LEGAL_DOCS_PATH, doc_name, 'en-US.md')
        localized = False

    try:
        # Parse the Markdown file
        md.markdownFromFile(input=source_file, output=output,
                            extensions=['attr_list', 'headerid',
                                        OutlineExtension((('wrapper_cls', ''),))])
        content = output.getvalue().decode('utf8')
    except IOError:
        content = None
        localized = False
    finally:
        output.close()

    return {
        'content': content,
        'localized': localized,
        'translations': translations,
    }
Пример #3
0
def firefox_features_translate(request):

    to_translate_langs = ['af', 'sq', 'am-et', 'ar', 'hy-AM', 'az', 'eu', 'be', 'bn', 'bs',
                          'bg', 'ca', 'zh-CN', 'hr', 'cs', 'da', 'nl', 'en-US', 'eo', 'et',
                          'fi', 'fr', 'fy-NL', 'gl', 'ka', 'de', 'el', 'gu', 'ha', 'he', 'hi',
                          'hu', 'is', 'ig', 'id', 'ga', 'it', 'ja', 'kn', 'kk', 'km', 'rw',
                          'ko', 'ku', 'lo', 'la', 'lv', 'lt', 'mk', 'mg', 'ms', 'ml', 'mi',
                          'mr', 'mn', 'my', 'ne-NP', 'nb-NO', 'or', 'fa', 'pl', 'pt-PT', 'pa',
                          'ro', 'ru', 'gd', 'sr', 'st', 'si', 'sk', 'sl', 'es', 'sw', 'sv-SE',
                          'ta', 'tt-RU', 'te', 'th', 'tr', 'uk', 'ur', 'uz', 'vi', 'cy', 'xh',
                          'yo', 'zu']

    names = get_translations_native_names(sorted(to_translate_langs))

    context = {'context_test': names}

    template_name = 'firefox/features/translate.html'

    return l10n_utils.render(request, template_name, context,
                             ftl_files=['firefox/features/shared', 'firefox/features/translate'])