Commit Graph

17 Commits

Author SHA1 Message Date
YuehuiLei 87f498bee5 Drop the usage of unicode prefix from unicode strings
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
2021-02-12 13:05:27 -06:00
Akihiro Motoki e5d09edc20 Use python3-style super()
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
2020-10-15 14:37:20 +09:00
Ivan Kolodyazhny e976461d85 Remove six usage from horizon package
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
2020-01-15 12:36:11 +02:00
francotseng 5de40b3f39 Complete angular translation extract pattern
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
2019-04-05 21:57:21 +08:00
Akihiro Motoki b06657b07d Fix gate failures by a new pycodestyle
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
2019-01-30 17:02:20 +09:00
Akihiro Motoki c076db20c8 pylint: fix len-as-condition warning
Change-Id: Ib89c1854ad42b96e4caf281160d568fe98430afe
2019-01-16 12:56:20 +09:00
Akihiro Motoki 386a5b669f Make babel_extract_angular work with python 3
Also run pep8 env with python3 as pep8/flake8 python 3 is
generally more strict.

Change-Id: Id4669ca1f929826f07cfe2928092d0e7255fda6f
Closes-Bug: #1762992
2018-04-11 19:43:30 +09:00
Akihiro Motoki 95629a337e Fix H405 (multi line docstring) warnings (horizon)
H405: multi line docstring summary not separated with an empty line

Partial-Bug: #1696996
Change-Id: I58f71206def1a25f3eda04b9297f1aa7d3caa646
2017-06-09 16:04:57 +00:00
Richard Jones b05658735b Enable Python 3.5 testing and fix tests
Fixes to a couple of places to make the python 3.5 tests pass.

Change-Id: I3f4b73b24fbe336ac6c80b7aa224a830ab7e36a6
2016-09-06 14:41:15 +10:00
Kenji Ishii 5e00cc5e92 Revert "i18n: trim whitespaces in extracted messages"
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
2016-08-03 17:11:40 +00:00
Akihiro Motoki f87b58fcab i18n: trim whitespaces in extracted messages from AngularJS templates
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
2016-07-07 12:24:01 +00:00
Richard Jones fdf0bf6f18 Fix babel msgids to include tag attributes and entities
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
2016-04-08 16:38:57 +10:00
Victor Stinner 7f3729f95c Port babel_extract_angular tests to Python 3
* 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
2015-09-30 18:26:28 +02:00
Thai Tran 3aad49dbc7 Babel extractor translating inner tags
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
2015-08-17 15:25:58 -07:00
Richard Jones e31e920336 Add extraction of filter-based translations
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
2015-07-24 20:17:53 +00:00
Thai Tran 09a5362e92 Add plurals and comments to angular i18n
This patch adds support for comments and pluralisation to the
babel angular extractor.

Partially-Implements: blueprint angular-translate-makemessages
Change-Id: I76bae0f25082b311affd070860ac4637d181495e
2015-07-24 14:58:07 +00:00
Neill Cox 9b36822fe2 Angular translation via babel (singular only)
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
2015-07-02 11:13:45 +10:00