From 3f63e9b68ee261766cabbd99ce227e553b700489 Mon Sep 17 00:00:00 2001 From: Changaco Date: Wed, 21 Nov 2018 14:39:57 +0100 Subject: [PATCH] create a `liberapay.i18n` submodule --- .babel_extract | 6 +- Makefile | 2 +- cli/po-tools.py | 31 ++++++ error.spt | 2 +- liberapay/billing/payday.py | 2 +- liberapay/exceptions.py | 2 +- liberapay/i18n/__init__.py | 0 liberapay/{utils/i18n.py => i18n/base.py} | 105 +----------------- liberapay/{utils => i18n}/currencies.py | 4 +- liberapay/i18n/extract.py | 44 ++++++++ liberapay/i18n/plural_rules.py | 27 +++++ liberapay/main.py | 9 +- liberapay/models/_mixin_team.py | 2 +- liberapay/models/participant.py | 5 +- liberapay/payin/common.py | 2 +- liberapay/payin/paypal.py | 2 +- liberapay/payin/stripe.py | 2 +- liberapay/testing/__init__.py | 2 +- liberapay/testing/mangopay.py | 2 +- liberapay/utils/__init__.py | 2 +- liberapay/utils/fake_data.py | 2 +- liberapay/utils/history.py | 2 +- liberapay/wireup.py | 10 +- tests/py/test_currencies.py | 2 +- tests/py/test_i18n.py | 2 +- tests/py/test_participant.py | 2 +- tests/py/test_payday.py | 2 +- tests/py/test_sign_in.py | 2 +- tests/py/test_take.py | 4 +- www/%username/charts.json.spt | 2 +- www/%username/edit/statement.spt | 2 +- .../wallet/payin/bankwire/%back_to.spt | 2 +- www/%username/wallet/payin/card/%back_to.spt | 2 +- .../payin/direct-debit/%exchange_id.spt | 2 +- www/%username/widgets/%type.spt | 2 +- www/about/legal.spt | 2 +- www/about/stats.spt | 2 +- www/for/%name/edit.spt | 2 +- www/for/new.spt | 2 +- www/index.html.spt | 2 +- www/migrate.spt | 2 +- www/search.spt | 2 +- 42 files changed, 157 insertions(+), 150 deletions(-) create mode 100644 cli/po-tools.py create mode 100644 liberapay/i18n/__init__.py rename liberapay/{utils/i18n.py => i18n/base.py} (82%) rename liberapay/{utils => i18n}/currencies.py (98%) create mode 100644 liberapay/i18n/extract.py create mode 100644 liberapay/i18n/plural_rules.py diff --git a/.babel_extract b/.babel_extract index ebf25cc22..15bce3d3b 100644 --- a/.babel_extract +++ b/.babel_extract @@ -1,7 +1,7 @@ [extractors] -jinja2_custom = liberapay.utils.i18n:extract_jinja2_custom -python_custom = liberapay.utils.i18n:extract_python_custom -spt = liberapay.utils.i18n:extract_spt +jinja2_custom = liberapay.i18n.extract:extract_jinja2_custom +python_custom = liberapay.i18n.extract:extract_python_custom +spt = liberapay.i18n.extract:extract_spt [python_custom: **.py] [jinja2_custom: **.html] diff --git a/Makefile b/Makefile index 134a1f52d..2d83ca9e4 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ pytest-profiling: env _i18n_extract: env @PYTHONPATH=. $(env_bin)/pybabel extract -F .babel_extract --no-wrap -o i18n/core.pot --sort-by-file _i18n_warning.html emails liberapay templates www *.spt - @PYTHONPATH=. $(env_bin)/python liberapay/utils/i18n.py po-reflag i18n/core.pot + @PYTHONPATH=. $(env_bin)/python cli/po-tools.py reflag i18n/core.pot @for f in i18n/*/*.po; do \ $(env_bin)/pybabel update -i i18n/core.pot -l $$(basename -s '.po' "$$f") -o "$$f" --ignore-obsolete --no-fuzzy-matching --no-wrap; \ done diff --git a/cli/po-tools.py b/cli/po-tools.py new file mode 100644 index 000000000..988cf41f5 --- /dev/null +++ b/cli/po-tools.py @@ -0,0 +1,31 @@ +from __future__ import print_function, unicode_literals + +import sys + +from babel.messages.pofile import read_po, write_po + + +if sys.argv[1] == 'reflag': + # This adds the `python-brace-format` flag to messages that contain braces + # https://github.com/python-babel/babel/issues/333 + pot_path = sys.argv[2] + print('rewriting PO template file', pot_path) + # read PO file + with open(pot_path, 'rb') as pot: + catalog = read_po(pot) + # tweak message flags + for m in catalog: + msg = m.id + contains_brace = any( + '{' in s for s in (msg if isinstance(msg, tuple) else (msg,)) + ) + if contains_brace: + m.flags.add('python-brace-format') + m.flags.discard('python-format') + # write back + with open(pot_path, 'wb') as pot: + write_po(pot, catalog, width=0) + +else: + print("unknown command") + raise SystemExit(1) diff --git a/error.spt b/error.spt index ba21f3289..63bcd06da 100644 --- a/error.spt +++ b/error.spt @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera from pando.http import status_strings from liberapay.exceptions import LazyResponse -from liberapay.utils.i18n import HTTP_ERRORS +from liberapay.i18n.base import HTTP_ERRORS [----------------------------------------] diff --git a/liberapay/billing/payday.py b/liberapay/billing/payday.py index f0d71208c..aee227a73 100644 --- a/liberapay/billing/payday.py +++ b/liberapay/billing/payday.py @@ -20,9 +20,9 @@ import requests from liberapay import constants from liberapay.billing.transactions import Money, transfer from liberapay.exceptions import NegativeBalance +from liberapay.i18n.currencies import MoneyBasket from liberapay.models.participant import Participant from liberapay.utils import NS, group_by -from liberapay.utils.currencies import MoneyBasket from liberapay.website import website diff --git a/liberapay/exceptions.py b/liberapay/exceptions.py index ba630863c..057c5de68 100644 --- a/liberapay/exceptions.py +++ b/liberapay/exceptions.py @@ -24,7 +24,7 @@ class LazyResponse(Response): def render_in_english(self): f = self.lazy_body fake_state = {} - from liberapay.utils.i18n import LOCALE_EN, add_helpers_to_context + from liberapay.i18n.base import LOCALE_EN, add_helpers_to_context add_helpers_to_context(fake_state, LOCALE_EN) return f(*resolve_dependencies(f, fake_state).as_args) diff --git a/liberapay/i18n/__init__.py b/liberapay/i18n/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/liberapay/utils/i18n.py b/liberapay/i18n/base.py similarity index 82% rename from liberapay/utils/i18n.py rename to liberapay/i18n/base.py index dfe174130..177c0a599 100644 --- a/liberapay/utils/i18n.py +++ b/liberapay/i18n/base.py @@ -4,29 +4,23 @@ from __future__ import print_function, unicode_literals from collections import namedtuple, OrderedDict from datetime import date, datetime, timedelta from decimal import Decimal, InvalidOperation -from hashlib import md5 -from io import BytesIO -import re from unicodedata import combining, normalize from six import text_type -from aspen.simplates.pagination import parse_specline, split_and_escape import babel.core from babel.dates import format_date, format_datetime, format_timedelta -from babel.messages.extract import extract_python from babel.messages.pofile import Catalog from babel.numbers import ( format_currency, format_decimal, format_number, format_percent, ) -import jinja2.ext from markupsafe import Markup from pando.utils import utcnow -from liberapay.constants import CURRENCIES, D_MAX -from liberapay.exceptions import AmbiguousNumber, InvalidNumber -from liberapay.utils.currencies import Money, MoneyBasket -from liberapay.website import website +from ..constants import CURRENCIES, D_MAX +from ..exceptions import AmbiguousNumber, InvalidNumber +from ..website import website +from .currencies import Money, MoneyBasket def LegacyMoney(o): @@ -267,30 +261,6 @@ HTTP_ERRORS = { del _ -ternary_re = re.compile(r'^(.+?) *\? *(.+?) *: *(.+?)$') -and_re = re.compile(r' *&& *') -or_re = re.compile(r' *\|\| *') - - -def strip_parentheses(s): - s = s.strip() - if s[:1] == '(' and s[-1:] == ')': - s = s[1:-1].strip() - return s - - -def ternary_sub(m): - g1, g2, g3 = m.groups() - return '%s if %s else %s' % (g2, g1, ternary_re.sub(ternary_sub, strip_parentheses(g3))) - - -def get_function_from_rule(rule): - rule = ternary_re.sub(ternary_sub, strip_parentheses(rule)) - rule = and_re.sub(' and ', rule) - rule = or_re.sub(' or ', rule) - return eval('lambda n: ' + rule, {'__builtins__': {}}) - - def _decode(o): return o.decode('ascii') if isinstance(o, bytes) else o @@ -501,70 +471,3 @@ def add_currency_to_state(request, user): return {'currency': user.main_currency} else: return {'currency': CURRENCIES_MAP.get(request.country) or 'EUR'} - - -def extract_custom(extractor, *args, **kw): - for match in extractor(*args, **kw): - msg = match[2] - if isinstance(msg, tuple) and msg[0] == '': - unused = "" % md5(msg[1]).hexdigest() - msg = (unused, msg[1], msg[2]) - match = (match[0], match[1], msg, match[3]) - yield match - - -def extract_jinja2_custom(*args, **kw): - return extract_custom(jinja2.ext.babel_extract, *args, **kw) - - -def extract_python_custom(*args, **kw): - return extract_custom(extract_python, *args, **kw) - - -def extract_spt(fileobj, *args, **kw): - pages = list(split_and_escape(fileobj.read().decode('utf8'))) - npages = len(pages) - for i, page in enumerate(pages, 1): - f = BytesIO(b'\n' * page.offset + page.content.encode('utf8')) - content_type, renderer = parse_specline(page.header) - extractor = None - python_page = i < 3 and i < npages and not page.header - json_page = renderer == 'json_dump' - if python_page or json_page: - extractor = extract_python_custom - else: - extractor = extract_jinja2_custom - if extractor: - for match in extractor(f, *args, **kw): - yield match - - -if __name__ == '__main__': - import sys - - from babel.messages.pofile import read_po, write_po - - if sys.argv[1] == 'po-reflag': - # This adds the `python-brace-format` flag to messages that contain braces - # https://github.com/python-babel/babel/issues/333 - pot_path = sys.argv[2] - print('rewriting PO template file', pot_path) - # read PO file - with open(pot_path, 'rb') as pot: - catalog = read_po(pot) - # tweak message flags - for m in catalog: - msg = m.id - contains_brace = any( - '{' in s for s in (msg if isinstance(msg, tuple) else (msg,)) - ) - if contains_brace: - m.flags.add('python-brace-format') - m.flags.discard('python-format') - # write back - with open(pot_path, 'wb') as pot: - write_po(pot, catalog, width=0) - - else: - print("unknown command") - raise SystemExit(1) diff --git a/liberapay/utils/currencies.py b/liberapay/i18n/currencies.py similarity index 98% rename from liberapay/utils/currencies.py rename to liberapay/i18n/currencies.py index 5a657a930..c31a09ba8 100644 --- a/liberapay/utils/currencies.py +++ b/liberapay/i18n/currencies.py @@ -10,8 +10,8 @@ from mangopay.utils import Money import requests import xmltodict -from liberapay.constants import CURRENCIES, D_CENT, D_ZERO -from liberapay.website import website +from ..constants import CURRENCIES, D_CENT, D_ZERO +from ..website import website def _convert(self, c, rounding=ROUND_HALF_UP): diff --git a/liberapay/i18n/extract.py b/liberapay/i18n/extract.py new file mode 100644 index 000000000..fcd054da1 --- /dev/null +++ b/liberapay/i18n/extract.py @@ -0,0 +1,44 @@ +from __future__ import division, print_function, unicode_literals + +from hashlib import md5 +from io import BytesIO + +from aspen.simplates.pagination import parse_specline, split_and_escape +from babel.messages.extract import extract_python +import jinja2.ext + + +def extract_custom(extractor, *args, **kw): + for match in extractor(*args, **kw): + msg = match[2] + if isinstance(msg, tuple) and msg[0] == '': + unused = "" % md5(msg[1]).hexdigest() + msg = (unused, msg[1], msg[2]) + match = (match[0], match[1], msg, match[3]) + yield match + + +def extract_jinja2_custom(*args, **kw): + return extract_custom(jinja2.ext.babel_extract, *args, **kw) + + +def extract_python_custom(*args, **kw): + return extract_custom(extract_python, *args, **kw) + + +def extract_spt(fileobj, *args, **kw): + pages = list(split_and_escape(fileobj.read().decode('utf8'))) + npages = len(pages) + for i, page in enumerate(pages, 1): + f = BytesIO(b'\n' * page.offset + page.content.encode('utf8')) + content_type, renderer = parse_specline(page.header) + extractor = None + python_page = i < 3 and i < npages and not page.header + json_page = renderer == 'json_dump' + if python_page or json_page: + extractor = extract_python_custom + else: + extractor = extract_jinja2_custom + if extractor: + for match in extractor(f, *args, **kw): + yield match diff --git a/liberapay/i18n/plural_rules.py b/liberapay/i18n/plural_rules.py new file mode 100644 index 000000000..3fcb7905d --- /dev/null +++ b/liberapay/i18n/plural_rules.py @@ -0,0 +1,27 @@ +from __future__ import print_function, unicode_literals + +import re + + +ternary_re = re.compile(r'^(.+?) *\? *(.+?) *: *(.+?)$') +and_re = re.compile(r' *&& *') +or_re = re.compile(r' *\|\| *') + + +def strip_parentheses(s): + s = s.strip() + if s[:1] == '(' and s[-1:] == ')': + s = s[1:-1].strip() + return s + + +def ternary_sub(m): + g1, g2, g3 = m.groups() + return '%s if %s else %s' % (g2, g1, ternary_re.sub(ternary_sub, strip_parentheses(g3))) + + +def get_function_from_rule(rule): + rule = ternary_re.sub(ternary_sub, strip_parentheses(rule)) + rule = and_re.sub(' and ', rule) + rule = or_re.sub(' or ', rule) + return eval('lambda n: ' + rule, {'__builtins__': {}}) diff --git a/liberapay/main.py b/liberapay/main.py index 924987cf4..1889cf593 100644 --- a/liberapay/main.py +++ b/liberapay/main.py @@ -21,15 +21,16 @@ from liberapay import utils, wireup from liberapay.billing.payday import Payday, create_payday_issue from liberapay.cron import Cron, Daily, Weekly from liberapay.exceptions import PayinMethodIsUnavailable, PayinsAreDisabled +from liberapay.i18n.base import add_currency_to_state, set_up_i18n +from liberapay.i18n.currencies import Money, MoneyBasket, fetch_currency_exchange_rates from liberapay.models.account_elsewhere import refetch_elsewhere_data from liberapay.models.community import Community from liberapay.models.participant import Participant, clean_up_closed_accounts from liberapay.models.repository import refetch_repos from liberapay.security import authentication, csrf, set_default_security_headers from liberapay.utils import ( - b64decode_s, b64encode_s, erase_cookie, http_caching, i18n, set_cookie, urlquote, + b64decode_s, b64encode_s, erase_cookie, http_caching, set_cookie, urlquote, ) -from liberapay.utils.currencies import Money, MoneyBasket, fetch_currency_exchange_rates from liberapay.utils.emails import handle_email_bounces from liberapay.utils.state_chain import ( attach_environ_to_request, create_response_object, reject_requests_bypassing_proxy, @@ -141,12 +142,12 @@ algorithm.functions = [ canonize, set_default_security_headers, - i18n.set_up_i18n, + set_up_i18n, insert_constants, authentication.start_user_as_anon, csrf.reject_forgeries, authentication.authenticate_user_if_possible, - i18n.add_currency_to_state, + add_currency_to_state, _dispatch_path_to_filesystem, algorithm['handle_dispatch_exception'], diff --git a/liberapay/models/_mixin_team.py b/liberapay/models/_mixin_team.py index b6f23a9b2..785281721 100644 --- a/liberapay/models/_mixin_team.py +++ b/liberapay/models/_mixin_team.py @@ -10,8 +10,8 @@ from statistics import median import mangopay from liberapay.constants import TAKE_THROTTLING_THRESHOLD +from liberapay.i18n.currencies import Money, MoneyBasket from liberapay.utils import NS, group_by -from liberapay.utils.currencies import Money, MoneyBasket class MemberLimitReached(Exception): pass diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py index d6d7731f4..4d0ebeedc 100644 --- a/liberapay/models/participant.py +++ b/liberapay/models/participant.py @@ -65,15 +65,16 @@ from liberapay.exceptions import ( ValueContainsForbiddenCharacters, VerificationEmailAlreadySent, ) +from liberapay.i18n import base as i18n +from liberapay.i18n.currencies import Money, MoneyBasket from liberapay.models._mixin_team import MixinTeam from liberapay.models.account_elsewhere import AccountElsewhere from liberapay.models.community import Community from liberapay.security.crypto import constant_time_compare from liberapay.utils import ( NS, deserialize, erase_cookie, serialize, set_cookie, urlquote, - emails, i18n, markdown, + emails, markdown, ) -from liberapay.utils.currencies import Money, MoneyBasket from liberapay.utils.emails import check_email_blacklist, normalize_email_address from liberapay.website import website diff --git a/liberapay/payin/common.py b/liberapay/payin/common.py index 5182f0c61..02c495f1c 100644 --- a/liberapay/payin/common.py +++ b/liberapay/payin/common.py @@ -4,8 +4,8 @@ from ..exceptions import ( AccountSuspended, MissingPaymentAccount, RecipientAccountSuspended, NoSelfTipping, ) +from ..i18n.currencies import Money from ..models.participant import Participant -from ..utils.currencies import Money def prepare_payin(db, payer, amount, route): diff --git a/liberapay/payin/paypal.py b/liberapay/payin/paypal.py index 8638a1cf7..152c20d9b 100644 --- a/liberapay/payin/paypal.py +++ b/liberapay/payin/paypal.py @@ -5,7 +5,7 @@ import logging import requests from ..exceptions import PaymentError -from ..utils.currencies import Money +from ..i18n.currencies import Money from ..website import website from .common import update_payin, update_payin_transfer diff --git a/liberapay/payin/stripe.py b/liberapay/payin/stripe.py index a8780a1cf..3b0d0077d 100644 --- a/liberapay/payin/stripe.py +++ b/liberapay/payin/stripe.py @@ -9,8 +9,8 @@ from six import text_type import stripe import stripe.error +from ..i18n.currencies import Money from ..models.exchange_route import ExchangeRoute -from ..utils.currencies import Money from ..website import website from .common import update_payin, update_payin_transfer diff --git a/liberapay/testing/__init__.py b/liberapay/testing/__init__.py index c90d51f2b..0c9fd0fe5 100644 --- a/liberapay/testing/__init__.py +++ b/liberapay/testing/__init__.py @@ -19,6 +19,7 @@ from liberapay.billing.transactions import ( from liberapay.constants import SESSION from liberapay.elsewhere._base import UserInfo from liberapay.exceptions import MissingPaymentAccount +from liberapay.i18n.currencies import Money from liberapay.main import website from liberapay.models.account_elsewhere import AccountElsewhere from liberapay.models.exchange_route import ExchangeRoute @@ -30,7 +31,6 @@ from liberapay.payin.common import ( ) from liberapay.security.csrf import CSRF_TOKEN from liberapay.testing.vcr import use_cassette -from liberapay.utils.currencies import Money TOP = realpath(join(dirname(dirname(__file__)), '..')) diff --git a/liberapay/testing/mangopay.py b/liberapay/testing/mangopay.py index e0f4e70a7..a0770d11c 100644 --- a/liberapay/testing/mangopay.py +++ b/liberapay/testing/mangopay.py @@ -8,10 +8,10 @@ from mangopay.resources import ( import mock import requests +from liberapay.i18n.currencies import Money from liberapay.models.exchange_route import ExchangeRoute from liberapay.testing import Harness from liberapay.testing.vcr import use_cassette -from liberapay.utils.currencies import Money class MangopayHarness(Harness): diff --git a/liberapay/utils/__init__.py b/liberapay/utils/__init__.py index 113f9dcb2..252b5db18 100644 --- a/liberapay/utils/__init__.py +++ b/liberapay/utils/__init__.py @@ -27,7 +27,7 @@ from liberapay.elsewhere._paginators import _modify_query from liberapay.elsewhere._utils import urlquote from liberapay.exceptions import AccountSuspended, AuthRequired, LoginRequired, InvalidNumber from liberapay.models.community import Community -from liberapay.utils.i18n import LOCALE_EN, add_helpers_to_context +from liberapay.i18n.base import LOCALE_EN, add_helpers_to_context from liberapay.website import website diff --git a/liberapay/utils/fake_data.py b/liberapay/utils/fake_data.py index 5fa93f5fb..71ebd1272 100644 --- a/liberapay/utils/fake_data.py +++ b/liberapay/utils/fake_data.py @@ -11,9 +11,9 @@ from liberapay.billing.transactions import ( record_exchange_result, lock_bundles, _record_transfer_result ) from liberapay.constants import D_CENT, DONATION_LIMITS, PERIOD_CONVERSION_RATES +from liberapay.i18n.currencies import Money, MoneyBasket from liberapay.models.exchange_route import ExchangeRoute from liberapay.models import community -from liberapay.utils.currencies import Money, MoneyBasket DONATION_PERIODS = tuple(PERIOD_CONVERSION_RATES.keys()) diff --git a/liberapay/utils/history.py b/liberapay/utils/history.py index 0bccc0276..1fdb3c5e2 100644 --- a/liberapay/utils/history.py +++ b/liberapay/utils/history.py @@ -6,8 +6,8 @@ from itertools import chain from pando import Response from pando.utils import utc, utcnow +from ..i18n.currencies import MoneyBasket from ..website import website -from .currencies import MoneyBasket from . import group_by diff --git a/liberapay/wireup.py b/liberapay/wireup.py index cb921c208..ed61019c1 100644 --- a/liberapay/wireup.py +++ b/liberapay/wireup.py @@ -32,6 +32,11 @@ from liberapay import elsewhere import liberapay.billing.payday import liberapay.billing.watcher from liberapay.exceptions import NeedDatabase +from liberapay.i18n.base import ( + ALIASES, ALIASES_R, COUNTRIES, LANGUAGES_2, LOCALES, Locale, make_sorted_dict +) +from liberapay.i18n.currencies import Money, MoneyBasket, get_currency_exchange_rates +from liberapay.i18n.plural_rules import get_function_from_rule from liberapay.models.account_elsewhere import _AccountElsewhere, AccountElsewhere from liberapay.models.community import _Community, Community from liberapay.models.exchange_route import ExchangeRoute @@ -39,13 +44,8 @@ from liberapay.models.participant import Participant from liberapay.models.repository import Repository from liberapay.models import DB from liberapay.utils import find_files, markdown, mkdir_p, resolve, urlquote -from liberapay.utils.currencies import Money, MoneyBasket, get_currency_exchange_rates from liberapay.utils.emails import compile_email_spt from liberapay.utils.http_caching import asset_etag -from liberapay.utils.i18n import ( - ALIASES, ALIASES_R, COUNTRIES, LANGUAGES_2, LOCALES, Locale, - get_function_from_rule, make_sorted_dict -) from liberapay.utils.query_cache import QueryCache from liberapay.version import get_version from liberapay.website import CustomUndefined diff --git a/tests/py/test_currencies.py b/tests/py/test_currencies.py index 9fdb3271a..875d8fd4b 100644 --- a/tests/py/test_currencies.py +++ b/tests/py/test_currencies.py @@ -7,10 +7,10 @@ from mock import patch from liberapay.billing.transactions import swap_currencies, Transfer from liberapay.constants import CURRENCIES from liberapay.exceptions import NegativeBalance, TransferError +from liberapay.i18n.currencies import Money, MoneyBasket from liberapay.payin.stripe import int_to_Money, Money_to_int from liberapay.testing import EUR, JPY, USD, Harness, Foobar from liberapay.testing.mangopay import FakeTransfersHarness, MangopayHarness, fake_transfer -from liberapay.utils.currencies import Money, MoneyBasket class TestCurrencies(Harness): diff --git a/tests/py/test_i18n.py b/tests/py/test_i18n.py index d564e8344..2fbeda927 100644 --- a/tests/py/test_i18n.py +++ b/tests/py/test_i18n.py @@ -3,8 +3,8 @@ from __future__ import absolute_import, division, print_function, unicode_literals from liberapay.exceptions import AmbiguousNumber, InvalidNumber +from liberapay.i18n.base import LOCALE_EN, Money from liberapay.testing import Harness -from liberapay.utils.i18n import LOCALE_EN, Money class Tests(Harness): diff --git a/tests/py/test_participant.py b/tests/py/test_participant.py index a242fcde3..6008d7027 100644 --- a/tests/py/test_participant.py +++ b/tests/py/test_participant.py @@ -19,9 +19,9 @@ from liberapay.exceptions import ( UsernameIsEmpty, UsernameTooLong, ) +from liberapay.i18n.currencies import Money from liberapay.models.participant import NeedConfirmation, Participant from liberapay.testing import EUR, USD, Harness -from liberapay.utils.currencies import Money class TestNeedConfirmation(Harness): diff --git a/tests/py/test_payday.py b/tests/py/test_payday.py index f98f48e2f..586dc8e85 100644 --- a/tests/py/test_payday.py +++ b/tests/py/test_payday.py @@ -6,12 +6,12 @@ import mock from liberapay.billing.payday import create_payday_issue, main, NoPayday, Payday from liberapay.billing.transactions import create_debt +from liberapay.i18n.currencies import MoneyBasket from liberapay.models.exchange_route import ExchangeRoute from liberapay.models.participant import Participant from liberapay.testing import EUR, USD, Foobar from liberapay.testing.mangopay import FakeTransfersHarness, MangopayHarness from liberapay.testing.emails import EmailHarness -from liberapay.utils.currencies import MoneyBasket class TestPayday(EmailHarness, FakeTransfersHarness, MangopayHarness): diff --git a/tests/py/test_sign_in.py b/tests/py/test_sign_in.py index 587a06033..8925d88d6 100644 --- a/tests/py/test_sign_in.py +++ b/tests/py/test_sign_in.py @@ -10,10 +10,10 @@ from six.moves.http_cookies import SimpleCookie from babel.messages.catalog import Message from liberapay.constants import SESSION +from liberapay.i18n.base import LOCALES from liberapay.models.participant import Participant from liberapay.testing import postgres_readonly from liberapay.testing.emails import EmailHarness -from liberapay.utils.i18n import LOCALES password = 'password' diff --git a/tests/py/test_take.py b/tests/py/test_take.py index a23dcfbae..ca0cddb3b 100644 --- a/tests/py/test_take.py +++ b/tests/py/test_take.py @@ -3,9 +3,9 @@ from __future__ import unicode_literals from psycopg2 import InternalError from liberapay.billing.payday import Payday -from liberapay.testing import EUR, USD, Harness +from liberapay.i18n.currencies import MoneyBasket from liberapay.models.participant import Participant -from liberapay.utils.currencies import MoneyBasket +from liberapay.testing import EUR, USD, Harness TEAM = 'A Team' diff --git a/www/%username/charts.json.spt b/www/%username/charts.json.spt index 71e1f729b..db6ae217e 100644 --- a/www/%username/charts.json.spt +++ b/www/%username/charts.json.spt @@ -10,8 +10,8 @@ this to mean, "no chart." """ +from liberapay.i18n.currencies import Money from liberapay.utils import get_participant -from liberapay.utils.currencies import Money [---] diff --git a/www/%username/edit/statement.spt b/www/%username/edit/statement.spt index fda84302b..1717b3e2d 100644 --- a/www/%username/edit/statement.spt +++ b/www/%username/edit/statement.spt @@ -1,7 +1,7 @@ # coding: utf8 +from liberapay.i18n.base import LANGUAGES_2, get_lang_options from liberapay.utils import excerpt_intro, form_post_success, get_participant, markdown -from liberapay.utils.i18n import LANGUAGES_2, get_lang_options [---] participant = get_participant(state, restrict=True, allow_member=True) diff --git a/www/%username/wallet/payin/bankwire/%back_to.spt b/www/%username/wallet/payin/bankwire/%back_to.spt index f23891cca..d0c1a5bb2 100644 --- a/www/%username/wallet/payin/bankwire/%back_to.spt +++ b/www/%username/wallet/payin/bankwire/%back_to.spt @@ -9,8 +9,8 @@ from liberapay.billing.fees import upcharge_bank_wire from liberapay.billing.transactions import cancel_bank_wire_payin, payin_bank_wire from liberapay.constants import EVENTS, PAYIN_BANK_WIRE_MIN from liberapay.exceptions import InvalidNumber +from liberapay.i18n.currencies import Money from liberapay.utils import b64decode_s, get_participant -from liberapay.utils.i18n import Money NOTIF_BIT_FAIL = EVENTS['payin_failed'].bit NOTIF_BIT_SUCC = EVENTS['payin_succeeded'].bit diff --git a/www/%username/wallet/payin/card/%back_to.spt b/www/%username/wallet/payin/card/%back_to.spt index c7f4be30e..be21a62b0 100644 --- a/www/%username/wallet/payin/card/%back_to.spt +++ b/www/%username/wallet/payin/card/%back_to.spt @@ -11,9 +11,9 @@ from liberapay.billing.transactions import ( ) from liberapay.constants import FEE_PAYIN_CARD, PAYIN_CARD_MIN from liberapay.exceptions import InvalidNumber, Redirect +from liberapay.i18n.currencies import Money from liberapay.models.exchange_route import ExchangeRoute from liberapay.utils import b64decode_s, check_address, get_participant, is_card_expired -from liberapay.utils.i18n import Money [---] diff --git a/www/%username/wallet/payin/direct-debit/%exchange_id.spt b/www/%username/wallet/payin/direct-debit/%exchange_id.spt index 860b20489..f7b285b7f 100644 --- a/www/%username/wallet/payin/direct-debit/%exchange_id.spt +++ b/www/%username/wallet/payin/direct-debit/%exchange_id.spt @@ -12,11 +12,11 @@ from liberapay.billing.transactions import ( ) from liberapay.constants import FEE_PAYIN_DIRECT_DEBIT, PAYIN_DIRECT_DEBIT_MIN from liberapay.exceptions import InvalidNumber +from liberapay.i18n.currencies import Money from liberapay.models.exchange_route import ExchangeRoute from liberapay.utils import ( b64decode_s, get_owner_address, get_owner_name, get_participant, obfuscate ) -from liberapay.utils.i18n import Money # https://docs.mangopay.com/endpoints/v2.01/mandates#e231_create-a-mandate MANDATE_LANGS = {'en', 'fr', 'nl', 'de', 'es', 'it', 'pl'} diff --git a/www/%username/widgets/%type.spt b/www/%username/widgets/%type.spt index cc3fcddee..756642a6c 100644 --- a/www/%username/widgets/%type.spt +++ b/www/%username/widgets/%type.spt @@ -1,7 +1,7 @@ from markupsafe import Markup +from liberapay.i18n.base import Wrap from liberapay.utils import get_participant -from liberapay.utils.i18n import Wrap span_open, span_close, br = Markup('
'), Markup(''), Markup('
') diff --git a/www/about/legal.spt b/www/about/legal.spt index 12e2a1483..b8efa4559 100644 --- a/www/about/legal.spt +++ b/www/about/legal.spt @@ -2,7 +2,7 @@ import os from markupsafe import Markup -from liberapay.utils.i18n import getdoc +from liberapay.i18n.base import getdoc MANGOPAY_TERMS = Markup().join( Markup('
  • %s
  • ') % (website.asset('mangopay/'+f), f) diff --git a/www/about/stats.spt b/www/about/stats.spt index 9ce73ce0d..d247b3cb4 100644 --- a/www/about/stats.spt +++ b/www/about/stats.spt @@ -1,7 +1,7 @@ # coding: utf8 from __future__ import division, print_function, unicode_literals -from liberapay.utils.currencies import Money, MoneyBasket +from liberapay.i18n.currencies import Money, MoneyBasket db = website.db db_qc5 = website.db_qc5 diff --git a/www/for/%name/edit.spt b/www/for/%name/edit.spt index 4136a37d4..d99d8ef63 100644 --- a/www/for/%name/edit.spt +++ b/www/for/%name/edit.spt @@ -1,5 +1,5 @@ +from liberapay.i18n.base import LANGUAGES_2, get_lang_options from liberapay.utils import get_community -from liberapay.utils.i18n import LANGUAGES_2, get_lang_options [---] diff --git a/www/for/new.spt b/www/for/new.spt index 655b34f1f..d765fe722 100644 --- a/www/for/new.spt +++ b/www/for/new.spt @@ -1,6 +1,6 @@ from liberapay.exceptions import AuthRequired +from liberapay.i18n.base import LANGUAGES_2, get_lang_options from liberapay.models.community import name_maxlength, normalize -from liberapay.utils.i18n import LANGUAGES_2, get_lang_options [---] diff --git a/www/index.html.spt b/www/index.html.spt index 2ab0ea009..6ac916bbb 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -2,8 +2,8 @@ from math import ceil +from liberapay.i18n.base import LANGUAGES_2 from liberapay.models.participant import Participant -from liberapay.utils.i18n import LANGUAGES_2 query_cache = website.db_qc5 diff --git a/www/migrate.spt b/www/migrate.spt index 760b287e4..f00da0324 100644 --- a/www/migrate.spt +++ b/www/migrate.spt @@ -4,9 +4,9 @@ import requests from liberapay.elsewhere._base import UserInfo from liberapay.exceptions import LoginRequired, UsernameAlreadyTaken +from liberapay.i18n.base import SEARCH_CONFS from liberapay.models.account_elsewhere import AccountElsewhere from liberapay.models.participant import NeedConfirmation, Participant -from liberapay.utils.i18n import SEARCH_CONFS pledge_platforms = {'github', 'twitter'} diff --git a/www/search.spt b/www/search.spt index 065410715..10ddeef7b 100644 --- a/www/search.spt +++ b/www/search.spt @@ -1,5 +1,5 @@ +from liberapay.i18n.base import LANGUAGES_2, SEARCH_CONFS, strip_accents from liberapay.utils import markdown -from liberapay.utils.i18n import LANGUAGES_2, SEARCH_CONFS, strip_accents [---]