Commit Graph

46 Commits

Author SHA1 Message Date
Takashi Kajinami 106ad5f374 Bump hacking
hacking 3.0.x is too old.

Change-Id: Id9565ec8a49d6482b6de1527d6ab190eb9594372
2024-01-26 01:28:26 +09:00
Michał Górny 151fa09cf0 Fix leftover `locale.getdefaultlocale` mock
Replace the remaining `locale.getdefaultlocale` mock with
`locale.getlocale`.  77a994a993 has
replaced the `locale.getdefaultlocale()` call and updated all other
mocks but this one remained, causing test failures on non-en_US locales.

Closes-Bug: 2043539
Change-Id: I5ab36a0ead05fa7a83fc1c64e440482f2cc8e675
Signed-off-by: Michał Górny <mgorny@gentoo.org>
2023-11-15 09:19:38 +01:00
Zuul 740af568bb Merge "The locale.getdefaultlocale is deprecated" 2023-09-14 10:18:19 +00:00
OpenStack Proposal Bot a74cbd9810 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: I536264140a77d0b41cd13c25b48a0d073952cf57
2023-05-06 03:45:03 +00:00
Pete Zaitcev 77a994a993 The locale.getdefaultlocale is deprecated
This patch is prompted by the following deprecation warning:

DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead

But getdefaultlocale() is scheduled to be removed in Python
3.13, so we need to act anyway.

We use LC_CTYPE as the most compatible setting. Probablly what
we really want for translations is LANG, but that is not a
valid argument for getlocale(). Fortunately, LC_CTYPE is set
when the environment variable LANG is set, so this works for us.

Change-Id: I07bdbaf95108aa4fdb4c645c12b196dcb820059b
2023-03-08 20:06:26 -06:00
songwenping 342d388803 Remove unnecessary unicode prefixes
Change-Id: Ia75cc0c9fd5117b22b54fe872b28a4164faedf9a
2022-04-19 19:31:26 +08:00
haixin 8609dc2c4c Remove all usage of six library
Replace six with Python 3 style code.

Change-Id: I3d2b0f7a78d4914913a3af3b68388392bf30b982
2020-11-26 14:41:12 +08:00
wangzihao 912849fe1a Remove six.PY3
The Python 2.7 Support has been dropped since Ussuri.
So remove hacking rules for compatibility between python 2 and 3.

Change-Id: Ibed92787d66227fec0cf48c78de8a24f9b39cc52
2020-09-23 09:37:53 +00:00
Hervé Beraud adc7f0c1fc Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: If01e22f2c01fdde9fc3569c243e805207b9cad88
2020-06-02 20:39:08 +02:00
Ben Nemec 9975652553 Remove a couple more shim tests
Since we removed the translate function from Message, we no longer
need tests for it. I missed removing these in
I9ba75874f64c4d7118c7679015c2e0eab5a69e4a so let's do that now.

Change-Id: Idfefcfe81521f6f5a9f0c197bd7998ffa31a4470
2020-05-27 19:30:22 +00:00
Zuul e4d1659c6e Merge "Remove Message.translate" 2020-05-27 15:52:20 +00:00
Ben Nemec 93b1405775 Remove Message.translate
This was deprecated in the Train cycle so we should be safe to remove
it in Victoria. I don't expect this to affect any users of the library
because the documented way to do a translation is to call the
_translate.translate function, so although this is technically a
public API change I don't believe anyone was actually using it.

Change-Id: I9ba75874f64c4d7118c7679015c2e0eab5a69e4a
2020-05-26 16:47:13 +00:00
Ben Nemec 0901283923 Add Babel aliases to get_available_languages
This pulls in the alias mapping from Babel[0] that previously made
some two character locale names available. It simply appends each
alias that is found by gettext.find to the list of available languages.

This change in behavior was initially reported as a result of a
breaking Glance unit test. After looking a bit closer at the test
in question, it appears they mock out gettext.find to assume the
existence of that locale. Whether it would actually exist in a real
world deployment I have no idea. However, I don't think it hurts
anything to include these aliases in the list checked by
get_available_languages so this should be fine.

Note that I did no mapping of the aliases in our override of
gettext.find. There was no aliasing going on there for these two
letter locales before either, so if they were found before they
will be found now. The same is true if they were not found before,
so this maintains the previous behavior.

Change-Id: Ie57ed2ca0228634ed9a3def99bf606ce1832a195
0: e7e4265d9a/babel/core.py (L80)
Closes-Bug: 1877386
2020-05-22 21:01:11 +00:00
Stephen Finucane 4e907ed2f3 Drop use of babel
We were simply using this to get a list of language codes. Turns out
Python provides a way to do this already via the 'locale' module, which
provides all of the locales we care about [1]. Use this.

[1] https://github.com/python/cpython/blob/3.5/Lib/locale.py

Change-Id: Id6dce33fdbe3fc537dfe28d5cc604985b3347405
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-04-16 17:31:19 +01:00
Sean McGinnis 34aaaf2eb5
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I597461bc2ce6a480ea18950ded606ef7db717f2d
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-31 15:55:50 -05:00
Hervé Beraud 281fd591e7 [ussuri][goal] Drop python 2.7 support and testing
OpenStack is dropping the py2.7 support in Ussuri cycle.

Complete discussion & schedule can be found in
-
http://lists.openstack.org/pipermail/openstack-discuss/2019-October/010142.html
- https://etherpad.openstack.org/p/drop-python2-support

Ussuri Communtiy-wide goal:
https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html

Change-Id: I340a7909c49e7d2a8c82c668cbdaf9ced7196f67
Sem-Ver: api-break
2020-02-06 10:23:19 +01:00
Ben Nemec 2249925846 Deprecate Message.translate in favor of Message.translation
It shadows the unicode function of the same name, and there's no
way to entirely disambiguate the two based on the parameter passed
in. This change deprecates Message.translate and makes it a wrapper
around the new function, Message.translation.

Note that we never documented calling Message.translate directly.
The documented way to get the translated form of a Message is to call
the _translate.translate function in this project, so chances are
that this public API change will have little actual impact on users.

Change-Id: I0c617937f5af7467d1454f72acd0474ae2ce0293
Closes-Bug: 1841796
2019-08-29 19:10:42 +00:00
Ben Nemec f8fa059c46 Allow Message.translate to handle unhashable inputs
We made a mistake with the API of the Message class and shadowed the
built-in function 'translate' from the unicode class that it inherits
from. This means that our translate may be called with things like
dicts and lists that are not hashable, which is problematic because
we use that value as a dict key. Unhashable types are not allowed as
dict keys so this fails.

While ideally we would address this shadowing by renaming our version
of translate, it is part of the public API of the library and thus
we can't just change it arbitrarily. As a partial fix, this change
adds a type check on the input parameter, and if it finds a type
other than a string it calls the superclass's implementation of
translate instead. This should handle most common uses of the stdlib
translate, but since technically it is possible to use a string as
input to that as well it doesn't fully address the problem.

Change-Id: Ie68cba6af19d11de8968ee80ac10107f488acb92
Partial-Bug: 1841796
2019-08-28 15:46:03 +00:00
Thomas Herve a5fde9a90a Override getttext.find to cache result
This monkey patches gettext to cache the results of gettext.find. This
allows to drastically reduces system calls made over time for checking
the existence of mo files, which don't move.

Change-Id: I1464f131b90123aab67ef45ae2a2685a3ba111ef
2018-11-21 14:45:52 +01:00
Chuck Short eb32de4565 Remove unused code
self.stubs and self.mox were left over from oslotest changes,
so remove them.

Change-Id: I00871c45672fadee9e93722543612b0bd9d76aea
Signed-off-by: Chuck Short <chucks@redhat.com>
2018-08-21 21:22:44 -04:00
Charles Short fe3e09af2a Remove moxstubout usage
In newer versions of oslotest moxstubout is deprecated,
so get out in front of the curve and replace it with mock.

Change-Id: Ib7526bc5f7fc21cda9288e085216997519322010
Signed-off-by: Charles Short <zulcss@gmail.com>
2018-05-19 14:20:02 +00:00
Doug Hellmann 6d8da4cdb9 set default python to python3
Set the default python to python3 except for the py27 environment. We
have to set that explicitly to override the new default.

As part of updating the pep8 job to run python 3 we need to remove the
use of the python 2 builtin unicode(). We can use six.text_type() to
produce the same result until we drop python 2 support.

Change-Id: I43c03aeb73bb8a246115400bcbd9a0a68708abd9
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-04-16 13:04:03 -04:00
OpenStack Proposal Bot c86f6eea79 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: Ia748a2799ea85e33ffab786a2f4f6447d4bdca19
2018-03-01 06:47:51 +00:00
WangBinbin 108d2bb7a9 Fix wrong response with language zh-TW.
When request OpenStack service with zh-TW, the response is zh-CN.

Change-Id: I00601dec28adbef05e9ab0ebb6d291d0eee8becb
Closes-Bug: #1665255
2017-02-20 02:11:01 +08:00
Luong Anh Tuan d99353c44d Replace six.iteritems() with .items()
We should avoid using six.iteritems/keys achieve iterators. We can use
dict.items/keys instead, as it will return iterators in PY3 as well.
And dict.items/keys will more readable.

In py2, the performance about list should be negligible, see
https://wiki.openstack.org/wiki/Python3 and
http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I8cdac1b75918094b9b3acbc65d53d231e86eca19
2016-11-23 12:02:38 +00:00
yanheven 69cf173ea7 Fix parameters of assertEqual are misplaced
Many assertEqual sentences don't follow assertEqual(expected, actual),
These misplaces have 2 impacts:
1, giving confusing messages when some tests failed.
2, mislead other developers, new test modules may follow these wrong pattern.

This patch fix all of them.

Change-Id: I33b5b59fda524d88386072d2058c4770a948db6f
Closes-Bug: #1604213
2016-07-23 19:54:15 +08:00
OpenStack Proposal Bot 4b33a2c0b0 Imported Translations from Zanata
For more information about this automatic import see:
https://wiki.openstack.org/wiki/Translations/Infrastructure

Change-Id: I78d7939fc32332b6b704eec43c5b2ae1c945af30
2016-06-04 06:50:46 +00:00
Joshua Harlow 1dc7cb7992 Better isolate tests and fixtures from environment
Remove a duplicate monkey patch as well as ensure that the
environment the test is running in does not influence the
test results (especially in regard to locale settings).

Change-Id: I2451240148bb329e0ff9aa01f279bde9711e599f
2016-03-24 11:42:53 -07:00
OpenStack Proposal Bot c6e44bc786 Imported Translations from Zanata
For more information about this automatic import see:
https://wiki.openstack.org/wiki/Translations/Infrastructure

Change-Id: I58f5c1932ade80a7c39ed91db3160a2d7170168a
2016-02-21 06:18:34 +00:00
Akihiro Motoki cbb1204498 Update translation setup
Follow new infra setup for translations, see spec
http://specs.openstack.org/openstack-infra/infra-specs/specs/translation_setup.html
for full details.

This basically renames oslo.i18n/locale/oslo.i18n.pot to
oslo_i18n/locale/oslo_i18n.pot.
For this we need to update setup.cfg.

Update also domain name in _i18n.py.

Update unit test to adapt to domain name change.

Change-Id: Ie016591a38dc0a83aadde501f882ee7849fa0c4f
2016-01-31 00:20:42 +09:00
Doug Hellmann 176959cbb8 add versionadded designations to newer functions
The base patch for this one adds a note to the guidelines. This patch
adds similar information to the API reference.

Change-Id: I6e21db2dd571aab3d33a97d93d989f986517d802
2015-12-28 15:34:11 +00:00
ChangBo Guo(gcb) 2d76ae46fe Remove Python 2.6 workround for logging
You can find why we add it in [1], we don't support Python 2.6 any more,
so we can remove the workaround now.
[1] https://review.openstack.org/#/c/56093/8/openstack/common/gettextutils.py

Change-Id: I5b67e3fcadbdd38f6e92e79f6549af5bafec29e4
2015-11-27 12:03:07 +08:00
ChangBo Guo(gcb) 835c89a9e5 Drop python 2.6 support
Change-Id: Ibd2c83ad19ff9890a9baef7926a1d32fea156ecc
2015-11-23 22:19:12 +08:00
Balazs Gibizer 634c52f602 Enhance the formatting error robustness patch
This patch fixes the issues raised in the previous robustness patch
I5c711b4654b5b2e591bcf365401ff35f7224fe82

Closes-bug: #1339337

Change-Id: I627c550e7bc05e56bbdffccf9bc88b88adf87aaf
2015-09-29 16:44:06 +02:00
Balazs Gibizer 8d49c279cf Trap formatting errors
Trap errors when trying to use translated messages as format strings so
translations don't break applications. Log the error, with the format
string (without interpolated values) and the original message so a bug
report can include it to make fixing the translation easier.

Co-Authored-By: Doug Hellmann <doug@doughellmann.com>

Change-Id: I5c711b4654b5b2e591bcf365401ff35f7224fe82
Closes-bug: #1339337
2015-08-24 15:27:57 +02:00
Doug Hellmann 7a0ab97cd0 Clean up _translate_msgid logic a bit
Streamline the logic in _translate_msgid to a series of cascading
if/elif statements to avoid having several different return points. Add
some test coverage for situations not handled by existing test code.

Change-Id: I9e0343757f515116c07f7f3fe1eab078046555e0
2015-08-01 19:45:48 +00:00
Jenkins cefa61014a Merge "Only define CONTEXT_SEPARATOR once" 2015-07-24 02:16:19 +00:00
Doug Hellmann 1b0b713120 Fix mock use for 1.1.0
Use the correct method name to check the calls to the mock.

Change-Id: Ibd7ab3f0a7f47682592b29cb238f78dae6337ba7
2015-07-12 19:18:06 +00:00
Doug Hellmann ecb91209d8 Only define CONTEXT_SEPARATOR once
Replace 2 of 3 definitions of CONTEXT_SEPARATOR with a reference to the
variable in _message.py.

Change-Id: I37020ca7cf26b523d3739b5613ea5d9be9051e0a
2015-07-02 20:43:02 +00:00
Peng Wu 9e3132bc2f Support contextual and plural form of gettext functions
This draft patch is created for more-gettext-support blueprint review.

Refer URL:
https://blueprints.launchpad.net/oslo.i18n/+spec/more-gettext-support
https://review.openstack.org/#q,topic:bp/more-gettext-support,n,z

Implements: blueprint more-gettext-support

Depends-on: I258eac447ecc7b71fb02952077cf3ef3ecfe12bb

Change-Id: Ic16d902ddfe94cfb5cfabe1c4f612ff001a8fa53
2015-07-01 14:56:54 +08:00
Doug Hellmann d49cfaac72 Remove oslo namespace package
Blueprint remove-namespace-packages

Depends-on: I5bd1cdc35d2ecaf98a0802fff589d8c37aaa8028
for openstack/django_openstack_auth
Depends-on: I5da7ca7a8a909eb12a4417e7d5f5b6bd33da4de8
for openstack/horizon
Depends-on: Ib17a74ada3122ce45c52fdd7dcf8d27fafbb1d70
for openstack/openstack-doc-tools
Depends-on: I1f539cf9f5d6f48e10cac381c13eeb5fa314abd4
for openstack/python-ceilometerclient
Depends-on: Ic21066211a071591854280a93a53bb2255cb8ad3
for openstack/python-ironicclient
Depends-on: I387a7a1a817058a4daca313fe6df60612cb84864
for openstack/python-keystoneclient
Depends-on: I32767615b2d678b6ce545722b6b9d1704cb1ffb4
for openstack/python-keystoneclient-saml2
Depends-on: Id26264ad0b002ab21e60431a2fd39fcecf76c490
for openstack/python-magnumclient
Depends-on: Ib86c36f81f6fdbee64d88dd0b1d126bcc16649ac
for openstack/python-manilaclient
Depends-on: If5e8257085b5fd0a26a34705505fc0077adbabb2
for openstack/python-novaclient
Depends-on: I37ce99d8c9a2ba5b97a12a0c2666f6340dbc7f42
for openstack/python-saharaclient
Depends-on: I2a8caa859830b3416bfe54e4261dd3415ac5a76a
for openstack/python-troveclient
Depends-on: I324a3bd0c468a3e84f633497ad5c0d59c5ccc455
for openstack/python-tuskarclient
Depends-on: Id54b2381f00d9905c4bb07821f54c5aaaa48d970
for openstack/python-zaqarclient
Depends-on: I9d3e80d94795060d375aae30ce249513aae3fd97
for openstack/trove

Change-Id: I1b100a426f84b91f9c5a9a857f420e36c209cbb4
2015-06-04 20:05:53 +00:00
James Carey 9a2cde208a Add test fixture to prefix lazily translated messages
This fixture enables testing of lazy translation by faking out translations
by providing a translation that is the message id prefixed with the domain
and language used in the translation.  It supports the definition of new fake
languages so that a different language can be specified without having to
create the associated message catalogs.

For example, this will be used to test that a fake language requested using
the Accept-Language header is used to translate the message instead of
the default language.  That is, that the message was enabled for lazy
translation and was not translated until just before it was returned to the
user.

Change-Id: If6dd28815d11c07ce9430ed07e61bfbc23695707
Partially-Implements: blueprint i18n-enablement-juno
2015-01-28 15:13:46 +00:00
James Carey d9b3ca60a7 Clear global cache in test_get_available_languages
The test_get_available_languages test assumes that
get_available_languages() has not been called prior to the test.
That is, it assumes that the global variable
_gettextutils._AVAILABLE_LANGUAGES does not already have a domain's
languages cached in it.  This causes problems if another test case
uses get_available_languages().  In order to properly isolate this
test case, it is updated to clear the cache prior to testing.

Change-Id: Ie04d7d98b51f4cc3cc9f0eda69425349e0801d6f
2015-01-19 20:28:44 +00:00
Doug Hellmann 118aeb0ceb Add a fixture to let tests manage the lazy flag
We do not want to expose the stored lazy flag, but we do want to allow
applications to force it to a certain state and then restore it to its
original test for testing. This new fixture provides a way to do that.

Change-Id: Ica05fd8fc7e687da69d61ea84bf1ceae65db93ce
2015-01-06 17:25:32 -05:00
Doug Hellmann 582c7183ca Correct the translation domain for loading messages
Change-Id: If7fa8fd1915378bda3fc6e361049c2d90cdec8af
2014-12-22 11:17:54 -05:00
Doug Hellmann ba05e9a9b9 Move out of the oslo namespace package
Move the public API out of oslo.i18n to oslo_i18n. Retain the ability to
import from the old namespace package for backwards compatibility for
this release cycle.

bp/drop-namespace-packages

Change-Id: I800f121c271d8e69f6e776c4aef509bbb8008170
2014-12-18 16:35:03 -05:00