Skip to content

Commit

Permalink
[FR] Fix handling non-numeric values from the 'Unité' template (#1293)
Browse files Browse the repository at this point in the history
Fixes #1288.
  • Loading branch information
BoboTiG committed May 11, 2022
1 parent 0aa2f12 commit bca68f4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion wikidict/lang/fr/template_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,19 @@ def render_unite(tpl: str, parts: List[str], data: Dict[str, str]) -> str:
>>> # '1 234 567 890,12345678 ¤'
>>> render_unite("unité", ["1.30", "m"], defaultdict(str, {}))
'1,30 m'
>>> # Non-numeric value
>>> render_unite("unité", ["8 à 12", "cm"], defaultdict(str, {}))
'8 à 12 cm'
"""
from . import float_separator, thousands_separator

sep = "⋅"
phrase = number(parts.pop(0), float_separator, thousands_separator)
value = parts.pop(0)
try:
phrase = number(value, float_separator, thousands_separator)
except ValueError:
phrase = value
if data["e"]: # exposant
phrase += "×10" + superscript(data["e"])
if parts: # symbol
Expand Down

0 comments on commit bca68f4

Please sign in to comment.