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>
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
The Python 2.7 Support has been dropped since Ussuri.
So remove hacking rules for compatibility between python 2 and 3.
Change-Id: Ibed92787d66227fec0cf48c78de8a24f9b39cc52
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
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
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
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>
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>
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
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
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
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>
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>
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>
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
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
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
The base patch for this one adds a note to the guidelines. This patch
adds similar information to the API reference.
Change-Id: I6e21db2dd571aab3d33a97d93d989f986517d802
This patch fixes the issues raised in the previous robustness patch
I5c711b4654b5b2e591bcf365401ff35f7224fe82
Closes-bug: #1339337
Change-Id: I627c550e7bc05e56bbdffccf9bc88b88adf87aaf
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
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
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
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
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
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
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