Ejemplo n.º 1
0
def test_normalize_language(mock_lang_storage, lang_en_us, lang_en_gb):
    res = normalize_language('en_US')

    assert res == lang_en_us
    assert res.code == 'en-us'

    res = normalize_language('EN-GB')

    assert res == lang_en_gb
    assert res.code == 'en-gb'

    res = normalize_language('en')

    assert res == lang_en_us
    assert res.code == lang_en_us.code
Ejemplo n.º 2
0
def validate_languges_input(languages, project_languages):
    selected_langs = set()
    for l in languages:
        selected_langs.add(normalize_language(l))

    not_valid = selected_langs.difference(set(project_languages))
    if not_valid:
        raise ArgumentTypeError('Selected languages not configured in project as dest languages: `{}`'
                                .format(','.join((str(i) for i in not_valid))))

    return list(selected_langs)
Ejemplo n.º 3
0
def validate_path(curdir, path, lang):
    """
    Validate path
        Make path relative to curdir
        Validate language string
        Create TranslationFile object
    :param str curdir: FilePath.
    :param str path: Raw file path
    :param str lang: Raw language string
    :rtype: qordoba.sources.TranslationFile
    """
    lang = normalize_language(lang)
    if not isinstance(path, TranslationFile):
        if os.path.isabs(path):
            path = os.path.relpath(path, curdir)
        path = TranslationFile(path, lang, curdir)

    return path
Ejemplo n.º 4
0
def test_normalize_language_error(mock_lang_storage):
    with pytest.raises(LanguageNotFound):
        normalize_language('ed-ed')

    with pytest.raises(LanguageNotFound):
        normalize_language('')