fix: Escape translation variables in SUI page parser
This commit is contained in:
parent
2966256ad6
commit
55e3a2b4dd
2 changed files with 16 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue