mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
* Allow to combine language variant with region (fixes #3947, Z#23220951) This only affects babel-based formatting (currently: currencies and phone numbers), **not** Django-based formatting (currently: date and time formats). * Remove tests where I don'T actually know whats right * Fix lookup order
This commit is contained in:
@@ -68,9 +68,6 @@ def test_urlreplace_replace_parameter():
|
||||
|
||||
("en", Decimal("1023"), "JPY", "¥1,023"),
|
||||
|
||||
("pt-pt", Decimal("10.00"), "EUR", "10,00" + NBSP + "€"),
|
||||
("pt-br", Decimal("10.00"), "EUR", "€" + NBSP + "10,00"),
|
||||
|
||||
# unknown currency
|
||||
("de", Decimal("1234.56"), "FOO", "1.234,56" + NBSP + "FOO"),
|
||||
("de", Decimal("1234.567"), "FOO", "1.234,57" + NBSP + "FOO"),
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
import pytest
|
||||
from django.utils.translation import get_language
|
||||
|
||||
from pretix.base.i18n import get_language_without_region, language
|
||||
from pretix.base.i18n import (
|
||||
get_babel_locale, get_language_without_region, language,
|
||||
)
|
||||
from pretix.helpers.i18n import get_javascript_format, get_moment_locale
|
||||
|
||||
|
||||
@@ -42,22 +45,26 @@ def test_get_locale():
|
||||
assert get_moment_locale('en-CA') == 'en-ca'
|
||||
|
||||
|
||||
def test_set_region():
|
||||
with language('de'):
|
||||
assert get_language() == 'de'
|
||||
assert get_language_without_region() == 'de'
|
||||
with language('de', 'US'):
|
||||
assert get_language() == 'de-us'
|
||||
assert get_language_without_region() == 'de'
|
||||
with language('de', 'DE'):
|
||||
assert get_language() == 'de-de'
|
||||
assert get_language_without_region() == 'de'
|
||||
with language('de-informal', 'DE'):
|
||||
assert get_language() == 'de-informal'
|
||||
assert get_language_without_region() == 'de-informal'
|
||||
with language('pt', 'PT'):
|
||||
assert get_language() == 'pt-pt'
|
||||
assert get_language_without_region() == 'pt-pt'
|
||||
with language('pt-pt', 'BR'):
|
||||
assert get_language() == 'pt-pt'
|
||||
assert get_language_without_region() == 'pt-pt'
|
||||
@pytest.mark.parametrize(
|
||||
["lng_in", "region_in", "lng_out", "lng_without_region_out", "babel_out"],
|
||||
[
|
||||
("en", None, "en", "en", "en"),
|
||||
("en-us", None, "en-us", "en", "en_US"),
|
||||
("en", "US", "en-us", "en", "en_US"),
|
||||
("de", None, "de", "de", "de"),
|
||||
("de", "US", "de-us", "de", "de"),
|
||||
("de", "DE", "de-de", "de", "de_DE"),
|
||||
("de-informal", "DE", "de-informal", "de-informal", "de_DE"),
|
||||
("de-informal", "CH", "de-informal", "de-informal", "de_CH"),
|
||||
("pt-pt", "PT", "pt-pt", "pt-pt", "pt_PT"),
|
||||
("es", "MX", "es-mx", "es", "es_MX"),
|
||||
("es-419", "MX", "es-419", "es-419", "es_MX"),
|
||||
("zh-hans", "CN", "zh-hans", "zh-hans", "zh_Hans_CN"),
|
||||
("zh-hant", "TW", "zh-hant", "zh-hant", "zh_Hant_TW"),
|
||||
],
|
||||
)
|
||||
def test_set_region(lng_in, region_in, lng_out, lng_without_region_out, babel_out):
|
||||
with language(lng_in, region_in):
|
||||
assert get_language() == lng_out
|
||||
assert get_language_without_region() == lng_without_region_out
|
||||
assert str(get_babel_locale()) == babel_out
|
||||
|
||||
Reference in New Issue
Block a user