-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit and compound unit formatting #369
Conversation
Current coverage is
|
|
||
for unit in elem.findall('compoundUnit'): | ||
unit_type = unit.attrib['type'] | ||
box = "%s:%s" % (unit_type, unit_length_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why the original implementation uses string concatenation instead of nested dicts (eg date formats)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,239 @@ | |||
# -- encoding: UTF-8 -- | |||
|
|||
from babel._compat import Decimal, string_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains unused source code.
PyUnusedCodeBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/units.py
+++ b/babel/units.py
@@ -1,6 +1,7 @@
# -- encoding: UTF-8 --
-from babel._compat import Decimal, string_types
+from babel._compat import Decimal
+from babel._compat import string_types
from babel.core import Locale
from babel.numbers import format_decimal, LC_NUMERIC
(Instead of colon-separated flat dicts.) This should not be a breaking change, unless someone has used the private API `l._data["unit_patterns"]`.
* babel.units.format_unit * babel.units.format_compound_unit * babel.units.get_unit_name
c9dc208
to
ca9dede
Compare
unit_patterns = locale._data["unit_patterns"][q_unit].get(length, {}) | ||
formatted_value = format_decimal(value, format, locale) | ||
plural_form = locale.plural_form(value) | ||
if plural_form in unit_patterns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLDR here casually mentions length fallbacks (at least that's how I interpreted it here). It'd be awesome to see it here, I don't think it would be that difficult to add an extra iteration through a hardcoded, ordered list of length strings. If it's gross, feel free to punt.
http://www.unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
Ow, my head. Yours must hurt more. ;) |
Looks good, push! |
Ignoring the single Travis failure; it's one of those split-second unluckinesses. |
No description provided.