|
44 | 44 | "19": "%", |
45 | 45 | } |
46 | 46 |
|
| 47 | +# Supported languages: English, German, French, and Spanish. |
| 48 | +VALID_BLACK_WORDS = ("black", "schwarz", "noir", "negra") |
| 49 | +VALID_CYAN_WORDS = ("cyan", "zyan", "cian") |
| 50 | +VALID_MAGENTA_WORDS = ("magenta",) |
| 51 | +VALID_YELLOW_WORDS = ("yellow", "gelb", "jaune", "amarilla") |
| 52 | + |
47 | 53 |
|
48 | 54 | Unit = NewType("Unit", str) |
49 | 55 |
|
@@ -106,19 +112,20 @@ def _get_supply_unit(raw_unit: str) -> Unit: |
106 | 112 | return Unit(unit) if unit in {"", "%"} else Unit(f" {unit}") |
107 | 113 |
|
108 | 114 |
|
109 | | -def _get_supply_color(raw_color: str) -> Color | None: |
| 115 | +def _get_supply_color(raw_color: str, raw_description: str) -> Color | None: |
110 | 116 | color = raw_color.lower() |
| 117 | + description = raw_description.lower() |
111 | 118 |
|
112 | | - if color == "black": |
| 119 | + if color == "black" or any(word in description for word in VALID_BLACK_WORDS): |
113 | 120 | return "black" |
114 | 121 |
|
115 | | - if color == "cyan": |
| 122 | + if color == "cyan" or any(word in description for word in VALID_CYAN_WORDS): |
116 | 123 | return "cyan" |
117 | 124 |
|
118 | | - if color == "magenta": |
| 125 | + if color == "magenta" or any(word in description for word in VALID_MAGENTA_WORDS): |
119 | 126 | return "magenta" |
120 | 127 |
|
121 | | - if color == "yellow": |
| 128 | + if color == "yellow" or any(word in description for word in VALID_YELLOW_WORDS): |
122 | 129 | return "yellow" |
123 | 130 |
|
124 | 131 | return None |
@@ -182,7 +189,7 @@ def parse_printer_supply(string_table: Sequence[StringTable]) -> Section: |
182 | 189 | raw_color = raw_color.rstrip("\0") |
183 | 190 |
|
184 | 191 | unit = _get_supply_unit(raw_unit) |
185 | | - color = _get_supply_color(raw_color) |
| 192 | + color = _get_supply_color(raw_color, description) |
186 | 193 | supply_class = _get_supply_class(raw_supply_class) |
187 | 194 |
|
188 | 195 | parsed[description] = PrinterSupply(unit, max_capacity, level, supply_class, color) |
|
0 commit comments