python-babel / django-babel Goto Github PK
View Code? Open in Web Editor NEWTools for using Babel with Django
Home Page: http://django-babel.rtfd.org/
License: Other
Tools for using Babel with Django
Home Page: http://django-babel.rtfd.org/
License: Other
Hello, I had an ImportError when extracting the messages of my Django app. The message error was the following one:
from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
ImportError: cannot import name 'TOKEN_TEXT' from 'django.template.base' (c:\users\artac\appdata\local\programs\python\python37-32\lib\site-packages\django\template\base.py)
I managed to solve it by making some changes in the django_babel/extract.py file. Those changes where:
from django.template.base import Lexer, TokenType
extract_django(fileobj, keywords, comment_tags, options)
method, replacing every TOKEN_BLOCK
to TokenType.BLOCK
, TOKEN_TEXT
to TokenType.TEXT
and TOKEN_VAR
to TokenType.VAR
.My package versions are:
would be nice if you'd put the documentation somewhere, either ask mitsuhiko
on IRC if you can have a django-babel.pocoo.org documentation or use readthedocs.org, would be my recommendation.
Django 1.7 added a "trimmed" option for blocktrans tags. When that's enabled, then it strips whitespace from the beginning and end of strings as well as collapses consecutive whitespace characters in the string.
I'm pretty sure django-babel's extractor doesn't support that.
Is that correct? If so, can support for that be added?
Hi !
Django 1.10 support has been added in #33 and is merged but not yet released.
Is it possible to release this to be able to use it with Django 1.10 ?
Thansk by advance !
When upgrading a project from Django 1.6 to 1.8, several libraries had to be updated as well. One of them was BabelDjango 0.2.2 to django-babel 0.4.0.
One particular type of translation in templates was no longer picked up by the extract function in pybabel. When I run pybabel extract
and pybabel update
on the following template:
<html>
{% trans "test1" %}
{{ _('test2') }}
{% macro label(label) %}
<label>{{ label }}</label>
{% endmacro %}
{{ label(_('test3')) }}
{% call macros.label(_('test4')) %}{% endcall %}
</html>
The output is:
#: templates2/staff/base.tmpl:3
msgid "test1"
msgstr ""
#: templates2/staff/base.tmpl:4
msgid "'test2'"
msgstr ""
#: templates2/staff/base.tmpl:12
msgid "'test4'"
msgstr ""
So test3
is not picked up anymore. I tried several combinations and/or versions of libraries, but could not get it to work with Django 1.8. I also compared the extract functions that both BabelDjango 0.2.2 and django-babel 0.4.0 use and not much changed there. My guess is that the extract function in django-babel does not pick up this translation with Django's template engine changes.
Installed packages (where "test3" is not picked up by extract)
Django==1.8.9
Jinja2==2.7.1
django_jinja==2.1.1
Babel==2.2.0
django-babel==0.4.0
Installed packages (where "test3" is picked up by extract)
Django==1.6.10
Jinja2==2.7.1
jingo==0.6.1
Babel==1.3
BabelDjango==0.2.2
tox -edocs
GLOB sdist-make: /home/mrunge/work/django-babel/setup.py
docs inst-nodeps: /home/mrunge/work/django-babel/.tox/dist/django-babel-0.4.0.zip
docs installed: alabaster==0.7.7,Babel==2.2.0,Django==1.9.2,django-babel==0.4.0,docutils==0.12,Jinja2==2.8,MarkupSafe==0.23,Pygments==2.1.1,pytz==2015.7,six==1.10.0,snowballstemmer==1.2.1,Sphinx==1.3.5,sphinx-rtd-theme==0.1.9
docs runtests: PYTHONHASHSEED='2878308748'
docs runtests: commands[0] | sphinx-build -W -b html -d /home/mrunge/work/django-babel/.tox/docs/tmp/doctrees docs /home/mrunge/work/django-babel/.tox/docs/tmp/_build/html
Running Sphinx v1.3.5
making output directory...
loading pickled environment... not yet created
loading intersphinx inventory from https://docs.python.org/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 5 source files that are out of date
updating environment: 5 added, 0 changed, 0 removed
reading sources... [ 20%] extract
reading sources... [ 40%] index
reading sources... [ 60%] management-commands
reading sources... [ 80%] middleware
reading sources... [100%] template-tags
Warning, treated as error:
/home/mrunge/work/django-babel/docs/template-tags.rst:4: WARNING: autodoc: failed to import module u'django_babel.templatetags.babel'; the following exception was raised:
Traceback (most recent call last):
File "/home/mrunge/work/django-babel/.tox/docs/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
__import__(self.modname)
File "/home/mrunge/work/django-babel/.tox/docs/lib/python2.7/site-packages/django_babel/templatetags/babel.py", line 3, in <module>
from babel import support as babel_support
ImportError: cannot import name support
ERROR: InvocationError: '/home/mrunge/work/django-babel/.tox/docs/bin/sphinx-build -W -b html -d /home/mrunge/work/django-babel/.tox/docs/tmp/doctrees docs /home/mrunge/work/django-babel/.tox/docs/tmp/_build/html'
Hey! I saw that django-babel has Django 1.11 support on master. Could we get a release on PyPI for downstream consumers?
Thanks
I have template with {% trans 'message' context 'some' %}
and when django-babel
gets this translation it's missing context
It doesn't seem to work with django 1.10, I guess just upgrading the checker to accept 1.10 would be enough:
pkg_resources.VersionConflict: (Django 1.10 (/x/y/z/lib/python3.5/site-packages), Requirement.parse('django<1.10,>=1.4'))
Traceback No module named django_babeltest_mako ,
how to deal with this problem
One usually only needs merge PR builds and not building pushes speeds up the merge process.
Just a recommendation :) I usually do that for all my repos.
Hi! Is this project still maintained. If you need any help I will be happy to
When I look at the django source code, I see that %
signs are escaped to %%
during extraction [1] [2] then replaced by %
during the rendering [3].
There is no such replacements during the extraction, but Django will still want to replace %%
by %
on rendering.
If you confirm my analysis, I can create a PR to fix the issue
[1] https://github.com/django/django/blob/stable/1.11.x/django/utils/translation/template.py#L182
[2] https://github.com/django/django/blob/stable/1.11.x/django/utils/translation/template.py#L145
[3] https://github.com/django/django/blob/master/django/templatetags/i18n.py#L86
Hi!
Currently, we faced the following issue for Django 2.1.* series:
django_babel/extract.py", line 2, in <module>
from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
ImportError: cannot import name 'TOKEN_TEXT'
Package versions:
So there need to add some compatibility. I'm in progress with the PR now.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.