Skip to content

Commit

Permalink
Add test for multiple directories with custom domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Leats committed Feb 17, 2020
1 parent d8fb73f commit 0bf48df
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Binary file added tests/renamed_translations/de/LC_MESSAGES/myapp.mo
Binary file not shown.
35 changes: 35 additions & 0 deletions tests/renamed_translations/de/LC_MESSAGES/myapp.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# German translations for PROJECT.
# Copyright (C) 2010 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2010-05-29 17:00+0200\n"
"PO-Revision-Date: 2010-05-30 12:56+0200\n"
"Last-Translator: Armin Ronacher <[email protected]>\n"
"Language-Team: de <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.5\n"

#: tests.py:94
#, python-format
msgid "Hello %(name)s!"
msgstr "Hallo %(name)s!"

#: tests.py:95 tests.py:96
#, python-format
msgid "%(num)s Apple"
msgid_plural "%(num)s Apples"
msgstr[0] "%(num)s Apfel"
msgstr[1] "%(num)s Äpfel"

#: tests.py:119
msgid "Yes"
msgstr "Ja"

33 changes: 33 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ def test_multiple_directories():
) == 'Hallo Peter!'


def test_multiple_directories_different_domain():
"""
Ensure we can load translations from multiple directories with a
custom domain.
"""
b = babel.Babel()
app = flask.Flask(__name__)

app.config.update({
'BABEL_TRANSLATION_DIRECTORIES': ';'.join((
'translations_different_domain',
'renamed_translations'
)),
'BABEL_DEFAULT_LOCALE': 'de_DE',
'BABEL_DOMAIN': 'myapp'
})

b.init_app(app)

with app.test_request_context():
translations = b.list_translations()

assert(len(translations) == 2)
assert(str(translations[0]) == 'de')
assert(str(translations[1]) == 'de')

assert gettext(
u'Hello %(name)s!',
name='Peter'
) == 'Hallo Peter!'
assert gettext(u'Good bye') == 'Auf Wiedersehen'


def test_different_domain():
"""
Ensure we can load translations from multiple directories.
Expand Down

0 comments on commit 0bf48df

Please sign in to comment.