Fix lazy translation issue with watcher-db-manage
In this changeset, I fix the issue caused by the use of lazy translations within the 'watcher-db-manage purge' subcommand. This is caused by the PrettyTable dependency which performs addition operations to format its tables and the __add__ magic method is not supported by oslo_i18n._message.Message objects. Change-Id: Idd590e882c697957cfaf1849c3d51b52797230f6 Closes-Bug: #1584652
This commit is contained in:
parent
78689fbe3b
commit
277a749ca0
@ -15,6 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import oslo_i18n
|
import oslo_i18n
|
||||||
|
from oslo_i18n import _lazy
|
||||||
|
|
||||||
# The domain is the name of the App which is used to generate the folder
|
# The domain is the name of the App which is used to generate the folder
|
||||||
# containing the translation files (i.e. the .pot file and the various locales)
|
# containing the translation files (i.e. the .pot file and the various locales)
|
||||||
@ -42,5 +43,9 @@ _LE = _translators.log_error
|
|||||||
_LC = _translators.log_critical
|
_LC = _translators.log_critical
|
||||||
|
|
||||||
|
|
||||||
|
def lazy_translation_enabled():
|
||||||
|
return _lazy.USE_LAZY
|
||||||
|
|
||||||
|
|
||||||
def get_available_languages():
|
def get_available_languages():
|
||||||
return oslo_i18n.get_available_languages(DOMAIN)
|
return oslo_i18n.get_available_languages(DOMAIN)
|
||||||
|
@ -28,6 +28,7 @@ import prettytable as ptable
|
|||||||
from six.moves import input
|
from six.moves import input
|
||||||
|
|
||||||
from watcher._i18n import _, _LI
|
from watcher._i18n import _, _LI
|
||||||
|
from watcher._i18n import lazy_translation_enabled
|
||||||
from watcher.common import context
|
from watcher.common import context
|
||||||
from watcher.common import exception
|
from watcher.common import exception
|
||||||
from watcher.common import utils
|
from watcher.common import utils
|
||||||
@ -56,11 +57,11 @@ class WatcherObjectsMap(object):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
for attr_name in self.__class__.keys():
|
for attr_name in self.keys():
|
||||||
setattr(self, attr_name, [])
|
setattr(self, attr_name, [])
|
||||||
|
|
||||||
def values(self):
|
def values(self):
|
||||||
return (getattr(self, key) for key in self.__class__.keys())
|
return (getattr(self, key) for key in self.keys())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def keys(cls):
|
def keys(cls):
|
||||||
@ -100,8 +101,13 @@ class WatcherObjectsMap(object):
|
|||||||
def get_count_table(self):
|
def get_count_table(self):
|
||||||
headers = list(self.keymap.values())
|
headers = list(self.keymap.values())
|
||||||
headers.append(_("Total")) # We also add a total count
|
headers.append(_("Total")) # We also add a total count
|
||||||
|
translated_headers = [
|
||||||
|
h.translate() if lazy_translation_enabled() else h
|
||||||
|
for h in headers
|
||||||
|
]
|
||||||
|
|
||||||
counters = [len(cat_vals) for cat_vals in self.values()] + [len(self)]
|
counters = [len(cat_vals) for cat_vals in self.values()] + [len(self)]
|
||||||
table = ptable.PrettyTable(field_names=headers)
|
table = ptable.PrettyTable(field_names=translated_headers)
|
||||||
table.add_row(counters)
|
table.add_row(counters)
|
||||||
return table.get_string()
|
return table.get_string()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user