def test_translate(self): l10n = get_l10n() assert fluent.translate(l10n, "fluent-title") == "Title in German" # does variable substition via kwargs assert fluent.translate(l10n, "fluent-page-desc", lang="Dudeish") == "Description in Dudeish" # fall back to 'en' string assert fluent.translate(l10n, "brand-new-string") == "New string not yet available in all languages" # will use fallback string assert fluent.translate(l10n, "brand-new-string", fallback="fluent-title") == "Title in German"
def test_translate_term_fallback(self): """Test that translation will get the brand term from english""" # English works l10n = get_l10n(["en-US", "en"]) assert fluent.translate(l10n, "fluent-brand") == "English Fluent" # German has no brands.ftl at all so falls back to English l10n = get_l10n(["de", "en"]) assert fluent.translate(l10n, "fluent-brand") == "German Fluent" # French has a translation for the term l10n = get_l10n(["fr", "en"]) assert fluent.translate(l10n, "fluent-brand") == "French Couramment"
def test_translate_term_fallback(self): """Test that translation will get the brand term from english""" # English works l10n = get_l10n(['en-US', 'en']) assert fluent.translate(l10n, 'fluent-brand') == 'English Fluent' # German has no brands.ftl at all so falls back to English l10n = get_l10n(['de', 'en']) assert fluent.translate(l10n, 'fluent-brand') == 'German Fluent' # French has a translation for the term l10n = get_l10n(['fr', 'en']) assert fluent.translate(l10n, 'fluent-brand') == 'French Couramment'
def test_translate(self): l10n = get_l10n() assert fluent.translate(l10n, 'fluent-title') == 'Title in German' # does variable substition via kwargs assert fluent.translate(l10n, 'fluent-page-desc', lang='Dudeish') == \ 'Description in Dudeish' # fall back to 'en' string assert fluent.translate(l10n, 'brand-new-string') == \ 'New string not yet available in all languages' # will use fallback string assert fluent.translate(l10n, 'brand-new-string', fallback='fluent-title') == 'Title in German'
def ftl(ctx, message_id, fallback=None, **kwargs): """Return the translated string. :param ctx: the context from the template (automatically included) :param str message_id: the ID of the message :param str fallback: the ID of a message to use if message_id is not translated :param kwargs: the other kwargs are passed to the translation as variables :return: the translated string marked as safe Usage example:: <p>{{ ftl('greeting', name='The Dude') }} """ return jinja2.Markup( fluent.translate(ctx["fluent_l10n"], message_id, fallback, **kwargs))