Ужесточены сценарии обновления перевода для AI-агента

This commit is contained in:
2026-04-09 16:03:02 +03:00
parent d048a33c55
commit 7f189aa741
4 changed files with 46 additions and 15 deletions

View File

@@ -80,9 +80,10 @@ ACTIONS:
plan: plan:
- run_translation:diff_sequentially - run_translation:diff_sequentially
- if_summary_has_no_missing_no_version_mismatch_no_stale_report_translation_up_to_date_and_stop - if_summary_has_no_missing_no_version_mismatch_no_stale_report_translation_up_to_date_and_stop
- if_diff_exists_stop_after_generating_build/translation-diff/candidates.json_until_prepared_edits_are_provided_explicitly
- review_build/translation-diff/candidates.json_before_apply - review_build/translation-diff/candidates.json_before_apply
- reuse_glossary_for_term_consistency_when_preparing_texts - reuse_glossary_for_term_consistency_when_preparing_texts
- run_translation:apply_only_after_candidate_texts_are_filled - run_translation:apply_only_after_candidate_texts_are_filled_and_explicit_edits_path_is_passed
checks: checks:
- xml_valid - xml_valid
- glossary_consistency - glossary_consistency

View File

@@ -51,6 +51,21 @@ function Get-ContentNodeMap {
return $map return $map
} }
function Assert-UniqueEditContentUid {
param(
[Parameter(Mandatory = $true)]
[System.Collections.Generic.HashSet[string]]$Seen,
[Parameter(Mandatory = $true)]
[string]$ContentUid,
[Parameter(Mandatory = $true)]
[string]$Section
)
if (-not $Seen.Add($ContentUid)) {
throw "Edits file contains duplicate contentuid '$ContentUid' in '$Section'."
}
}
$russianDocument = Read-XmlDocument -Path $RussianPath $russianDocument = Read-XmlDocument -Path $RussianPath
$temporaryRussianPath = "$($russianDocument.Path).tmp" $temporaryRussianPath = "$($russianDocument.Path).tmp"
$validateScriptPath = Join-Path $PSScriptRoot "validate-translation-xml.ps1" $validateScriptPath = Join-Path $PSScriptRoot "validate-translation-xml.ps1"
@@ -83,6 +98,7 @@ if ($null -eq $contentListNode) {
$nodeMap = Get-ContentNodeMap -Xml $russianDocument.Xml $nodeMap = Get-ContentNodeMap -Xml $russianDocument.Xml
$updatedEntries = New-Object System.Collections.Generic.List[string] $updatedEntries = New-Object System.Collections.Generic.List[string]
$addedEntries = New-Object System.Collections.Generic.List[string] $addedEntries = New-Object System.Collections.Generic.List[string]
$seenEditContentUids = [System.Collections.Generic.HashSet[string]]::new()
$updates = @() $updates = @()
if ($edits.PSObject.Properties.Name -contains "updates" -and $null -ne $edits.updates) { if ($edits.PSObject.Properties.Name -contains "updates" -and $null -ne $edits.updates) {
@@ -95,6 +111,8 @@ foreach ($edit in $updates) {
throw "Each update entry must contain non-empty 'contentuid'." throw "Each update entry must contain non-empty 'contentuid'."
} }
Assert-UniqueEditContentUid -Seen $seenEditContentUids -ContentUid $contentUid -Section "updates"
if (-not $nodeMap.ContainsKey($contentUid)) { if (-not $nodeMap.ContainsKey($contentUid)) {
throw "Target russian.xml does not contain contentuid '$contentUid' for update." throw "Target russian.xml does not contain contentuid '$contentUid' for update."
} }
@@ -105,6 +123,9 @@ foreach ($edit in $updates) {
} }
if ($edit.PSObject.Properties.Name -contains "text") { if ($edit.PSObject.Properties.Name -contains "text") {
if ([string]::IsNullOrWhiteSpace([string]$edit.text)) {
throw "Update entry '$contentUid' must contain non-empty 'text' when provided."
}
$node.InnerText = [string]$edit.text $node.InnerText = [string]$edit.text
} }
@@ -133,6 +154,8 @@ foreach ($edit in $adds) {
throw "Each add entry must contain non-empty 'contentuid'." throw "Each add entry must contain non-empty 'contentuid'."
} }
Assert-UniqueEditContentUid -Seen $seenEditContentUids -ContentUid $contentUid -Section "adds"
if ($nodeMap.ContainsKey($contentUid)) { if ($nodeMap.ContainsKey($contentUid)) {
throw "Target russian.xml already contains contentuid '$contentUid'; use 'updates' instead of 'adds'." throw "Target russian.xml already contains contentuid '$contentUid'; use 'updates' instead of 'adds'."
} }

View File

@@ -27,12 +27,21 @@ function Get-LocalizationEntries {
foreach ($node in $nodes) { foreach ($node in $nodes) {
$contentUid = [string]$node.GetAttribute("contentuid") $contentUid = [string]$node.GetAttribute("contentuid")
if ([string]::IsNullOrWhiteSpace($contentUid)) { if ([string]::IsNullOrWhiteSpace($contentUid)) {
continue throw "Localization XML contains a content node without 'contentuid': '$resolvedPath'."
}
if ($entries.ContainsKey($contentUid)) {
throw "Localization XML contains duplicate contentuid '$contentUid': '$resolvedPath'."
}
$version = [string]$node.GetAttribute("version")
if ([string]::IsNullOrWhiteSpace($version)) {
throw "Localization XML contains contentuid '$contentUid' with empty 'version': '$resolvedPath'."
} }
$entries[$contentUid] = [ordered]@{ $entries[$contentUid] = [ordered]@{
contentuid = $contentUid contentuid = $contentUid
version = [string]$node.GetAttribute("version") version = $version
text = [string]$node.InnerText text = [string]$node.InnerText
} }
} }
@@ -46,9 +55,6 @@ New-Item -ItemType Directory -Path $resolvedOutputDir -Force | Out-Null
$englishEntries = Get-LocalizationEntries -Path $EnglishPath $englishEntries = Get-LocalizationEntries -Path $EnglishPath
$russianEntries = Get-LocalizationEntries -Path $RussianPath $russianEntries = Get-LocalizationEntries -Path $RussianPath
$englishKeys = [System.Collections.Generic.HashSet[string]]::new([string[]]$englishEntries.Keys)
$russianKeys = [System.Collections.Generic.HashSet[string]]::new([string[]]$russianEntries.Keys)
$missingInRussian = New-Object System.Collections.Generic.List[object] $missingInRussian = New-Object System.Collections.Generic.List[object]
$versionMismatch = New-Object System.Collections.Generic.List[object] $versionMismatch = New-Object System.Collections.Generic.List[object]
$staleOnlyInRussian = New-Object System.Collections.Generic.List[object] $staleOnlyInRussian = New-Object System.Collections.Generic.List[object]
@@ -156,11 +162,11 @@ if ($isUpToDate) {
$mdLines += "Перевод уже актуален, дополнительные действия не требуются." $mdLines += "Перевод уже актуален, дополнительные действия не требуются."
} else { } else {
$mdLines += "" $mdLines += ""
$mdLines += "## Local workflow" $mdLines += "## Agent workflow"
$mdLines += "1. Update upstream cache: ``scripts/get-upstream-english.ps1``" $mdLines += "1. Refresh upstream cache: ``scripts/get-upstream-english.ps1``"
$mdLines += "2. Refresh diff: ``scripts/compare-translation.ps1``" $mdLines += "2. Refresh diff reports: ``scripts/compare-translation.ps1``"
$mdLines += "3. Edit ``build/translation-diff/candidates.json``" $mdLines += "3. Fill translated texts in ``build/translation-diff/candidates.json``"
$mdLines += "4. Apply changes: ``scripts/apply-translation-edits.ps1 -EditsPath build/translation-diff/candidates.json``" $mdLines += "4. Apply only prepared edits: ``scripts/apply-translation-edits.ps1 -EditsPath build/translation-diff/candidates.json``"
} }
$mdLines += "" $mdLines += ""

View File

@@ -51,13 +51,14 @@ try {
return return
} }
$effectiveEditsPath = $EditsPath if ([string]::IsNullOrWhiteSpace($EditsPath)) {
if ([string]::IsNullOrWhiteSpace($effectiveEditsPath)) { Write-Host "[update-translation.ps1] Найдены изменения перевода. Подготовьте правки в '$([System.IO.Path]::GetFullPath((Join-Path $resolvedOutputDir "candidates.json")))' и затем запустите повторно с '-EditsPath'."
$effectiveEditsPath = Join-Path $resolvedOutputDir "candidates.json" return
} }
$effectiveEditsPath = [System.IO.Path]::GetFullPath($EditsPath)
if (-not (Test-Path -LiteralPath $effectiveEditsPath)) { if (-not (Test-Path -LiteralPath $effectiveEditsPath)) {
throw "Translation changes were found. Prepare edits in '$([System.IO.Path]::GetFullPath((Join-Path $resolvedOutputDir "candidates.json")))' and rerun update with '-EditsPath'." throw "Prepared edits file was not found: '$effectiveEditsPath'."
} }
& $applyScriptPath -RussianPath $RussianPath -EditsPath $effectiveEditsPath & $applyScriptPath -RussianPath $RussianPath -EditsPath $effectiveEditsPath