Skip to content

Commit 7c14774

Browse files
committed
with --lower-case-lang-codes, handle valid language codes πŸ›βœ…
follow-up of 2da56cd
1 parent 160bd9f commit 7c14774

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

β€Žlib/prerequisites.jsβ€Ž

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const is_valid_lang_code = {
66
-- identifiers with "_", not with "-", so we use pg_collation instead.
77
-- https://www.postgresql.org/docs/current/infoschema-collations.html
88
-- https://www.postgresql.org/docs/current/catalog-pg-collation.html
9+
-- todo [breaking]: rename to e.g. is_similar_to_bcp_47_tag?
910
CREATE OR REPLACE FUNCTION "${opt.schema}".is_bcp_47_tag(
1011
input TEXT
1112
)
@@ -14,9 +15,9 @@ AS $$
1415
SELECT EXISTS (
1516
SELECT collctype
1617
FROM pg_collation
17-
WHERE collctype = input
18-
OR collname = input
19-
OR collname = input || '-x-icu'
18+
WHERE ${opt.lowerCaseLanguageCodes ? `lower(collctype)` : `collctype`} = ${opt.lowerCaseLanguageCodes ? `lower(input)` : `input`}
19+
OR ${opt.lowerCaseLanguageCodes ? `lower(collname)` : `collname`} = ${opt.lowerCaseLanguageCodes ? `lower(input)` : `input`}
20+
OR ${opt.lowerCaseLanguageCodes ? `lower(collname)` : `collname`} = ${opt.lowerCaseLanguageCodes ? `lower(input)` : `input`} || '-x-icu'
2021
LIMIT 1
2122
);
2223
$$ language sql STABLE;
@@ -30,9 +31,7 @@ CREATE OR REPLACE FUNCTION "${opt.schema}".is_valid_lang_code(
3031
)
3132
RETURNS BOOLEAN
3233
AS $$
33-
SELECT "${opt.schema}".is_bcp_47_tag(
34-
${opt.lowerCaseLanguageCodes ? `lower(input)` : `input`}
35-
);
34+
SELECT "${opt.schema}".is_bcp_47_tag(input);
3635
$$ language sql STABLE;
3736
3837
${opt.postgraphile ? `\

β€Žtest/sample-gtfs-feed.shβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ env | grep '^PG' || true
1111
psql -c 'create database sample_gtfs_feed'
1212
export PGDATABASE='sample_gtfs_feed'
1313

14-
../cli.js -d --trips-without-shape-id -- \
14+
# --lower-case-lang-codes: Even though sample-gtfs-feed@0.11.2 *does not* contain invalid-case language codes (e.g. de_aT or de-at), we check that with --lower-case-lang-codes valid ones are still accepted.
15+
../cli.js -d --trips-without-shape-id --lower-case-lang-codes -- \
1516
../node_modules/sample-gtfs-feed/gtfs/agency.txt \
1617
../node_modules/sample-gtfs-feed/gtfs/calendar.txt \
1718
../node_modules/sample-gtfs-feed/gtfs/calendar_dates.txt \

0 commit comments

Comments
Β (0)