summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Nemec <bnemec@redhat.com>2020-05-26 16:47:13 +0000
committerBen Nemec <bnemec@redhat.com>2020-05-26 16:47:13 +0000
commit93b140577518ce905c890f579104e8ecff030821 (patch)
treecf7f4c7f2d591d356055be22c51eae119ea4848f
parent7e00c5939aca92876b69f51ca2a7ffd595bd73cd (diff)
downloadoslo-i18n-93b140577518ce905c890f579104e8ecff030821.tar.gz
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
-rw-r--r--oslo_i18n/_message.py35
-rw-r--r--oslo_i18n/tests/test_message.py9
2 files changed, 0 insertions, 44 deletions
diff --git a/oslo_i18n/_message.py b/oslo_i18n/_message.py
index ce31970..09ed69c 100644
--- a/oslo_i18n/_message.py
+++ b/oslo_i18n/_message.py
@@ -68,41 +68,6 @@ class Message(six.text_type):
msg.has_plural_form = has_plural_form
return msg
- def translate(self, desired_locale=None):
- """DEPRECATED: Use ``translation`` instead
-
- This is a compatibility shim to allow callers a chance to move away
- from using this function, which shadows a built-in function from our
- parent class.
- """
- # We did a bad thing here. We shadowed the unicode built-in translate,
- # which means there are circumstances where this function may be called
- # with a desired_locale that is a non-string sequence or mapping type.
- # This will not only result in incorrect behavior, it also fails
- # because things like lists are not hashable, and we use the value in
- # desired_locale as part of a dict key. If we see a non-string
- # desired_locale, we know that the caller did not intend to call this
- # form of translate and we should instead pass that along to the
- # unicode implementation of translate.
- #
- # Unfortunately this doesn't entirely solve the problem as it would be
- # possible for a caller to use a string as the mapping type and in that
- # case we can't tell which version of translate they intended to call.
- # That doesn't seem to be a common thing to do though. str.maketrans
- # returns a dict, and that is probably the way most callers will create
- # their mapping.
- if (desired_locale is not None and
- not isinstance(desired_locale, six.string_types)):
- return super(Message, self).translate(desired_locale)
- warnings.warn('Message.translate called with a string argument. '
- 'If your intent was to translate the message into '
- 'another language, please call Message.translation '
- 'instead. If your intent was to call "translate" as '
- 'defined by the str/unicode type, please use a dict or '
- 'list mapping instead. String mappings will not work '
- 'until this compatibility shim is removed.')
- return self.translation(desired_locale)
-
def translation(self, desired_locale=None):
"""Translate this message to the desired locale.
diff --git a/oslo_i18n/tests/test_message.py b/oslo_i18n/tests/test_message.py
index 9e5fa04..346e854 100644
--- a/oslo_i18n/tests/test_message.py
+++ b/oslo_i18n/tests/test_message.py
@@ -633,15 +633,6 @@ class MessageTestCase(test_base.BaseTestCase):
table[ord('c')] = 'd'
self.assertEqual('bcd', msg.translate(table))
- @mock.patch('warnings.warn')
- def test_translate_warning(self, mock_warn):
- msg = _message.Message('a message')
- msg.translate('es')
- self.assertTrue(mock_warn.called, 'No warning found')
- # Make sure it was our warning
- self.assertIn('Message.translate called with a string argument.',
- mock_warn.call_args[0][0])
-
class TranslateMsgidTest(test_base.BaseTestCase):