diff --git a/sui/core/build.go b/sui/core/build.go index 0b28cbd4..f1efafaa 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -669,7 +669,7 @@ func (page *Page) translateNode(node *html.Node, sequence *int) ([]Translation, parentSel.SetAttr("s:trans-node", key) *sequence = *sequence + 1 } - parentSel.RemoveAttr("s:trans") + parentSel.SetAttr("s:trans-escape", "true") } if _, has := parentSel.Attr("s:trans-text"); has { @@ -682,7 +682,6 @@ func (page *Page) translateNode(node *html.Node, sequence *int) ([]Translation, if len(keys) > 0 { raw := strings.Join(keys, ",") parentSel.SetAttr("s:trans-text", raw) - parentSel.RemoveAttr("s:trans") translations = append(translations, trans...) } break diff --git a/sui/core/parser.go b/sui/core/parser.go index d35b19b1..48329fe6 100644 --- a/sui/core/parser.go +++ b/sui/core/parser.go @@ -311,9 +311,10 @@ func (parser *TemplateParser) transElementNode(sel *goquery.Selection) { } // Escape the text - if _, exists := sel.Attr("s:trans-node"); exists { - content := parser.escapeText(strings.TrimSpace(sel.Text())) - sel.SetText(content) + if _, exists := sel.Attr("s:trans-escape"); exists { + html, _ := sel.Html() + html = parser.escapeText(html) + sel.SetHtml(html) } // Translate the attributes @@ -378,9 +379,19 @@ func (parser *TemplateParser) escape(value string) string { if strings.HasPrefix(value, "':::") { return "'::" + strings.TrimPrefix(value, "':::") } + + if strings.HasPrefix(value, "':::") { + return "'::" + strings.TrimPrefix(value, "':::") + } + if strings.HasPrefix(value, "\":::") { return "\"::" + strings.TrimPrefix(value, "\":::") } + + if strings.HasPrefix(value, "":::") { + return ""::" + strings.TrimPrefix(value, "":::") + } + return value } @@ -390,7 +401,7 @@ func (parser *TemplateParser) transText(content string, keys []string) string { newContent := content for _, match := range matches { text := strings.TrimSpace(match[1]) - if strings.HasPrefix(text, "':::") || strings.HasPrefix(text, "\":::") { + if strings.HasPrefix(text, "':::") || strings.HasPrefix(text, "\":::") || strings.HasPrefix(text, "':::") || strings.HasPrefix(text, "":::") { escaped := parser.escape(text) newContent = strings.Replace(newContent, text, escaped, 1) continue