diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 068a482..7cf453e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,15 @@ Changelog ========= -0.6.3 (unreleased) +0.6.4 (2022-11-17) ------------------ -- Nothing changed yet. +- compatibility with Django 4.0 added + +0.6.3 (2022-01-27) +------------------ + +- compatibility with Django 3.0 added 0.6.2 (2017-12-18) diff --git a/django_babel/extract.py b/django_babel/extract.py index edb42c7..7217fa0 100644 --- a/django_babel/extract.py +++ b/django_babel/extract.py @@ -1,15 +1,12 @@ # -*- coding: utf-8 -*- -from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK +from django.template.base import Lexer, TokenType from django.utils.translation import trim_whitespace -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str +from django.utils.translation.template import inline_re, block_re, endblock_re, plural_re, constant_re -try: - from django.utils.translation.trans_real import ( - inline_re, block_re, endblock_re, plural_re, constant_re) -except ImportError: - # Django 1.11+ - from django.utils.translation.template import ( - inline_re, block_re, endblock_re, plural_re, constant_re) +TOKEN_TEXT = TokenType.TEXT +TOKEN_VAR = TokenType.VAR +TOKEN_BLOCK = TokenType.BLOCK def join_tokens(tokens, trim=False): @@ -48,13 +45,7 @@ def extract_django(fileobj, keywords, comment_tags, options): encoding = options.get('encoding', 'utf8') text = fileobj.read().decode(encoding) - - try: - text_lexer = Lexer(text) - except TypeError: - # Django 1.9 changed the way we invoke Lexer; older versions - # require two parameters. - text_lexer = Lexer(text, None) + text_lexer = Lexer(text) for t in text_lexer.tokenize(): lineno += t.contents.count('\n') @@ -68,32 +59,32 @@ def extract_django(fileobj, keywords, comment_tags, options): yield ( lineno, 'npgettext', - [smart_text(message_context), - smart_text(join_tokens(singular, trimmed)), - smart_text(join_tokens(plural, trimmed))], + [smart_str(message_context), + smart_str(join_tokens(singular, trimmed)), + smart_str(join_tokens(plural, trimmed))], [], ) else: yield ( lineno, 'ngettext', - (smart_text(join_tokens(singular, trimmed)), - smart_text(join_tokens(plural, trimmed))), + (smart_str(join_tokens(singular, trimmed)), + smart_str(join_tokens(plural, trimmed))), []) else: if message_context: yield ( lineno, 'pgettext', - [smart_text(message_context), - smart_text(join_tokens(singular, trimmed))], + [smart_str(message_context), + smart_str(join_tokens(singular, trimmed))], [], ) else: yield ( lineno, None, - smart_text(join_tokens(singular, trimmed)), + smart_str(join_tokens(singular, trimmed)), []) intrans = False @@ -131,18 +122,18 @@ def extract_django(fileobj, keywords, comment_tags, options): yield ( lineno, 'pgettext', - [smart_text(message_context), smart_text(g)], + [smart_str(message_context), smart_str(g)], [], ) message_context = None else: - yield lineno, None, smart_text(g), [] + yield lineno, None, smart_str(g), [] elif bmatch: if bmatch.group(2): message_context = bmatch.group(2)[1:-1] for fmatch in constant_re.findall(t.contents): stripped_fmatch = strip_quotes(fmatch) - yield lineno, None, smart_text(stripped_fmatch), [] + yield lineno, None, smart_str(stripped_fmatch), [] intrans = True inplural = False trimmed = 'trimmed' in t.split_contents() @@ -151,13 +142,13 @@ def extract_django(fileobj, keywords, comment_tags, options): elif cmatches: for cmatch in cmatches: stripped_cmatch = strip_quotes(cmatch) - yield lineno, None, smart_text(stripped_cmatch), [] + yield lineno, None, smart_str(stripped_cmatch), [] elif t.token_type == TOKEN_VAR: parts = t.contents.split('|') cmatch = constant_re.match(parts[0]) if cmatch: stripped_cmatch = strip_quotes(cmatch.group(1)) - yield lineno, None, smart_text(stripped_cmatch), [] + yield lineno, None, smart_str(stripped_cmatch), [] for p in parts[1:]: if p.find(':_(') >= 0: p1 = p.split(':', 1)[1] @@ -166,4 +157,4 @@ def extract_django(fileobj, keywords, comment_tags, options): if p1[0] == '(': p1 = p1.strip('()') p1 = strip_quotes(p1) - yield lineno, None, smart_text(p1), [] + yield lineno, None, smart_str(p1), [] diff --git a/setup.py b/setup.py index 9c62fef..660fe1a 100755 --- a/setup.py +++ b/setup.py @@ -15,16 +15,16 @@ def read(*parts): name='django-babel', description='Utilities for using Babel in Django', long_description=read('README.rst') + u'\n\n' + read('CHANGELOG.rst'), - version='0.6.3.dev0', + version='0.6.4', license='BSD', author='Christopher Grebs', author_email='cg@webshox.org', - maintainer='Thomas Grainger', - maintainer_email='django-babel@graingert.co.uk', - url='https://github.com/python-babel/django-babel/', + maintainer='Nikita Grygoriev', + maintainer_email='n.grygoriev@useme.com', + url='https://github.com/nikitagrygoriev/django-babel', packages=find_packages(exclude=('tests',)), install_requires=[ - 'django>=1.8,<3.0', + 'django>=1.8', 'babel>=1.3', ], classifiers=[