raha
April 7, 2025, 11:17am
1
How can I add the following text to the “Transaction” so that it get translated??
msg = f"Row #{row.idx}: Quality Inspection is required for Item {frappe.bold(row.item_code)}"
the following code doesn’t work.
Row #{0}: Quality Inspection is required for Item {1}
VINOTH
April 7, 2025, 11:20am
2
Hi @raha ,
If you want your message to be translatable in Frappe, don’t use f-strings. Instead, do this:
msg = _("Row #{0}: Quality Inspection is required for Item {1}").format(row.idx, frappe.bold(row.item_code))
This way, Frappe can pick up the string for translation.
Hope that helps!
raha
April 7, 2025, 11:25am
3
thanks.
It’s a system code and I don’t want to change the core code.
VINOTH
April 7, 2025, 11:30am
4
Ah, gotcha! If you don’t want to change the core code, just add a custom translation:
Go to Translations in the UI
Add:
Source Text: Row #{0}: Quality Inspection is required for Item {1}
Your translated text
Set the language
That way, you can translate it without touching the original code.
Let me know if you need help with that!
VINOTH
April 7, 2025, 11:50am
6
Are you getting any kind of errors?
raha
April 7, 2025, 11:56am
7
No, I don’t get any errors, but only this part of the code isn’t being translated. I’ve tested all the structures as well.