-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from python-babel/akx-one-ten
Akx one ten
- Loading branch information
Showing
17 changed files
with
163 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ dist | |
*.pyc | ||
django_babel.egg-info | ||
.tox | ||
htmlcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[django: **/templates/**.*] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf import settings | ||
|
||
from testproject import settings as testproject_settings | ||
|
||
|
||
def pytest_configure(): | ||
settings.configure(**vars(testproject_settings)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
import pkg_resources | ||
from django.core.management import call_command | ||
|
||
TEST_LOCALE_DIR = pkg_resources.resource_filename( | ||
'testproject', 'locale' | ||
) | ||
|
||
|
||
def test_babel_compilemessages(): | ||
call_command( | ||
'babel', | ||
'compilemessages', | ||
'-l', 'fi', | ||
) | ||
# Assert that the .mo file was created by attempting to delete it. | ||
os.unlink( | ||
os.path.join(TEST_LOCALE_DIR, 'fi', 'LC_MESSAGES', 'django.mo') | ||
) | ||
|
||
|
||
def test_babel_makemessages(): | ||
call_command( | ||
'babel', | ||
'makemessages', | ||
'-l', 'en', | ||
'-F', pkg_resources.resource_filename(__name__, 'babel.cfg'), | ||
) | ||
# See that the expected files get populated with the discovered message | ||
for path in [ | ||
os.path.join(TEST_LOCALE_DIR, 'django.pot'), | ||
os.path.join(TEST_LOCALE_DIR, 'en', 'LC_MESSAGES', 'django.po'), | ||
]: | ||
with open(path) as infp: | ||
assert '"This could be translated."' in infp.read() | ||
os.unlink(path) # clean up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -- encoding: utf-8 -- | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize('locale', ('en', 'fi', 'sv', 'pt-BR')) | ||
def test_babel_render(client, locale): | ||
""" | ||
Test the middleware and the rendery bits. | ||
""" | ||
response = client.get('/', HTTP_ACCEPT_LANGUAGE=locale) | ||
# "Parse" the key-value format | ||
lines = response.content.decode('utf-8').strip().splitlines() | ||
content = dict(kv.split('=', 1) for kv in lines) | ||
# See that we're rendering in the locale we expect | ||
assert content['language_code'] == locale.lower() | ||
# check that we could access `babel.Locale.language_name` | ||
assert content['language_name'] == { | ||
'en': 'English', | ||
'fi': 'suomi', | ||
'sv': 'svenska', | ||
'pt-BR': 'português', | ||
}[locale] | ||
# The rest are not really tested (aside from smoke tests) further; | ||
# the Babel test suite has taken care of that. |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# the header message is required to turn off the fuzzy bit for the catalog | ||
msgid "" | ||
msgstr "" | ||
|
||
#: tests/templates/test.txt:2 | ||
msgid "This could be translated." | ||
msgstr "Tämän voisi kääntää." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pkg_resources | ||
|
||
SECRET_KEY = 'x' | ||
USE_I18N = True | ||
ROOT_URLCONF = 'testproject.urls' | ||
INSTALLED_APPS = [ | ||
'django_babel', | ||
'testproject', | ||
] | ||
MIDDLEWARE_CLASSES = [ | ||
'django.middleware.locale.LocaleMiddleware', | ||
'django_babel.middleware.LocaleMiddleware', | ||
] | ||
TEMPLATES = [ | ||
{ | ||
'NAME': 'default', | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.i18n', | ||
], | ||
}, | ||
}, | ||
] | ||
LOCALE_PATHS = [ | ||
pkg_resources.resource_filename(__name__, 'locale'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% load i18n babel %} | ||
text={% trans "This could be translated." %} | ||
language_code={{ LANGUAGE_CODE }} | ||
language_name={{ locale.language_name }} | ||
date={{ date|datefmt }} | ||
datetime={{ date|datetimefmt }} | ||
time={{ date|timefmt }} | ||
number={{ number|numberfmt }} | ||
decimal={{ number|decimalfmt }} | ||
currency={{ number|currencyfmt:"EUR" }} | ||
percent={{ number|percentfmt }} | ||
scientificfmt={{ number|scientificfmt }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import time | ||
|
||
from django.conf.urls import url | ||
from django.shortcuts import render | ||
from django.utils.timezone import now | ||
|
||
|
||
def test_view(request): | ||
return render(request, 'test.txt', { | ||
'date': now(), | ||
'number': time.time(), | ||
'locale': request.locale, | ||
}) | ||
|
||
|
||
urlpatterns = [ | ||
url('^$', test_view), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters