Skip to content

Commit

Permalink
Patch CLDR Plurals
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Dec 2, 2024
1 parent 49e9186 commit 03b9bcf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ jobs:
unzip -p src/downloads/cldr-$CLDR_VERSION.zip LICENSE > installed/license-cldr.txt
mkdir -p installed/lib/gettext/common/supplemental
unzip -p src/downloads/cldr-$CLDR_VERSION.zip common/supplemental/plurals.xml >installed/lib/gettext/common/supplemental/plurals.xml
-
name: Simplify CLDR plurals.xml
if: steps.vars.outputs.simplify-plurals-xml
shell: pwsh
run: ./build-exe/simplify-plurals-xml.ps1 installed/lib/gettext/common/supplemental/plurals.xml
-
name: Extract iconv
run: |
Expand Down
33 changes: 33 additions & 0 deletions build-exe/simplify-plurals-xml.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Script that simplify the CLDR plural.xml so that it's parsable by cldr-plurals (see https://savannah.gnu.org/bugs/?66378)

param (
[Parameter(Mandatory = $true)]
[ValidateLength(1, [int]::MaxValue)]
[ValidateScript({Test-Path -LiteralPath $_ -PathType Leaf})]
[string] $InputPath,
[Parameter(Mandatory = $false)]
[string] $OutputPath
)

$xml = Get-Content -LiteralPath $InputPath -Raw -Encoding utf8NoBOM

# for gettext we can assume that c (compact decimal exponent value) and e (a deprecated synonym for 'c')
# are always 0.
# since (as of version 0.23) gettext doesn't recognize c and e, we replace them with v (assumed to be 0 by gettext)
while ($true) {
$xml2 = $xml -creplace '(?<before>>[^"]*)\b[ce]\b','${before}v'
if ($xml2 -eq $xml) {
break
}
$xml = $xml2
}
# Strip examples like 1c3, 1.1c6
$xml = $xml -creplace '\b\d+(\.\d*)?c\d+,\s*',''
# Strip emppy examples (@decimal \u{2026})
$xml = $xml -replace "@\w+\s+`u{2026}\s*",''

if (-not($OutputPath)) {
$OutputPath = $InputPath
}

Set-Content -LiteralPath $OutputPath -Value $xml -NoNewLine -Encoding utf8NoBOM
1 change: 1 addition & 0 deletions build-exe/vars.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ Export-Variable -Name 'gettext-peversion-libtextstyle' -Value $gettextPEVersionL
Export-Variable -Name 'iconv-tp-version' -Value $iconvTPVersion
Export-Variable -Name 'gettext-tp-version' -Value $gettextTPVersion
Export-Variable -Name 'cldr-plural-works' -Value $cldrPluralWorks
Export-Variable -Name 'simplify-plurals-xml' -Value ($gettextVersion -le [Version]'0.23.0' ? 'true' : '')

Write-Output '## Outputs'
Get-Content -LiteralPath $env:GITHUB_OUTPUT

0 comments on commit 03b9bcf

Please sign in to comment.