Skip to content

Commit c4ef5c8

Browse files
authored
Import CLDR data directly from XML, switch to CLDR 47 (#50)
1 parent ec77434 commit c4ef5c8

File tree

8 files changed

+731
-72
lines changed

8 files changed

+731
-72
lines changed

.github/workflows/tests.yml

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: Tests
22

3+
env:
4+
BUILD_CLDR_VERSION: "47"
5+
36
on:
47
push:
58
branches:
69
- main
10+
tags-ignore:
11+
- "**"
712
pull_request:
813
branches:
914
- main
@@ -13,18 +18,21 @@ jobs:
1318
name: Check PHP coding style
1419
runs-on: ubuntu-latest
1520
steps:
16-
- name: Setup PHP
21+
-
22+
name: Setup PHP
1723
uses: shivammathur/setup-php@v2
1824
with:
1925
php-version: "8.1"
2026
extensions: mbstring, zip
2127
tools: composer:2, php-cs-fixer:3
2228
coverage: none
23-
- name: Checkout
24-
uses: actions/checkout@v2
25-
- name: Check PHP coding style
26-
run: |
27-
php-cs-fixer fix --path-mode=intersection --config=./.php-cs-fixer.dist.php --dry-run --using-cache=no --diff --show-progress=dots --verbose --no-interaction --ansi .
29+
-
30+
name: Checkout
31+
uses: actions/checkout@v4
32+
-
33+
name: Check PHP coding style
34+
run: php-cs-fixer fix --config=./.php-cs-fixer.dist.php --dry-run --using-cache=no --diff --show-progress=dots --verbose --no-interaction --ansi
35+
2836
phpunit:
2937
name: Run PHPUnit tests
3038
needs: php-coding-style
@@ -45,24 +53,71 @@ jobs:
4553
- "8.0"
4654
- "8.1"
4755
- "8.2"
56+
- "8.3"
57+
- "8.4"
4858
include:
4959
- os: windows-latest
5060
php-version: "5.6"
5161
- os: windows-latest
5262
php-version: "7.4"
5363
- os: windows-latest
54-
php-version: "8.1"
64+
php-version: "8.4"
5565
runs-on: ${{ matrix.os }}
5666
steps:
57-
- name: Setup PHP
67+
-
68+
name: Setup PHP
5869
uses: shivammathur/setup-php@v2
5970
with:
6071
php-version: ${{ matrix.php-version }}
6172
tools: composer:v2
6273
coverage: none
63-
- name: Checkout
64-
uses: actions/checkout@v2
65-
- name: Install Composer dependencies
74+
-
75+
name: Checkout
76+
uses: actions/checkout@v4
77+
-
78+
name: Install Composer dependencies
6679
run: composer update --no-progress --no-suggest --optimize-autoloader --ansi --no-interaction
67-
- name: Run PHPUnit
80+
-
81+
name: Build CLDR data
82+
run: php ./bin/import-cldr-data ${{ env.BUILD_CLDR_VERSION }}
83+
-
84+
name: Run PHPUnit
6885
run: composer --no-interaction run-script test
86+
87+
commit:
88+
name: Commit CLDR data
89+
runs-on: ubuntu-latest
90+
needs: phpunit
91+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
92+
steps:
93+
-
94+
name: Setup PHP
95+
uses: shivammathur/setup-php@v2
96+
with:
97+
php-version: 8.4
98+
tools: none
99+
coverage: none
100+
-
101+
name: Checkout
102+
uses: actions/checkout@v4
103+
-
104+
name: Build CLDR data
105+
run: php ./bin/import-cldr-data ${{ env.BUILD_CLDR_VERSION }}
106+
-
107+
name: Check changes
108+
id: check-changes
109+
run: |
110+
git add --all src/cldr-data
111+
if git diff-index --name-status --exit-code HEAD src/cldr-data; then
112+
echo 'No changes detected.'
113+
else
114+
echo 'Changes detected.'
115+
echo 'commit=yes' >> $GITHUB_OUTPUT
116+
fi
117+
- name: Commit changes
118+
if: steps.check-changes.outputs.commit == 'yes'
119+
run: |
120+
git config --local user.name 'GitHub Actions'
121+
git config --local user.email [email protected]
122+
git commit -m 'Update CLDR data'
123+
git push

.php-cs-fixer.dist.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
])
2727
->append([
2828
__DIR__ . '/bin/export-plural-rules',
29+
__DIR__ . '/bin/import-cldr-data',
2930
])
3031
->in(__DIR__)
3132
)
@@ -245,8 +246,6 @@
245246
'phpdoc_no_access' => true,
246247
// No alias PHPDoc tags should be used.
247248
'phpdoc_no_alias_tag' => true,
248-
// `@return void` and `@return null` annotations should be omitted from PHPDoc.
249-
'phpdoc_no_empty_return' => true,
250249
// `@package` and `@subpackage` annotations should be omitted from PHPDoc.
251250
'phpdoc_no_package' => true,
252251
// Classy that does not inherit must not have `@inheritdoc` tags.

README.md

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -172,63 +172,7 @@ the resulting formulas will be in this format:
172172

173173
### Generating the CLDR data
174174
This repository uses the CLDR data, including American English (`en_US`) json files.
175-
In order to generate this data, you can use Docker.
176-
Start a new Docker container by running
177-
178-
```sh
179-
docker run --rm -it -v path/to/src/cldr-data:/output alpine:3.13 sh
180-
```
181-
182-
Then run the following script, setting the values of the variables accordingly to your needs:
183-
184-
```sh
185-
# The value of the CLDR version (eg 39, 38.1, ...)
186-
CLDR_VERSION=39
187-
# Your GitHub username (required since CLDR 38) - see http://cldr.unicode.org/development/maven#TOC-Introduction
188-
GITHUB_USERNAME=
189-
# Your GitHub personal access token (required since CLDR 38) - see http://cldr.unicode.org/development/maven#TOC-Introduction
190-
GITHUB_TOKEN=
191-
192-
if ! test -d /output; then
193-
echo 'Missing output directory' >&2
194-
return 1
195-
fi
196-
apk -U upgrade
197-
apk add --no-cache git git-lfs openjdk8 apache-ant maven
198-
CLDR_MAJORVERSION="$(printf '%s' "$CLDR_VERSION" | sed -E 's/^([0-9]+).*/\1/')"
199-
SOURCE_DIR="$(mktemp -d)"
200-
DESTINATION_DIR="$(mktemp -d)"
201-
git clone --single-branch --depth=1 "--branch=release-$(printf '%s' "$CLDR_VERSION" | tr '.' '-')" https://github.com/unicode-org/cldr.git "$SOURCE_DIR"
202-
if test $CLDR_MAJORVERSION -lt 38; then
203-
git -C "$SOURCE_DIR" lfs pull --include tools/java || true
204-
ant -f "$SOURCE_DIR/tools/java/build.xml" jar
205-
JARFILE="$SOURCE_DIR/tools/java/cldr.jar"
206-
DESTINATION_DIR_LOCALE="$DESTINATION_DIR/en_US"
207-
DESTINATION_FILE_PLURALS="$DESTINATION_DIR/supplemental/plurals.json"
208-
else
209-
if test -z "${GITHUB_USERNAME:-}"; then
210-
echo 'GITHUB_USERNAME is missing' >&2
211-
return 1
212-
fi
213-
if test -z "${GITHUB_TOKEN:-}"; then
214-
echo 'GITHUB_TOKEN is missing' >&2
215-
return 1
216-
fi
217-
printf '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"><servers><server><id>githubicu</id><username>%s</username><password>%s</password></server></servers></settings>' "$GITHUB_USERNAME" "$GITHUB_TOKEN" > "$SOURCE_DIR/mvn-settings.xml"
218-
mvn --settings "$SOURCE_DIR/mvn-settings.xml" package -DskipTests=true --file "$SOURCE_DIR/tools/cldr-code/pom.xml"
219-
JARFILE="$SOURCE_DIR//tools/cldr-code/target/cldr-code.jar"
220-
DESTINATION_DIR_LOCALE="$DESTINATION_DIR"
221-
DESTINATION_FILE_PLURALS="$DESTINATION_DIR/supplemental/plurals/plurals.json"
222-
fi
223-
java -Duser.language=en -Duser.country=US "-DCLDR_DIR=$SOURCE_DIR" "-DCLDR_GEN_DIR=$DESTINATION_DIR_LOCALE" -jar "$JARFILE" ldml2json -t main -r true -s contributed -m en_US
224-
java -Duser.language=en -Duser.country=US "-DCLDR_DIR=$SOURCE_DIR" "-DCLDR_GEN_DIR=$DESTINATION_DIR/supplemental" -jar "$JARFILE" ldml2json -s contributed -o true -t supplemental
225-
mkdir -p /output/main/en-US
226-
cp $DESTINATION_DIR/en_US/languages.json /output/main/en-US/
227-
cp $DESTINATION_DIR/en_US/scripts.json /output/main/en-US/
228-
cp $DESTINATION_DIR/en_US/territories.json /output/main/en-US/
229-
mkdir -p /output/supplemental
230-
cp "$DESTINATION_FILE_PLURALS" /output/supplemental/
231-
```
175+
In order to generate this data, you can use the `bin/import-cldr-data` CLI command.
232176

233177

234178
## Support this project

0 commit comments

Comments
 (0)