| 1 | function _(txt: string, replace?: string[], context = null) { |
| 2 | if (!txt) return txt; |
| 3 | if (typeof txt != "string") return txt; |
| 4 | |
| 5 | let translated_text = ""; |
| 6 | |
| 7 | const key = txt; // txt.replace(/\n/g, ""); |
| 8 | if (window.frappe) { |
| 9 | if (context) { |
| 10 | translated_text = window.frappe._messages[`${key}:${context}`]; |
| 11 | } |
| 12 | |
| 13 | if (!translated_text) { |
| 14 | translated_text = window.frappe?._messages?.[key] || txt; |
| 15 | } |
| 16 | |
| 17 | } else { |
| 18 | translated_text = txt; |
| 19 | } |
| 20 | |
| 21 | if (replace && typeof replace === "object") { |
| 22 | translated_text = format(translated_text, replace); |
| 23 | } |
| 24 | return translated_text; |
| 25 | }; |
| 26 | |
| 27 | function format(str: string, args: string[]) { |
| 28 | if (str == undefined) return str; |