Repository navigation
Fix translation safeguards and stable release recovery #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,30 @@ | ||
| function ConvertFrom-GuideTranslationJson { | ||
| param([Parameter(Mandatory)][string]$Content) | ||
| # ConvertFrom-Json in PowerShell 7.4 coerces ISO strings to DateTime. | ||
| # Preserve the JSON types used by the text-only translation contract. | ||
| function ReadJsonValue([System.Text.Json.JsonElement]$element) { | ||
| switch ($element.ValueKind.ToString()) { | ||
| 'Object' { | ||
| $value=[Collections.Specialized.OrderedDictionary]::new([StringComparer]::Ordinal) | ||
| foreach($property in $element.EnumerateObject()){$value.Add($property.Name,(ReadJsonValue $property.Value))} | ||
| return $value | ||
| } | ||
| 'Array' { | ||
| $value=@(foreach($item in $element.EnumerateArray()){ReadJsonValue $item}) | ||
| return ,$value | ||
| } | ||
| 'String' { return $element.GetString() } | ||
| 'Number' { return (ConvertFrom-Json $element.GetRawText() -NoEnumerate) } | ||
| 'True' { return $true } | ||
| 'False' { return $false } | ||
| 'Null' { return $null } | ||
| default { throw 'Unsupported JSON value.' } | ||
| } | ||
| } | ||
| $document=[System.Text.Json.JsonDocument]::Parse($Content) | ||
| try { return ,(ReadJsonValue $document.RootElement) } | ||
| finally { $document.Dispose() } | ||
| } | ||
| function Get-GuideSiteTranslationWork { | ||
| <# .SYNOPSIS | ||
| Discover site-language work before selecting individual guide translations. | ||
|
|
@@ -47,20 +74,45 @@ function Get-GuideSiteTranslationWork { | |
| WorkItem 'json-text-selection-required' $relative ($relative.Substring(0,$relative.Length-$sourceLanguage.Length-5)+"$Language.json") 'Set-GuideWrapperTranslation -JsonTextPaths' | ||
| }} | ||
| ) | ||
| function SameJsonShape($source,$target){ | ||
| if($source -is [Collections.IDictionary]){ | ||
| if($target -isnot [Collections.IDictionary] -or $source.Count -ne $target.Count){return $false} | ||
| foreach($key in $source.Keys){if(-not $target.Contains($key) -or -not (SameJsonShape $source[$key] $target[$key])){return $false}} | ||
| }elseif($source -is [Collections.IList]){ | ||
| if($target -isnot [Collections.IList] -or $source.Count -ne $target.Count){return $false} | ||
| for($i=0;$i -lt $source.Count;$i++){if(-not (SameJsonShape $source[$i] $target[$i])){return $false}} | ||
| }else{ | ||
| function JsonScalarKind($value){if($null -eq $value){'null'}elseif($value -is [string]){'string'}elseif($value -is [bool]){'boolean'}elseif($value -is [ValueType]){'number'}else{'unsupported'}} | ||
| if((JsonScalarKind $source) -ne (JsonScalarKind $target)){return $false} | ||
| } | ||
| return $true | ||
| } | ||
| foreach($item in $wrappers){ | ||
| if($item.Kind -eq 'json-text-selection-required'){ | ||
| try { | ||
| $sourceJson=ConvertFrom-GuideTranslationJson ([IO.File]::ReadAllText((Resolve-GuideWorkspacePath $WorkspaceRoot $item.SourcePath))) | ||
| if($item.TargetSha256){ | ||
| $targetJson=ConvertFrom-GuideTranslationJson ([IO.File]::ReadAllText((Resolve-GuideWorkspacePath $WorkspaceRoot $item.TargetPath))) | ||
| if(-not (SameJsonShape $sourceJson $targetJson)){$item.State='unsupported-json-schema-reconciliation';$item.SupportedOperation=$null} | ||
| } | ||
| }catch{$item.State='unsupported-invalid-json';$item.SupportedOperation=$null} | ||
| } | ||
| if($item.Kind -eq 'catalogue'){ | ||
| $existing=@(foreach($ext in @('yaml','yml')){$candidate="$wrapper/i18n/$Language.$ext";if(FileHash $candidate){$candidate}}) | ||
| if($existing.Count -eq 1){$item.TargetPath=$existing[0];$item.TargetSha256=FileHash $existing[0];$item.State='existing-review-required'} | ||
| if($existing.Count -eq 1){$item.TargetPath=$existing[0];$item.TargetSha256=FileHash $existing[0];$item.State='existing-review-required';$item.WriteAllowed=(Test-GuideWritePolicy $Policy $item.TargetPath).Allowed} | ||
| elseif($existing.Count -gt 1){$item.State='ambiguous-target-catalogue';$item.SupportedOperation=$null} | ||
| } | ||
| if(($item.Kind -eq 'markdown' -and -not $item.TargetPath.StartsWith("$wrapper/content/")) -or ($item.Kind -eq 'json-text-selection-required' -and -not $item.TargetPath.StartsWith("$wrapper/data/"))){$item.SupportedOperation=$null;$item.State='unsupported-custom-directory'} | ||
| } | ||
| $sourceCatalogues=@($wrappers|Where-Object Kind -EQ catalogue) | ||
| if($sourceCatalogues.Count -gt 1){foreach($item in $sourceCatalogues){$item.State='ambiguous-source-catalogue';$item.SupportedOperation=$null}} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When both source catalogues (for example, AGENTS.md reference: AGENTS.md:L14-L14 Useful? React with 👍 / 👎. |
||
| foreach($group in @($wrappers|Group-Object TargetPath|Where-Object Count -gt 1)){foreach($item in $group.Group){$item.State='ambiguous-source';$item.SupportedOperation=$null}} | ||
| $guides=@(foreach($guide in $Policy.guides){foreach($edition in $guide.editions){ | ||
| $target="$($guide.contentRoot)/$($edition.path)/index.$Language.md";$path=Resolve-GuideWorkspacePath $WorkspaceRoot $target | ||
| $translation=@($edition.translations|Where-Object language -CEQ $Language) | ||
| $intent=if($translation.Count){$translation[0].intent}else{$null} | ||
| $state=if([IO.File]::Exists($path)){if([string]::IsNullOrWhiteSpace((Read-GuideDocument $path).Body)){'empty-stub'}else{'populated'}}else{'missing'} | ||
| $excluded=@($Policy.publication.permanentExclusions|Where-Object {($_.subject -eq 'guide' -and $_.id -eq $guide.id) -or ($_.subject -eq 'edition' -and $_.id -eq "$($guide.id)/$($edition.id)")}).Count -gt 0 | ||
| $excluded=$intent -eq 'excluded' -or @($Policy.publication.permanentExclusions|Where-Object {($_.subject -eq 'guide' -and $_.id -eq $guide.id) -or ($_.subject -eq 'edition' -and $_.id -eq "$($guide.id)/$($edition.id)")}).Count -gt 0 | ||
| $allowed=(Test-GuideWritePolicy $Policy $target).Allowed | ||
| [pscustomobject]@{GuideId=$guide.id;EditionId=$edition.id;SourceLanguage=$edition.sourceLanguage;SourceLanguageSelected=($Language -ieq $edition.sourceLanguage);SourcePath="$($guide.contentRoot)/$($edition.path)/index.md";SourceSha256=(FileHash "$($guide.contentRoot)/$($edition.path)/index.md");TargetPath=$target;TargetSha256=(FileHash $target);State=$state;Intent=$intent;Excluded=$excluded;WriteAllowed=$allowed;Downloads=@($translation|ForEach-Object {$_.downloads});CanCreateScaffold=($state -eq 'missing' -and $Language -ine $edition.sourceLanguage -and $allowed -and $disabled -and -not $excluded -and $intent -notin @('pdf-only','fallback'))} | ||
| }}) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.