fix(spp_programs): locale-aware total_amount_in_words (#236)#300
fix(spp_programs): locale-aware total_amount_in_words (#236)#300Tarekchehahde wants to merge 1 commit into
Conversation
…P#236) Derive num2words language from env context or user lang instead of hardcoding English; fall back to en for unsupported locales. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request introduces localization support for converting total amounts into words using the num2words library, falling back to English if the requested language is not supported, and adds a corresponding test case for French. The reviewer suggested improving the language resolution logic to try the full language code (preserving regional dialects like pt_BR) before falling back to the base language code and finally English.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| lang_code = (self.env.context.get("lang") or self.env.user.lang or "en_US").split("_")[0] | ||
| try: | ||
| amount_in_words = num2words(record.total_amount, lang=lang_code).title() | ||
| except NotImplementedError: | ||
| amount_in_words = num2words(record.total_amount, lang="en").title() | ||
| record.total_amount_in_words = f"{amount_in_words} {record.currency_id.name}" |
There was a problem hiding this comment.
By immediately splitting the language code on _ (e.g., converting pt_BR to pt), regional dialects supported by num2words (such as Brazilian Portuguese pt_BR or British English en_GB) are lost, falling back to the generic base language.
A more robust approach is to attempt translation using the full language code first, then fall back to the base language code (split by _), and finally fall back to English (en) if neither is supported.
| lang_code = (self.env.context.get("lang") or self.env.user.lang or "en_US").split("_")[0] | |
| try: | |
| amount_in_words = num2words(record.total_amount, lang=lang_code).title() | |
| except NotImplementedError: | |
| amount_in_words = num2words(record.total_amount, lang="en").title() | |
| record.total_amount_in_words = f"{amount_in_words} {record.currency_id.name}" | |
| lang_code = self.env.context.get("lang") or self.env.user.lang or "en_US" | |
| for lang in (lang_code, lang_code.split("_")[0], "en"): | |
| try: | |
| amount_in_words = num2words(record.total_amount, lang=lang).title() | |
| break | |
| except NotImplementedError: | |
| continue | |
| record.total_amount_in_words = f"{amount_in_words} {record.currency_id.name}" |
Summary
env.context['lang']orenv.user.lang(withenfallback) fornum2wordsin_compute_total_amount_in_words.test_total_amount_in_wordsto assert French output underfr_FRcontext.Test plan
./spp test spp_programs—test_total_amount_in_wordsfr_FR, confirm amount-in-words renders in FrenchFixes #236
Made with Cursor