mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-06-14 18:04:58 +03:00
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:
@@ -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
|
||||
param(
|
||||
[string]$JsonPath,
|
||||
@@ -1521,13 +1521,26 @@ function Esc-Xml {
|
||||
|
||||
# --- 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 {
|
||||
param([string]$tag, [string]$text, [string]$indent)
|
||||
param([string]$tag, $text, [string]$indent)
|
||||
X "$indent<$tag>"
|
||||
X "$indent`t<v8:item>"
|
||||
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>"
|
||||
Emit-MLItems -val $text -indent "$indent`t"
|
||||
X "$indent</$tag>"
|
||||
}
|
||||
|
||||
@@ -2045,9 +2058,9 @@ function Emit-Title {
|
||||
param($el, [string]$name, [string]$indent, [switch]$auto)
|
||||
$hasKey = $null -ne $el.PSObject.Properties['title']
|
||||
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) {
|
||||
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))
|
||||
|
||||
if ($el.inputHint) {
|
||||
Emit-MLText -tag "InputHint" -text "$($el.inputHint)" -indent $inner
|
||||
Emit-MLText -tag "InputHint" -text $el.inputHint -indent $inner
|
||||
}
|
||||
|
||||
# Companions
|
||||
@@ -2476,14 +2489,11 @@ function Emit-Label {
|
||||
$inner = "$indent`t"
|
||||
|
||||
$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) {
|
||||
$formatted = if ($el.hyperlink -eq $true) { "true" } else { "false" }
|
||||
X "$inner<Title formatted=`"$formatted`">"
|
||||
X "$inner`t<v8:item>"
|
||||
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>"
|
||||
Emit-MLItems -val $labelTitle -indent "$inner`t"
|
||||
X "$inner</Title>"
|
||||
}
|
||||
|
||||
@@ -2937,9 +2947,9 @@ function Emit-Attributes {
|
||||
X "$indent`t<Attribute name=`"$attrName`" id=`"$attrId`">"
|
||||
$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) {
|
||||
Emit-MLText -tag "Title" -text "$attrTitle" -indent $inner
|
||||
Emit-MLText -tag "Title" -text $attrTitle -indent $inner
|
||||
}
|
||||
|
||||
# Type
|
||||
@@ -2970,7 +2980,7 @@ function Emit-Attributes {
|
||||
$colId = New-Id
|
||||
X "$inner`t<Column name=`"$($col.name)`" id=`"$colId`">"
|
||||
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"
|
||||
X "$inner`t</Column>"
|
||||
@@ -3031,13 +3041,13 @@ function Emit-Commands {
|
||||
X "$indent`t<Command name=`"$($cmd.name)`" id=`"$cmdId`">"
|
||||
$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) {
|
||||
Emit-MLText -tag "Title" -text "$cmdTitle" -indent $inner
|
||||
Emit-MLText -tag "Title" -text $cmdTitle -indent $inner
|
||||
}
|
||||
|
||||
if ($cmd.tooltip) {
|
||||
Emit-MLText -tag "ToolTip" -text "$($cmd.tooltip)" -indent $inner
|
||||
Emit-MLText -tag "ToolTip" -text $cmd.tooltip -indent $inner
|
||||
}
|
||||
|
||||
if ($cmd.action) {
|
||||
@@ -3289,7 +3299,7 @@ function Compute-MainAcbAutofill {
|
||||
|
||||
# Title
|
||||
if ($def.title) {
|
||||
Emit-MLText -tag "Title" -text "$($def.title)" -indent "`t"
|
||||
Emit-MLText -tag "Title" -text $def.title -indent "`t"
|
||||
}
|
||||
|
||||
# Header
|
||||
@@ -3312,7 +3322,7 @@ if (-not $formTitle -and $def.properties -and $def.properties.title) {
|
||||
$formTitle = $def.properties.title
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
import argparse
|
||||
import copy
|
||||
@@ -1254,15 +1254,27 @@ def esc_xml(s):
|
||||
return s.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"')
|
||||
|
||||
|
||||
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):
|
||||
if not text:
|
||||
lines.append(f"{indent}<{tag}/>")
|
||||
return
|
||||
lines.append(f"{indent}<{tag}>")
|
||||
lines.append(f"{indent}\t<v8:item>")
|
||||
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>")
|
||||
emit_ml_items(lines, f"{indent}\t", text)
|
||||
lines.append(f"{indent}</{tag}>")
|
||||
|
||||
|
||||
@@ -1630,7 +1642,7 @@ def emit_title(lines, el, name, indent, auto=False):
|
||||
# Явный title "" (или None) → подавить. Явный непустой → как есть.
|
||||
if 'title' in el:
|
||||
if el.get('title'):
|
||||
emit_mltext(lines, indent, 'Title', str(el['title']))
|
||||
emit_mltext(lines, indent, 'Title', el['title'])
|
||||
elif auto and 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))
|
||||
|
||||
if el.get('inputHint'):
|
||||
emit_mltext(lines, inner, 'InputHint', str(el['inputHint']))
|
||||
emit_mltext(lines, inner, 'InputHint', el['inputHint'])
|
||||
|
||||
# Companions
|
||||
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}">')
|
||||
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:
|
||||
formatted = 'true' if el.get('hyperlink') is True else 'false'
|
||||
lines.append(f'{inner}<Title formatted="{formatted}">')
|
||||
lines.append(f'{inner}\t<v8:item>')
|
||||
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>')
|
||||
emit_ml_items(lines, f'{inner}\t', label_title)
|
||||
lines.append(f'{inner}</Title>')
|
||||
|
||||
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:
|
||||
attr_title = title_from_name(attr_name)
|
||||
if attr_title:
|
||||
emit_mltext(lines, inner, 'Title', str(attr_title))
|
||||
emit_mltext(lines, inner, 'Title', attr_title)
|
||||
|
||||
# Type
|
||||
if attr.get('type'):
|
||||
@@ -2585,7 +2594,7 @@ def emit_attributes(lines, attrs, indent):
|
||||
col_id = new_id()
|
||||
lines.append(f'{inner}\t<Column name="{col["name"]}" id="{col_id}">')
|
||||
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')
|
||||
lines.append(f'{inner}\t</Column>')
|
||||
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']))
|
||||
if cmd_title:
|
||||
emit_mltext(lines, inner, 'Title', str(cmd_title))
|
||||
emit_mltext(lines, inner, 'Title', cmd_title)
|
||||
|
||||
if cmd.get('tooltip'):
|
||||
emit_mltext(lines, inner, 'ToolTip', str(cmd['tooltip']))
|
||||
emit_mltext(lines, inner, 'ToolTip', cmd['tooltip'])
|
||||
|
||||
if cmd.get('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'):
|
||||
form_title = defn['properties']['title']
|
||||
if form_title:
|
||||
emit_mltext(lines, '\t', 'Title', str(form_title))
|
||||
emit_mltext(lines, '\t', 'Title', form_title)
|
||||
|
||||
# Properties (skip 'title' — handled above)
|
||||
# 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
|
||||
# ВНИМАНИЕ: раундтрип не гарантируется. Навык исключён из авто-использования моделью.
|
||||
param(
|
||||
@@ -258,8 +258,7 @@ function Add-CommonProps {
|
||||
if ($titleNode) {
|
||||
$t = Get-LangText $titleNode
|
||||
if ($null -ne $t) { $obj['title'] = $t }
|
||||
$fmt = $titleNode.GetAttribute("formatted")
|
||||
if ($fmt -eq 'true') { $obj['titleFormatted'] = $true } elseif ($fmt -eq 'false') { $obj['titleFormatted'] = $false }
|
||||
# formatted у LabelDecoration выводится компилятором из hyperlink — отдельный ключ не нужен (#16 хвост)
|
||||
}
|
||||
$ev = Get-Events $node $elName
|
||||
if ($ev) {
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
| Свойство | Тип | Описание |
|
||||
|----------|-----|----------|
|
||||
| `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>` |
|
||||
| `disabled` | bool | `true` → `<Enabled>false</Enabled>` |
|
||||
| `readOnly` | bool | `true` → `<ReadOnly>true</ReadOnly>` |
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
{ "input": "Поле2", "path": "Поле2", "title": "Поле 2" },
|
||||
{ "labelField": "Метка", "path": "Поле1", "groupVerticalAlign": "Center" }
|
||||
]},
|
||||
{ "group": "vertical", "name": "ГруппаПодвал", "children": [
|
||||
{ "group": "vertical", "name": "ГруппаПодвал", "title": { "ru": "Подвал", "en": "Footer" }, "children": [
|
||||
{ "input": "Поле3", "path": "Поле3", "title": "Поле 3" }
|
||||
]}
|
||||
],
|
||||
|
||||
+10
@@ -59,6 +59,16 @@
|
||||
</ChildItems>
|
||||
</UsualGroup>
|
||||
<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>
|
||||
<ExtendedTooltip name="ГруппаПодвалРасширеннаяПодсказка" id="14"/>
|
||||
<ChildItems>
|
||||
|
||||
Reference in New Issue
Block a user