# HG changeset patch # User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr> # Date 1601283023 -7200 # Mon Sep 28 10:50:23 2020 +0200 # Branch 11.0 # Node ID 2651c5a8904dd4630d14bf4ece91aa407a77e5f9 # Parent 4c6bf2470d3e3e9911583b5c5f266355cc8f3833 👕 black diff --git a/__manifest__.py b/__manifest__.py --- a/__manifest__.py +++ b/__manifest__.py @@ -18,20 +18,14 @@ ############################################################################## { - 'name': 'ICU Format', - 'summary': 'Format message using ICU', - 'version': '11.0.1.0', - 'category': 'Technical', - 'author': 'XCG Consulting', - 'website': 'http://odoo.consulting/', - 'license': 'AGPL-3', - 'depends': [ - 'base', - ], - 'external_dependencies': { - 'python': [ - 'PyICU', - ], - }, - 'installable': True, + "name": "ICU Format", + "summary": "Format message using ICU", + "version": "11.0.1.0", + "category": "Technical", + "author": "XCG Consulting", + "website": "http://odoo.consulting/", + "license": "AGPL-3", + "depends": ["base"], + "external_dependencies": {"python": ["PyICU"]}, + "installable": True, } diff --git a/icuformat.py b/icuformat.py --- a/icuformat.py +++ b/icuformat.py @@ -30,17 +30,15 @@ key_list.append(key) value_list.append(Formattable(value)) if not lang: - lang = 'en' + lang = "en" locale = Locale(lang) return MessageFormat(msg, locale).format(key_list, value_list) def _icuformat(self, msg: str, args: Dict[str, Union[int, str]]) -> str: return icuformat( - self.env.context.get('lang') or self.env.user.lang, - msg, - args, + self.env.context.get("lang") or self.env.user.lang, msg, args ) -setattr(BaseModel, 'icuformat', _icuformat) +setattr(BaseModel, "icuformat", _icuformat) diff --git a/tests/test_icuformat.py b/tests/test_icuformat.py --- a/tests/test_icuformat.py +++ b/tests/test_icuformat.py @@ -24,15 +24,15 @@ class Test(tests.TransactionCase): def test_simple(self): - msg = '{test}' - d = {'test': 'foobar'} - expected = 'foobar' - self.assertEqual(expected, icuformat('en', msg, d)) + msg = "{test}" + d = {"test": "foobar"} + expected = "foobar" + self.assertEqual(expected, icuformat("en", msg, d)) def test_nothing_to_format(self): - msg = 'test' + msg = "test" d = dict() - self.assertEqual(msg, icuformat('en', msg, d)) + self.assertEqual(msg, icuformat("en", msg, d)) def test_nested_plural_select(self): msg = ( @@ -58,11 +58,12 @@ "}}}" ) d = dict( - gender_of_host='female', + gender_of_host="female", num_guests=1005, - host='Ms. Marple', - guest='Robert') + host="Ms. Marple", + guest="Robert", + ) expected = ( - 'Ms. Marple invites Robert and 1,004 other people to her party.' + "Ms. Marple invites Robert and 1,004 other people to her party." ) - self.assertEqual(expected, icuformat('en', msg, d)) + self.assertEqual(expected, icuformat("en", msg, d))