Skip to content

Commit

Permalink
Don't include :und in known_locales
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed May 7, 2023
1 parent a61598b commit 7b293aa
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Cldr v2.37.1

This is the changelog for Cldr v2.37.1 released on May 7th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr/tags)

**Note that `ex_cldr` version 2.33.0 and later are supported on Elixir 1.11 and later only.**

### Bug Fixes

* Don't include `:und` in the list returned by `Cldr.known_locale_names/1` since that function is commonly used to enumerate the configured locales and ultimately used to generate UI elements. `:und` is not a useful locale to select so its inclusion, which was added in `ex_cldr version 2.37.0` is inappropriate and now reverted.

## Cldr v2.37.0

This is the changelog for Cldr v2.37.0 released on April 28th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr/tags)
Expand Down
6 changes: 1 addition & 5 deletions lib/cldr/backend/cldr_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ defmodule Cldr.Backend do

alias Cldr.{Locale, Config, LanguageTag}

# We used to omit :und but the spec says thats the ultimate
# fallback so its back!

# @omit_locales [Config.root_locale_name()]
@omit_locales []
@omit_locales [Config.root_locale_name()]
@known_locale_names Locale.Loader.known_locale_names(config) -- @omit_locales

def known_locale_names do
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/config/rbnf_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule Cldr.Rbnf.Config do
:ff, :fi, :fil, :fo, :fr, :"fr-BE", :"fr-CH", :ga, :he, :hi, :hr, :hu, :hy,
:id, :is, :it, :ja, :ka, :kk, :kl, :km, :ko, :ky, :lb, :lo, :lrc, :lt, :lv,
:mk, :ms, :mt, :my, :ne, :nl, :nn, :no, :pl, :pt, :"pt-PT", :qu, :ro, :ru, :se,
:sk, :sl, :sq, :sr, :"sr-Latn", :su, :sv, :sw, :ta, :th, :tr, :uk, :und, :vec,
:sk, :sl, :sq, :sr, :"sr-Latn", :su, :sv, :sw, :ta, :th, :tr, :uk, :vec,
:vi, :yue, :"yue-Hans", :zh, :"zh-Hant"]
"""
Expand Down
8 changes: 7 additions & 1 deletion lib/cldr/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ defmodule Cldr.Locale do
end

defp known_locale(locale_name, _tags, backend) when is_atom(locale_name) do
Enum.find(backend.known_locale_names(), &(locale_name == &1))
Enum.find(backend.known_locale_names() ++ [Cldr.Config.root_locale_name()], &(locale_name == &1))
end

defp known_rbnf_locale_name(locale_name, _tags, backend) do
Expand Down Expand Up @@ -1809,7 +1809,13 @@ defmodule Cldr.Locale do
%{language_tag | gettext_locale_name: gettext_locale_name}
end

@root_locale_name Cldr.Config.root_locale_name()

@spec cldr_locale_name(Cldr.LanguageTag.t()) :: locale_name() | nil
defp cldr_locale_name(%LanguageTag{language: @root_locale_name}) do
@root_locale_name
end

defp cldr_locale_name(%LanguageTag{} = language_tag) do
first_match(language_tag, &known_locale(&1, &2, language_tag.backend)) ||
Cldr.known_locale_name(language_tag.requested_locale_name, language_tag.backend)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.Mixfile do
use Mix.Project

@version "2.37.0"
@version "2.37.1"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion test/config_locales_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ defmodule Cldr.Config.Test do
end)

assert apply(Cldr.Config.Test.PosixDefaultLocale, :known_locale_names, []) ==
[:en, :"en-GB", :und]
[:en, :"en-GB"]

assert apply(Cldr.Config.Test.PosixDefaultLocale, :default_locale, []).cldr_locale_name ==
:"en-GB"
Expand Down
7 changes: 5 additions & 2 deletions test/parent_locale_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ defmodule Cldr.Locale.Parent.Test do
assert Cldr.Locale.parent("und") ==
{:error, {Cldr.NoParentError, "The locale :und has no parent locale"}}

assert Cldr.Locale.parent("en-US") == TestBackend.Cldr.Locale.new("und")
assert Cldr.Locale.parent("en-US-u-va-POSIX") == TestBackend.Cldr.Locale.new("und-u-va-posix")
assert Cldr.Locale.parent("en-AU") == TestBackend.Cldr.Locale.new("en-001")
end

test "parent is :und" do
assert Cldr.Locale.parent("en-US") == TestBackend.Cldr.Locale.new("und")
assert Cldr.Locale.parent("ca") == TestBackend.Cldr.Locale.new("und")
assert Cldr.Locale.parent("en-US-u-va-POSIX") == TestBackend.Cldr.Locale.new("und-u-va-posix")
end

test "parent locale of en-001" do
Expand Down

0 comments on commit 7b293aa

Please sign in to comment.