Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQXb8-0002dy-QA for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Feb 2023 17:54:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pQXb7-0004Zg-Ck for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Feb 2023 17:54:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQXb6-0004ZX-UG for pgsql-hackers@lists.postgresql.org; Fri, 10 Feb 2023 17:54:09 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pQXaz-0000nE-Tr for pgsql-hackers@postgresql.org; Fri, 10 Feb 2023 17:54:07 +0000 Received: by mail-pg1-x536.google.com with SMTP id 24so4220664pgt.7 for ; Fri, 10 Feb 2023 09:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20210112.gappssmtp.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=l/9qzzElFq0nOlIWbd9cdfRV0hF3NMrDX/EodhlszsQ=; b=LD6lLOmaiZqMYwDhMvh4gRSRNonkejSIM/LDaqw1vZJ01as1GTi71e9wyD06fMXK5n Z7YfRimNaCHfC/ZvMUAQBDKTGUvhnjCfWEX5GhrvUwrMdqB3LSCFuU5/RCaN21oBwMyB VZwS1KQb1SOSTVyvGN35SpcAr59eEDzZ7ACCea1MSkGsqTy9QEl0vZWXq9dlRxeYcAb6 /VGS3EHqxIWCATp7QsPJLUd2jjwjFCQ6GcxWH1EexAXL/RdwSBN/ZEvt/bLxnq0HTczy rVVKPGNA7ZXJ6hBtyKwb6+2r4Ve6j798bxuvd0A1YWLLmhLfxwC9gShg3g4cRDG4hCOd obZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=l/9qzzElFq0nOlIWbd9cdfRV0hF3NMrDX/EodhlszsQ=; b=XJAQU3DUfk1ymGkRwH8SaxkkEw64xJIl2k6BlAAjxggbPrJxOTn4lh01zGrOA6bhE+ 9JV8cjGsLoj72cPST/0S2aD9f+6+mGww3w3Py7yHrgvlM7HIhsdPH/lbVXR3+f5cCxoc CVQbZ7LjCvuy3mWFCEr9vH5mC35ZHqLh5YmCxzkxIynSMJKpycXV3zyo6TeNv2BLsaRw i2ycCw24FlVHRQqj/SurdD47QOJLEmmhTceWuz7UkjbxiOYHTRJo5s7Geg+QbUW1/JYt 9SkAzqT+AwkqbvXQ8IVRqw3fAC4m6E0epVjd0wmhND5YD3AYb2VvcMF3SxTU2iwxnZHB LIIA== X-Gm-Message-State: AO0yUKUTOJGVPrDnSf1T0AKyMCOEQtGwO6H1RqgUlndfZMjvGHwq3+Yg 7T5/CTlU5P9blbyBxv1dIFhtVw== X-Google-Smtp-Source: AK7set+a9almfYzFin8MCbE7kjSWoWz7sh4mSU1NO2WY2M7HtAfoWA/MiCsINvT0K6347a7vkpj9+g== X-Received: by 2002:a62:15ca:0:b0:5a8:4b86:fbdd with SMTP id 193-20020a6215ca000000b005a84b86fbddmr8747640pfv.8.1676051640857; Fri, 10 Feb 2023 09:54:00 -0800 (PST) Received: from jeff-laptop.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id v23-20020aa78097000000b00587c11bc925sm3510465pff.168.2023.02.10.09.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 09:54:00 -0800 (PST) Message-ID: <33acfc3a772224d668042bd2cbef88e91704ce25.camel@j-davis.com> Subject: Re: ICU locale validation / canonicalization From: Jeff Davis To: Robert Haas Cc: pgsql-hackers@postgresql.org Date: Fri, 10 Feb 2023 09:53:58 -0800 In-Reply-To: References: <11b1eeb7e7667fdd4178497aeb796c48d26e69b9.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2023-02-10 at 09:43 -0500, Robert Haas wrote: > On Thu, Feb 9, 2023 at 5:09 PM Jeff Davis wrote: > > I do like the ICU format locale IDs from a readability standpoint. > > "en_US@colstrength=3Dprimary" is more meaningful to me than "en-US-u- > > ks- > > level1" (the equivalent language tag). >=20 > Sadly, neither of those means a whole lot to me? :-( >=20 > How did you find out that those are equivalent? In our tests you can see colstrength=3Dprimary is used to mean "case insensitive". That's where I picked up the "colstrength" keyword, which is also present in the ICU sources, but now that you ask I'm embarassed that I don't see the keyword itself documented very well.=20 This document https://unicode-org.github.io/icu/userguide/locale/#keywords lists keywords, but colstrength is not there. It's easy enough to find in the ICU source; I'm probably just missing the document. Here's the API reference, which tells you that you can set the strength of a collator (using the API, not the keyword): https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/ucol_8h.html#acc801= 048729e684bcabed328be85f77a The more precise definitions of the strengths are here: https://unicode-org.github.io/icu/userguide/collation/concepts.html#compari= son-levels Regarding the equivalence of the two forms, uloc_toLanguageTag() and uloc_toLanguageTag() are inverses. As far as I can tell (a lower degree of assurance than you are looking for), if one succeeds, then the other will also succeed and produce the original result. There are another couple documents here (TR35): http://www.unicode.org/reports/tr35/ https://www.unicode.org/reports/tr35/tr35-collation.html#Setting_Options that seems to cover the "ks-level1" and how it maps to the collation strength. My examination of these standards is very superficial -- I'm basically just checking that they seem to be there. If I search for a string like "en-US-u-ks-level1", I only find Postgres-related results, so you could also question whether these standards are actually used. Using BCP 47 tags for icu locale strings, and moving to ICU (as discussed in the other thread) is basically a leap of faith in ICU. The docs aren't perfect, the source is hard to read, and we've found bugs. But it seems like a better place for us than libc for the reasons I mentioned in the other thread. > > And the format is specified[1], > > even though it's not an independent standard. But I think the > > benefits > > of better validation, an independent standard, and the fact that > > we're > > already favoring BCP47 outweigh my subjective opinion. >=20 > See, I'm confused, because that link says "If a keyword list is > present it must be preceded by an at-sign" which makes it sound like > it is talking about stuff like en_US@colstrength=3Dprimary rather than > stuff like en-US-u-ks-level1. The examples are all that way too, like > it gives examples like en_IE@currency=3DIEP and > fr@collation=3Dphonebook;calendar=3Dislamic-civil. My paragraph was unclear, let me restate the point: To represent ICU locale strings in the catalog consistently, we have two choices, which as far as I can tell are equivalent: 1. ICU format Locale IDs. These are more readable, and still specified (albeit non-standard). 2. BCP47 language tags. These are standardized, there's better validation with "strict" mode, and we are already using them. Honestly I don't think it's hugely important which one we pick. But being consistent is important, so we need to pick one, and BCP 47 seems like the better option to me. --=20 Jeff Davis PostgreSQL Contributor Team - AWS