Skip to content
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

Patch CLDR Plurals #38

Merged
merged 1 commit into from
Dec 2, 2024
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
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