feat(form-decompile,form-compile): мультиязычный текст (кластер I)

БАГ: Emit-MLText стрингифицировал мультиязычный объект {ru,en} →
<v8:content>@{ru=…; en=…}</v8:content> (мусор). ERP — двуязычная конфигурация,
поэтому это доминирующий пробел раундтрипа (item/content/lang).

- compiler PS1+PY: Emit-MLItems/emit_ml_items — по <v8:item> на язык; все
  вызывающие (Title/ToolTip/InputHint/реквизиты/колонки/команды/форма + Emit-Label)
  передают сырой объект вместо стрингификации. choice presentation уже был мультиязычен.
- decompiler уже давал {ru,en}; убран мёртвый titleFormatted (компилятор выводит formatted из hyperlink).
- docs/form-dsl-spec: title/tooltip/inputHint принимают объект {ru,en,…}.
- tests: groups (title {ru,en}) сертифицирован в 1С.

Эффект (220 форм 2.17): item 3909→1475, content 3193→737, lang 1861→635. Регресс 32/32 PS1+PY.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-06-04 21:28:53 +03:00
parent b4fc9bf42c
commit 3b0061c8a0
6 changed files with 72 additions and 44 deletions
@@ -1,4 +1,4 @@
# form-compile v1.30 — Compile 1C managed form from JSON or object metadata # form-compile v1.31 — Compile 1C managed form from JSON or object metadata
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
param( param(
[string]$JsonPath, [string]$JsonPath,
@@ -1521,13 +1521,26 @@ function Esc-Xml {
# --- 4. Multilang helper --- # --- 4. Multilang helper ---
# Эмитит <v8:item> для значения: строка → один ru-элемент; объект {lang:text} → по элементу на язык.
function Emit-MLItems {
param($val, [string]$indent)
if ($val -is [System.Collections.IDictionary]) {
foreach ($k in $val.Keys) {
X "$indent<v8:item>"; X "$indent`t<v8:lang>$k</v8:lang>"; X "$indent`t<v8:content>$(Esc-Xml "$($val[$k])")</v8:content>"; X "$indent</v8:item>"
}
} elseif ($val -is [System.Management.Automation.PSCustomObject]) {
foreach ($p in $val.PSObject.Properties) {
X "$indent<v8:item>"; X "$indent`t<v8:lang>$($p.Name)</v8:lang>"; X "$indent`t<v8:content>$(Esc-Xml "$($p.Value)")</v8:content>"; X "$indent</v8:item>"
}
} else {
X "$indent<v8:item>"; X "$indent`t<v8:lang>ru</v8:lang>"; X "$indent`t<v8:content>$(Esc-Xml "$val")</v8:content>"; X "$indent</v8:item>"
}
}
function Emit-MLText { function Emit-MLText {
param([string]$tag, [string]$text, [string]$indent) param([string]$tag, $text, [string]$indent)
X "$indent<$tag>" X "$indent<$tag>"
X "$indent`t<v8:item>" Emit-MLItems -val $text -indent "$indent`t"
X "$indent`t`t<v8:lang>ru</v8:lang>"
X "$indent`t`t<v8:content>$(Esc-Xml $text)</v8:content>"
X "$indent`t</v8:item>"
X "$indent</$tag>" X "$indent</$tag>"
} }
@@ -2045,9 +2058,9 @@ function Emit-Title {
param($el, [string]$name, [string]$indent, [switch]$auto) param($el, [string]$name, [string]$indent, [switch]$auto)
$hasKey = $null -ne $el.PSObject.Properties['title'] $hasKey = $null -ne $el.PSObject.Properties['title']
if ($hasKey) { if ($hasKey) {
if ($el.title) { Emit-MLText -tag "Title" -text "$($el.title)" -indent $indent } if ($el.title) { Emit-MLText -tag "Title" -text $el.title -indent $indent }
} elseif ($auto -and $name) { } elseif ($auto -and $name) {
Emit-MLText -tag "Title" -text "$(Title-FromName -name $name)" -indent $indent Emit-MLText -tag "Title" -text (Title-FromName -name $name) -indent $indent
} }
} }
@@ -2215,7 +2228,7 @@ function Emit-Input {
Emit-Layout -el $el -indent $inner -multiLineDefault ([bool]($el.multiLine -eq $true)) Emit-Layout -el $el -indent $inner -multiLineDefault ([bool]($el.multiLine -eq $true))
if ($el.inputHint) { if ($el.inputHint) {
Emit-MLText -tag "InputHint" -text "$($el.inputHint)" -indent $inner Emit-MLText -tag "InputHint" -text $el.inputHint -indent $inner
} }
# Companions # Companions
@@ -2476,14 +2489,11 @@ function Emit-Label {
$inner = "$indent`t" $inner = "$indent`t"
$hasTitleKey = $null -ne $el.PSObject.Properties['title'] $hasTitleKey = $null -ne $el.PSObject.Properties['title']
$labelTitle = if ($hasTitleKey) { "$($el.title)" } else { Title-FromName -name $name } $labelTitle = if ($hasTitleKey) { $el.title } else { Title-FromName -name $name }
if ($labelTitle) { if ($labelTitle) {
$formatted = if ($el.hyperlink -eq $true) { "true" } else { "false" } $formatted = if ($el.hyperlink -eq $true) { "true" } else { "false" }
X "$inner<Title formatted=`"$formatted`">" X "$inner<Title formatted=`"$formatted`">"
X "$inner`t<v8:item>" Emit-MLItems -val $labelTitle -indent "$inner`t"
X "$inner`t`t<v8:lang>ru</v8:lang>"
X "$inner`t`t<v8:content>$(Esc-Xml "$labelTitle")</v8:content>"
X "$inner`t</v8:item>"
X "$inner</Title>" X "$inner</Title>"
} }
@@ -2937,9 +2947,9 @@ function Emit-Attributes {
X "$indent`t<Attribute name=`"$attrName`" id=`"$attrId`">" X "$indent`t<Attribute name=`"$attrName`" id=`"$attrId`">"
$inner = "$indent`t`t" $inner = "$indent`t`t"
$attrTitle = if ($attr.title) { "$($attr.title)" } elseif ($attr.main -ne $true) { Title-FromName -name $attrName } else { '' } $attrTitle = if ($attr.title) { $attr.title } elseif ($attr.main -ne $true) { Title-FromName -name $attrName } else { '' }
if ($attrTitle) { if ($attrTitle) {
Emit-MLText -tag "Title" -text "$attrTitle" -indent $inner Emit-MLText -tag "Title" -text $attrTitle -indent $inner
} }
# Type # Type
@@ -2970,7 +2980,7 @@ function Emit-Attributes {
$colId = New-Id $colId = New-Id
X "$inner`t<Column name=`"$($col.name)`" id=`"$colId`">" X "$inner`t<Column name=`"$($col.name)`" id=`"$colId`">"
if ($col.title) { if ($col.title) {
Emit-MLText -tag "Title" -text "$($col.title)" -indent "$inner`t`t" Emit-MLText -tag "Title" -text $col.title -indent "$inner`t`t"
} }
Emit-Type -typeStr "$($col.type)" -indent "$inner`t`t" Emit-Type -typeStr "$($col.type)" -indent "$inner`t`t"
X "$inner`t</Column>" X "$inner`t</Column>"
@@ -3031,13 +3041,13 @@ function Emit-Commands {
X "$indent`t<Command name=`"$($cmd.name)`" id=`"$cmdId`">" X "$indent`t<Command name=`"$($cmd.name)`" id=`"$cmdId`">"
$inner = "$indent`t`t" $inner = "$indent`t`t"
$cmdTitle = if ($cmd.title) { "$($cmd.title)" } else { Title-FromName -name "$($cmd.name)" } $cmdTitle = if ($cmd.title) { $cmd.title } else { Title-FromName -name "$($cmd.name)" }
if ($cmdTitle) { if ($cmdTitle) {
Emit-MLText -tag "Title" -text "$cmdTitle" -indent $inner Emit-MLText -tag "Title" -text $cmdTitle -indent $inner
} }
if ($cmd.tooltip) { if ($cmd.tooltip) {
Emit-MLText -tag "ToolTip" -text "$($cmd.tooltip)" -indent $inner Emit-MLText -tag "ToolTip" -text $cmd.tooltip -indent $inner
} }
if ($cmd.action) { if ($cmd.action) {
@@ -3289,7 +3299,7 @@ function Compute-MainAcbAutofill {
# Title # Title
if ($def.title) { if ($def.title) {
Emit-MLText -tag "Title" -text "$($def.title)" -indent "`t" Emit-MLText -tag "Title" -text $def.title -indent "`t"
} }
# Header # Header
@@ -3312,7 +3322,7 @@ if (-not $formTitle -and $def.properties -and $def.properties.title) {
$formTitle = $def.properties.title $formTitle = $def.properties.title
} }
if ($formTitle) { if ($formTitle) {
Emit-MLText -tag "Title" -text "$formTitle" -indent "`t" Emit-MLText -tag "Title" -text $formTitle -indent "`t"
} }
# 12b. Properties (skip 'title' — handled above as multilingual) # 12b. Properties (skip 'title' — handled above as multilingual)
@@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# form-compile v1.30 — Compile 1C managed form from JSON or object metadata # form-compile v1.31 — Compile 1C managed form from JSON or object metadata
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import argparse import argparse
import copy import copy
@@ -1254,15 +1254,27 @@ def esc_xml(s):
return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;') return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;')
def emit_ml_items(lines, indent, val):
# строка → один ru-элемент; объект {lang: text} → по элементу на язык
if isinstance(val, dict):
for k, v in val.items():
lines.append(f"{indent}<v8:item>")
lines.append(f"{indent}\t<v8:lang>{k}</v8:lang>")
lines.append(f"{indent}\t<v8:content>{esc_xml(str(v))}</v8:content>")
lines.append(f"{indent}</v8:item>")
else:
lines.append(f"{indent}<v8:item>")
lines.append(f"{indent}\t<v8:lang>ru</v8:lang>")
lines.append(f"{indent}\t<v8:content>{esc_xml(str(val))}</v8:content>")
lines.append(f"{indent}</v8:item>")
def emit_mltext(lines, indent, tag, text): def emit_mltext(lines, indent, tag, text):
if not text: if not text:
lines.append(f"{indent}<{tag}/>") lines.append(f"{indent}<{tag}/>")
return return
lines.append(f"{indent}<{tag}>") lines.append(f"{indent}<{tag}>")
lines.append(f"{indent}\t<v8:item>") emit_ml_items(lines, f"{indent}\t", text)
lines.append(f"{indent}\t\t<v8:lang>ru</v8:lang>")
lines.append(f"{indent}\t\t<v8:content>{esc_xml(text)}</v8:content>")
lines.append(f"{indent}\t</v8:item>")
lines.append(f"{indent}</{tag}>") lines.append(f"{indent}</{tag}>")
@@ -1630,7 +1642,7 @@ def emit_title(lines, el, name, indent, auto=False):
# Явный title "" (или None) → подавить. Явный непустой → как есть. # Явный title "" (или None) → подавить. Явный непустой → как есть.
if 'title' in el: if 'title' in el:
if el.get('title'): if el.get('title'):
emit_mltext(lines, indent, 'Title', str(el['title'])) emit_mltext(lines, indent, 'Title', el['title'])
elif auto and name: elif auto and name:
emit_mltext(lines, indent, 'Title', title_from_name(name)) emit_mltext(lines, indent, 'Title', title_from_name(name))
@@ -2020,7 +2032,7 @@ def emit_input(lines, el, name, eid, indent):
emit_layout(lines, el, inner, multi_line_default=(el.get('multiLine') is True)) emit_layout(lines, el, inner, multi_line_default=(el.get('multiLine') is True))
if el.get('inputHint'): if el.get('inputHint'):
emit_mltext(lines, inner, 'InputHint', str(el['inputHint'])) emit_mltext(lines, inner, 'InputHint', el['inputHint'])
# Companions # Companions
emit_companion(lines, 'ContextMenu', f'{name}\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435\u041c\u0435\u043d\u044e', inner) emit_companion(lines, 'ContextMenu', f'{name}\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435\u041c\u0435\u043d\u044e', inner)
@@ -2127,14 +2139,11 @@ def emit_label(lines, el, name, eid, indent):
lines.append(f'{indent}<LabelDecoration name="{name}" id="{eid}">') lines.append(f'{indent}<LabelDecoration name="{name}" id="{eid}">')
inner = f'{indent}\t' inner = f'{indent}\t'
label_title = str(el['title'] or '') if 'title' in el else title_from_name(name) label_title = el['title'] if 'title' in el else title_from_name(name)
if label_title: if label_title:
formatted = 'true' if el.get('hyperlink') is True else 'false' formatted = 'true' if el.get('hyperlink') is True else 'false'
lines.append(f'{inner}<Title formatted="{formatted}">') lines.append(f'{inner}<Title formatted="{formatted}">')
lines.append(f'{inner}\t<v8:item>') emit_ml_items(lines, f'{inner}\t', label_title)
lines.append(f'{inner}\t\t<v8:lang>ru</v8:lang>')
lines.append(f'{inner}\t\t<v8:content>{esc_xml(str(label_title))}</v8:content>')
lines.append(f'{inner}\t</v8:item>')
lines.append(f'{inner}</Title>') lines.append(f'{inner}</Title>')
emit_common_flags(lines, el, inner) emit_common_flags(lines, el, inner)
@@ -2559,7 +2568,7 @@ def emit_attributes(lines, attrs, indent):
if not attr_title and attr.get('main') is not True: if not attr_title and attr.get('main') is not True:
attr_title = title_from_name(attr_name) attr_title = title_from_name(attr_name)
if attr_title: if attr_title:
emit_mltext(lines, inner, 'Title', str(attr_title)) emit_mltext(lines, inner, 'Title', attr_title)
# Type # Type
if attr.get('type'): if attr.get('type'):
@@ -2585,7 +2594,7 @@ def emit_attributes(lines, attrs, indent):
col_id = new_id() col_id = new_id()
lines.append(f'{inner}\t<Column name="{col["name"]}" id="{col_id}">') lines.append(f'{inner}\t<Column name="{col["name"]}" id="{col_id}">')
if col.get('title'): if col.get('title'):
emit_mltext(lines, f'{inner}\t\t', 'Title', str(col['title'])) emit_mltext(lines, f'{inner}\t\t', 'Title', col['title'])
emit_type(lines, str(col.get('type', '')), f'{inner}\t\t') emit_type(lines, str(col.get('type', '')), f'{inner}\t\t')
lines.append(f'{inner}\t</Column>') lines.append(f'{inner}\t</Column>')
lines.append(f'{inner}</Columns>') lines.append(f'{inner}</Columns>')
@@ -2641,10 +2650,10 @@ def emit_commands(lines, cmds, indent):
cmd_title = cmd.get('title') or title_from_name(str(cmd['name'])) cmd_title = cmd.get('title') or title_from_name(str(cmd['name']))
if cmd_title: if cmd_title:
emit_mltext(lines, inner, 'Title', str(cmd_title)) emit_mltext(lines, inner, 'Title', cmd_title)
if cmd.get('tooltip'): if cmd.get('tooltip'):
emit_mltext(lines, inner, 'ToolTip', str(cmd['tooltip'])) emit_mltext(lines, inner, 'ToolTip', cmd['tooltip'])
if cmd.get('action'): if cmd.get('action'):
lines.append(f'{inner}<Action>{cmd["action"]}</Action>') lines.append(f'{inner}<Action>{cmd["action"]}</Action>')
@@ -3106,7 +3115,7 @@ def main():
if not form_title and defn.get('properties') and defn['properties'].get('title'): if not form_title and defn.get('properties') and defn['properties'].get('title'):
form_title = defn['properties']['title'] form_title = defn['properties']['title']
if form_title: if form_title:
emit_mltext(lines, '\t', 'Title', str(form_title)) emit_mltext(lines, '\t', 'Title', form_title)
# Properties (skip 'title' — handled above) # Properties (skip 'title' — handled above)
# When form-level Title is set, default autoTitle=false (≈95% of ERP forms do this; # When form-level Title is set, default autoTitle=false (≈95% of ERP forms do this;
@@ -1,4 +1,4 @@
# form-decompile v0.8 — Decompile 1C managed Form.xml to JSON DSL (draft) # form-decompile v0.9 — Decompile 1C managed Form.xml to JSON DSL (draft)
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
# ВНИМАНИЕ: раундтрип не гарантируется. Навык исключён из авто-использования моделью. # ВНИМАНИЕ: раундтрип не гарантируется. Навык исключён из авто-использования моделью.
param( param(
@@ -258,8 +258,7 @@ function Add-CommonProps {
if ($titleNode) { if ($titleNode) {
$t = Get-LangText $titleNode $t = Get-LangText $titleNode
if ($null -ne $t) { $obj['title'] = $t } if ($null -ne $t) { $obj['title'] = $t }
$fmt = $titleNode.GetAttribute("formatted") # formatted у LabelDecoration выводится компилятором из hyperlink — отдельный ключ не нужен (#16 хвост)
if ($fmt -eq 'true') { $obj['titleFormatted'] = $true } elseif ($fmt -eq 'false') { $obj['titleFormatted'] = $false }
} }
$ev = Get-Events $node $elName $ev = Get-Events $node $elName
if ($ev) { if ($ev) {
+1 -1
View File
@@ -110,7 +110,7 @@
| Свойство | Тип | Описание | | Свойство | Тип | Описание |
|----------|-----|----------| |----------|-----|----------|
| `name` | string | Имя элемента (по умолчанию — из значения ключа типа) | | `name` | string | Имя элемента (по умолчанию — из значения ключа типа) |
| `title` | string | Заголовок. **Нет ключа** → авто-вывод из имени (для page/popup/label и непривязанных полей/кнопок). **`""`** → подавить (заголовок не выводится). Непустая строка → как есть | | `title` | string/object | Заголовок. **Нет ключа** → авто-вывод из имени (для page/popup/label и непривязанных полей/кнопок). **`""`** → подавить (заголовок не выводится). Строка → ru. Объект `{ "ru": "…", "en": "…" }` → мультиязычный (по `<v8:item>` на язык). Так же `tooltip`/`inputHint`/`title` команд/реквизитов/колонок |
| `hidden` | bool | `true``<Visible>false</Visible>` | | `hidden` | bool | `true``<Visible>false</Visible>` |
| `disabled` | bool | `true``<Enabled>false</Enabled>` | | `disabled` | bool | `true``<Enabled>false</Enabled>` |
| `readOnly` | bool | `true``<ReadOnly>true</ReadOnly>` | | `readOnly` | bool | `true``<ReadOnly>true</ReadOnly>` |
+1 -1
View File
@@ -22,7 +22,7 @@
{ "input": "Поле2", "path": "Поле2", "title": "Поле 2" }, { "input": "Поле2", "path": "Поле2", "title": "Поле 2" },
{ "labelField": "Метка", "path": "Поле1", "groupVerticalAlign": "Center" } { "labelField": "Метка", "path": "Поле1", "groupVerticalAlign": "Center" }
]}, ]},
{ "group": "vertical", "name": "ГруппаПодвал", "children": [ { "group": "vertical", "name": "ГруппаПодвал", "title": { "ru": "Подвал", "en": "Footer" }, "children": [
{ "input": "Поле3", "path": "Поле3", "title": "Поле 3" } { "input": "Поле3", "path": "Поле3", "title": "Поле 3" }
]} ]}
], ],
@@ -59,6 +59,16 @@
</ChildItems> </ChildItems>
</UsualGroup> </UsualGroup>
<UsualGroup name="ГруппаПодвал" id="13"> <UsualGroup name="ГруппаПодвал" id="13">
<Title>
<v8:item>
<v8:lang>ru</v8:lang>
<v8:content>Подвал</v8:content>
</v8:item>
<v8:item>
<v8:lang>en</v8:lang>
<v8:content>Footer</v8:content>
</v8:item>
</Title>
<Group>Vertical</Group> <Group>Vertical</Group>
<ExtendedTooltip name="ГруппаПодвалРасширеннаяПодсказка" id="14"/> <ExtendedTooltip name="ГруппаПодвалРасширеннаяПодсказка" id="14"/>
<ChildItems> <ChildItems>