All strings are considered as unicode strings in python 3,
so we no longer need "u" prefix (u'...').
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: I796d2fcdca066475bbf29d25cbf2aa67b2b2178b
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.
pylint provides a check for this.
Let's enable 'super-with-arguments' check.
NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.
Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
We don't support Python 2 anymore so we don't need this
compatibility library.
six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.
This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.
Change-Id: I0b567382edf4d68674a7b8d0b02333fb57293958
Currently AngularGettextHTMLParser parses translations of form
{$ 'content' | translate $}. However, there is another form in
projects' html files: {$ ::'content' | translate $}.
This commit fine-tunes the filter_regex and related handle_xxx
functions to extract both forms of translations.
Change-Id: I7129a13d046b699328b77267ae4936d31af8144c
pycodestyle 2.5.0 introduces E117 over-indented.
This commit fixes E117 errors.
pycodestyle 2.5.0 also drops pep8.py. As a result,
horizon/test/unit/hacking/test_checks.py starts to fail.
The equivalent elements are provided by pycodestyle.py,
so we can consume pycodestyle instead of pep8 module.
Change-Id: Ib103998f42ce7c901a10669b771a898783ca1a92
Also run pep8 env with python3 as pep8/flake8 python 3 is
generally more strict.
Change-Id: Id4669ca1f929826f07cfe2928092d0e7255fda6f
Closes-Bug: #1762992
This reverts commit f87b58fcab.
In https://bugs.launchpad.net/horizon/+bug/1592965,
extracted messages are stored with trimming.
After this change, strings with multi lines cannot be translated.
This change cause the difference between the real strings in html
and a key in pot, from the view point of extra spaces and break lines.
Message extraction is done by babel (with horizon specific extractor),
but translation message lookup is done by angular-gettext.
As a result, a key used in translation lookup becomes different from
a key generated by the message extraction.
Keys in both steps should be same.
So this patch reverts the corresponding commit to make translation
work, even though it may be annoying for translators again.
Regarding the comment from i18n perspective, see Akihiro's comment
in patch set 3 in https://review.openstack.org/#/c/347725
Closes-Bug: #1606837
Change-Id: I651a2f39fdc0209f702cb9cf45691c944382b897
When extracting translation messages from AngularJS templates,
there is no need to keep whitespaces in the messages as there is
no meaning of repeated whitespaces in HTML.
This will make translation effort much simpler.
More detail is described in the bug report.
This commit trims such whitespaces. Django provides a convenient method
to do the same purpose for 'trimmed' option in Django templates.
This method is reused in this commit as well.
Closes-Bug: #1592965
Change-Id: I9b7ce54452f3db2350eecc3115db2e4173df5167
The messages for translation were omitting the attributes in
tags and HTML entities embedded in the translation strings,
thus they no longer matched the original HTML.
Additionally, HTML entities are mostly (but not always) decoded
by the browser before angular-gettext sees them, so we have to
emulate this behaviour in our babel extractor so the message
ids match.
Change-Id: Ie6ae0776a2c0d7db589b34a9e7676508178a473d
Closes-Bug: 1561550
Closes-Bug: 1561738
Closes-Bug: 1561761
* Fix AngularGettextHTMLParser constructor: call the constructor of the
right parent class.
* tox.ini: Add horizon.test.tests.babel_extract_angular to Python 3.4
Partial-Implements: blueprint porting-python3
Change-Id: I020f9655baf18326f3752b82a8c3bf385c8e1e24
The current extractor does not support nesting of inner tags.
This creates problems when we have something like this
"<translate> hello <b>beautiful</b> world</translate>".
The message extraction gets prematurely cut off.
Futhermore, the extractor does not support trimming.
This is important because angular-gettext trims the content and use that
as the msgid. The goal is to get it working with angular-gettext, hence,
we also need to trim our messages.
Change-Id: I9265f731431521240dddd24bb87baa97cc3ed4b5
Implements: blueprint babel-translate-inner-tags
This patch adds detection and extraction of strings to
extract that use the filter mechanism for translation:
<img alt="{$ 'description' | translate $}">
The patch also tweaks the existing code in a couple of ways:
- clean up python version compatibility for the HTMLParser rename
- alter the existing unit tests to make them more stringent in
checking some cases
Change-Id: Ice933f560d17af8b7f17f31981d3935c67019355
This patch adds support for comments and pluralisation to the
babel angular extractor.
Partially-Implements: blueprint angular-translate-makemessages
Change-Id: I76bae0f25082b311affd070860ac4637d181495e
An approach to i18n for Angular HTML templates using babel. This patch
allows only singular translation. Plurals and context will be
addressed in subsequent patches.
Based on Thai Tran's work at https://review.openstack.org/#/c/187321
This patch implements a custom extractor in
horizon/utils/babel_extract_angular.py. pybabel really wants this to be
a package installed into site-packages. I have not done this so as to
avoid introducing a dependency on another change to global requirements
just yet. I will upload a package to pypi in parallel so that we can
start using it in the future.
For now, I have had to modify tools/with_venv.sh to add horizon to the
PYTHONPATH. This is less than ideal but seemed to be the least worst
option.
Steps to verify that it works:
1. Create a new html file in horizon/static or openstack_dashboard/static
2. Add something like <div translate>hello world!</div> to the html
To test interpolation add something like:
<div translate>hello {$name$}!</div>
3. Run ./run_tests.sh --makemessages
4. Inspect your djangojs.po file, it should be there.
The following steps are optional:
5. Run ./run_tests.sh --pseudo de
6. Run ./run_tests.sh --compilemessages
7. Go to http://localhost:8000/settings
8. Change Language to Deutsch
9. Go to http://localhost:8000/i18n/js/horizon+openstack_dashboard
10. Your translated text should be there as well.
Note: There are now unit tests as well.
Partially-Implements: blueprint angular-translate-makemessages
Depends on: If4352aba01ce0ca6337f590c0689d8fe9f0867c8
Change-Id: I26d4fef8646d5f038918cd3376dbbdbef37eb603