Commit 51e225da authored by Peter Eisentraut's avatar Peter Eisentraut

Expand set of predefined ICU locales

Install language+region combinations even if they are not distinct from
the language's base locale.  This gives better long-term stability of
the set of predefined locales and makes the predefined locales less
implementation-dependent and more practical for users.
Reviewed-by: default avatarPeter Geoghegan <pg@bowt.ie>
parent 1f6d515a
...@@ -653,9 +653,8 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1; ...@@ -653,9 +653,8 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1;
string will be accepted as a locale name.) string will be accepted as a locale name.)
See <ulink url="http://userguide.icu-project.org/locale"></ulink> for See <ulink url="http://userguide.icu-project.org/locale"></ulink> for
information on ICU locale naming. <command>initdb</command> uses the ICU information on ICU locale naming. <command>initdb</command> uses the ICU
APIs to extract a set of locales with distinct collation rules to populate APIs to extract a set of distinct locales to populate the initial set of
the initial set of collations. Here are some example collations that collations. Here are some example collations that might be created:
might be created:
<variablelist> <variablelist>
<varlistentry> <varlistentry>
...@@ -677,9 +676,9 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1; ...@@ -677,9 +676,9 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1;
<listitem> <listitem>
<para>German collation for Austria, default variant</para> <para>German collation for Austria, default variant</para>
<para> <para>
(As of this writing, there is no, (There are also, say, <literal>de-DE-x-icu</literal>
say, <literal>de-DE-x-icu</literal> or <literal>de-CH-x-icu</literal>, or <literal>de-CH-x-icu</literal>, but as of this writing, they are
because those are equivalent to <literal>de-x-icu</literal>.) equivalent to <literal>de-x-icu</literal>.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -690,6 +689,7 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1; ...@@ -690,6 +689,7 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1;
<para>German collation for Austria, phone book variant</para> <para>German collation for Austria, phone book variant</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>und-x-icu</literal> (for <quote>undefined</quote>)</term> <term><literal>und-x-icu</literal> (for <quote>undefined</quote>)</term>
<listitem> <listitem>
...@@ -724,7 +724,6 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1; ...@@ -724,7 +724,6 @@ SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1;
<programlisting> <programlisting>
CREATE COLLATION german FROM "de_DE"; CREATE COLLATION german FROM "de_DE";
CREATE COLLATION french FROM "fr-x-icu"; CREATE COLLATION french FROM "fr-x-icu";
CREATE COLLATION "de-DE-x-icu" FROM "de-x-icu";
</programlisting> </programlisting>
</para> </para>
......
...@@ -667,7 +667,16 @@ pg_import_system_collations(PG_FUNCTION_ARGS) ...@@ -667,7 +667,16 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
} }
#endif /* READ_LOCALE_A_OUTPUT */ #endif /* READ_LOCALE_A_OUTPUT */
/* Load collations known to ICU */ /*
* Load collations known to ICU
*
* We use uloc_countAvailable()/uloc_getAvailable() rather than
* ucol_countAvailable()/ucol_getAvailable(). The former returns a full
* set of language+region combinations, whereas the latter only returns
* language+region combinations of they are distinct from the language's
* base collation. So there might not be a de-DE or en-GB, which would be
* confusing.
*/
#ifdef USE_ICU #ifdef USE_ICU
{ {
int i; int i;
...@@ -676,7 +685,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) ...@@ -676,7 +685,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
* Start the loop at -1 to sneak in the root locale without too much * Start the loop at -1 to sneak in the root locale without too much
* code duplication. * code duplication.
*/ */
for (i = -1; i < ucol_countAvailable(); i++) for (i = -1; i < uloc_countAvailable(); i++)
{ {
/* /*
* In ICU 4.2, ucol_getKeywordValuesForLocale() sometimes returns * In ICU 4.2, ucol_getKeywordValuesForLocale() sometimes returns
...@@ -706,7 +715,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) ...@@ -706,7 +715,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
if (i == -1) if (i == -1)
name = ""; /* ICU root locale */ name = ""; /* ICU root locale */
else else
name = ucol_getAvailable(i); name = uloc_getAvailable(i);
langtag = get_icu_language_tag(name); langtag = get_icu_language_tag(name);
collcollate = U_ICU_VERSION_MAJOR_NUM >= 54 ? langtag : name; collcollate = U_ICU_VERSION_MAJOR_NUM >= 54 ? langtag : name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment