Merge pull request #27278 from shariquerik/translate-header-block

fix: header block is not translatable
This commit is contained in:
Shariq Ansari 2024-08-02 17:07:50 +05:30 committed by GitHub
commit 60cfeb0dee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -104,8 +104,16 @@ export default class Header extends Block {
this._data = this.normalizeData(data);
if (data.text !== undefined) {
let text = this._data.text || "";
let text = __(this._data.text) || "";
const contains_html_tag = /<[a-z][\s\S]*>/i.test(text);
// apply translation to header text
let div = document.createElement("div");
div.innerHTML = text;
let only_text = div.innerText;
only_text = frappe.utils.escape_html(only_text);
text = text.replace(only_text, __(only_text));
this._element.innerHTML = contains_html_tag
? text
: `<span class="h${this._settings.default_size}">${text}</span>`;