Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ function Test-IntentionalSourceEqualValue {
return $false
}

. ([System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\..\..\scripts\translation\Languages\IntentionalSourceEqualValues.ps1')))

function Sync-TranslatedWorkingCopy {
param(
[Parameter(Mandatory = $true)]
[string]$LanguageCode,

[Parameter(Mandatory = $true)]
[System.Collections.IDictionary]$CurrentSourceMap,

Expand All @@ -313,7 +318,9 @@ function Sync-TranslatedWorkingCopy {
}

if ($translatedValue -ceq $sourceValue) {
continue
if (-not (Test-IntentionalSourceEqualValue -LanguageCode $LanguageCode -SourceValue $sourceValue -TargetValue $translatedValue)) {
continue
}
}

if ($null -ne $PreviousSourceMap -and $PreviousSourceMap.Contains($key)) {
Expand Down Expand Up @@ -473,7 +480,7 @@ else {

Write-OrderedJsonMap -Path $sourcePatchPath -Map $sourcePatchMap
Write-OrderedJsonMap -Path $referencePatchPath -Map $referencePatchMap
Sync-TranslatedWorkingCopy -CurrentSourceMap $sourcePatchMap -TranslatedPatchPath $translatedPatchPath -PreviousSourceMap $previousSourceMap
Sync-TranslatedWorkingCopy -LanguageCode $languageCode -CurrentSourceMap $sourcePatchMap -TranslatedPatchPath $translatedPatchPath -PreviousSourceMap $previousSourceMap

$mergedTargetPath = Join-Path ([System.IO.Path]::GetDirectoryName($targetPath)) ('{0}.merged.json' -f [System.IO.Path]::GetFileNameWithoutExtension($targetPath))
$skillsRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..'))
Expand All @@ -498,4 +505,4 @@ if ($ActiveOnly.IsPresent) {
}
if ($KeepIntermediate.IsPresent) {
Write-Output "Kept intermediate files under: $tmpRoot"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

. (Join-Path $PSScriptRoot '..\..\translation-diff-export\scripts\TranslationDiff.JsonTools.ps1')
. ([System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\..\..\scripts\translation\Languages\IntentionalSourceEqualValues.ps1')))

function Assert-PatchCompatibility {
param(
Expand All @@ -31,6 +32,9 @@ function Assert-PatchCompatibility {
[Parameter(Mandatory = $true)]
[System.Collections.IDictionary]$TranslatedMap,

[Parameter(Mandatory = $true)]
[string]$LanguageCode,

[Parameter(Mandatory = $true)]
[bool]$AllowUnchanged
)
Expand All @@ -49,7 +53,7 @@ function Assert-PatchCompatibility {
$sourceValue = [string]$SourceMap[$key]
Assert-TranslationStructure -SourceValue $sourceValue -TranslatedValue $translatedValue -Key $key

if (-not $AllowUnchanged -and $translatedValue -ceq $sourceValue) {
if (-not $AllowUnchanged -and $translatedValue -ceq $sourceValue -and -not (Test-IntentionalSourceEqualValue -LanguageCode $LanguageCode -SourceValue $sourceValue -TargetValue $translatedValue)) {
throw "Translated patch still contains the English source value for key '$key'. Use -AllowUnchangedValues only when that is intentional."
}
}
Expand Down Expand Up @@ -99,6 +103,13 @@ if (-not (Test-Path -Path $translatedPatchPath -PathType Leaf)) {
$targetPath = Get-FullPath -Path $TargetJson
$targetMap = Read-OrderedJsonMap -Path $targetPath
$translatedPatchMap = Read-OrderedJsonMap -Path $translatedPatchPath
$targetBaseName = [System.IO.Path]::GetFileNameWithoutExtension($targetPath)
$languageCode = if ($targetBaseName.StartsWith('lang_', [System.StringComparison]::Ordinal)) {
$targetBaseName.Substring(5)
}
else {
''
}

if ([string]::IsNullOrWhiteSpace($NeutralJson)) {
$NeutralJson = Join-Path (Split-Path -Path $targetPath -Parent) 'lang_en.json'
Expand All @@ -118,7 +129,7 @@ if (-not [string]::IsNullOrWhiteSpace($SourcePatch)) {
}

$sourceMap = Read-OrderedJsonMap -Path $sourcePatchPath
Assert-PatchCompatibility -SourceMap $sourceMap -TranslatedMap $translatedPatchMap -AllowUnchanged:$AllowUnchangedValues.IsPresent
Assert-PatchCompatibility -SourceMap $sourceMap -TranslatedMap $translatedPatchMap -LanguageCode $languageCode -AllowUnchanged:$AllowUnchangedValues.IsPresent
}

foreach ($entry in $translatedPatchMap.GetEnumerator()) {
Expand Down Expand Up @@ -154,4 +165,4 @@ if (-not $KeepIntermediate.IsPresent) {
Write-Output "Merged translated patch into: $outputJsonPath"
if ($null -ne $sourceMap) {
Write-Output "Validated translated patch against: $SourcePatch"
}
}
11 changes: 9 additions & 2 deletions scripts/translation/Get-TranslationStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ function Test-IntentionalSourceEqualValue {
)

if ($SourceValue -in @(
'MSI',
'MSIX',
'OK',
'UniGetUI',
'UniGetUI - {0} {1}'
'UniGetUI - {0} {1}',
'your@email.com',
'{0}: {1}',
'{0}: {1}, {2}'
)) {
return $true
}
Expand Down Expand Up @@ -295,6 +300,8 @@ function Test-IntentionalSourceEqualValue {
return $false
}

. (Join-Path $PSScriptRoot 'Languages\IntentionalSourceEqualValues.ps1')

function Get-TranslationStatusRow {
param(
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -572,4 +579,4 @@ switch ($OutputFormat) {
)) -join [Environment]::NewLine
Write-OutputContent -Content $content
}
}
}
210 changes: 210 additions & 0 deletions scripts/translation/Languages/IntentionalSourceEqualValues.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
function Test-IntentionalSourceEqualValue {
param(
[Parameter(Mandatory = $true)]
[string]$LanguageCode,

[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$SourceValue,

[Parameter(Mandatory = $false)]
[AllowEmptyString()]
[string]$TargetValue = ''
)

if ($SourceValue -in @(
'MSI',
'MSIX',
'OK',
'UniGetUI',
'UniGetUI - {0} {1}',
'your@email.com',
'{0}: {1}',
'{0}: {1}, {2}'
)) {
return $true
}

if ($LanguageCode -ceq 'it' -and $SourceValue -ceq 'No' -and $TargetValue -ceq 'No') {
return $true
}

if ($LanguageCode -ceq 'it' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'DEBUG BUILD'
)) {
return $true
}

if ($LanguageCode -ceq 'ca' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'1 - Errors',
'Error',
'Global',
'Local',
'Manifest',
'Manifests',
'No',
'Notes:',
'Text'
)) {
return $true
}

if ($LanguageCode -ceq 'pt_PT' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Global',
'Local'
)) {
return $true
}

if ($LanguageCode -ceq 'hr' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Manifest',
'Status',
'URL'
)) {
return $true
}

if ($LanguageCode -ceq 'es' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Error',
'Global',
'Local',
'No',
'URL'
)) {
return $true
}

if ($LanguageCode -ceq 'es-MX' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Error',
'Global',
'Local',
'No',
'URL',
'Url'
)) {
return $true
}

if ($LanguageCode -ceq 'fr' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Ascendant',
'Descendant',
'Global',
'Local',
'Navigation',
'Portable',
'Source',
'Sources',
'Verbose',
'Version',
'installation',
'option',
'version {0}',
'{0} minutes'
)) {
return $true
}

if ($LanguageCode -ceq 'nl' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'1 week',
'Filters',
'Manifest',
'Status',
'Updates',
'URL',
'update',
'website',
'{0} status'
)) {
return $true
}

if ($LanguageCode -ceq 'sk' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Manifest',
'Text'
)) {
return $true
}

if ($LanguageCode -ceq 'de' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Global',
'Manifest',
'Name',
'Repository',
'Start',
'Status',
'Text',
'Updates',
'URL',
'Verbose',
'Version',
'Version:',
'optional',
'{package} Installation',
'{package} Update'
)) {
return $true
}

if ($LanguageCode -ceq 'sv' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Global',
'Manifest',
'Start',
'Status',
'Text',
'Version',
'Version:',
'installation',
'version {0}',
'{0} installation',
'{0} status',
'{pm} version:'
)) {
return $true
}

if ($LanguageCode -ceq 'id' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Global',
'Grid',
'Manifest',
'Status',
'URL',
'Verbose',
'{0} status'
)) {
return $true
}

if ($LanguageCode -ceq 'fil' -and $SourceValue -ceq $TargetValue -and $SourceValue -in @(
'Android Subsystem',
'Default',
'Error',
'Global',
'Grid',
'Machine | Global',
'Manifest',
'OK',
'Ok',
'Package',
'Password',
'Portable',
'Portable mode',
'PreRelease',
'Repository',
'Source',
'Source:',
'Telemetry',
'Text',
'URL',
'UniGetUI',
'UniGetUI - {0} {1}',
'User',
'Username',
'Verbose',
'website',
'library'
)) {
return $true
}

return $false
}
Loading