Skip to content

Commit

Permalink
Use parent locale to resolve rbnf_locale_name if required
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed May 9, 2022
1 parent 5dca09c commit 3ad972b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

## Cldr v2.29.0

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

### Migration

* The plugs `Cldr.Plug.SetLocale`, `Cldr.Plug.AcceptLanguage` and `Cldr.Plug.PutSession` have been extracted to their own library, [ex_cldr_plug](https://hex.pm/packages/ex_cldr_plug). Therefore adding `{:ex_cldr_plug, "~> 1.0"}` to the `deps` of any application using these plugs is required.

### Bug Fixes

* Fixes resolving the RBNF locale name for locales that inherit the RBNF locale from a parent. This is true for at least the "nb" locale which in previous releases had its own RBNF locale data but now inherits from "no". Thanks to @juanperi for the report. Closes [#175](https://github.com/elixir-cldr/cldr/issues/175).

## Cldr v2.28.0

This is the changelog for Cldr v2.28.0 released on April 6th, 2022. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr/tags)
Expand Down
19 changes: 17 additions & 2 deletions lib/cldr/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ defmodule Cldr.Locale do
Enum.find(backend.known_locale_names(), &(locale_name == &1))
end

def known_rbnf_locale_name(locale_name, _tags \\ [], backend) do
defp known_rbnf_locale_name(locale_name, _tags, backend) do
locale_name = String.to_existing_atom(locale_name)
Cldr.known_rbnf_locale_name(locale_name, backend)
rescue ArgumentError ->
Expand Down Expand Up @@ -1591,8 +1591,23 @@ defmodule Cldr.Locale do
@root_rbnf_locale_name
end

# Get the rbnf locale name for this locale. If not found, see
# if a parent has RBNF> Note parent in this case means direct parent,
# not the fallback chain.
defp rbnf_locale_name(%LanguageTag{} = language_tag) do
first_match(language_tag, &known_rbnf_locale_name(&1, &2, language_tag.backend))
cond do
rbnf_locale = first_match(language_tag, &known_rbnf_locale_name(&1, &2, language_tag.backend)) ->
rbnf_locale

parent = Map.get(parent_locale_map(), language_tag.cldr_locale_name) ->
case Cldr.validate_locale(parent, language_tag.backend) do
{:ok, parent} -> rbnf_locale_name(parent)
{:error, _} -> nil
end

true ->
nil
end
end

@spec gettext_locale_name(Cldr.LanguageTag.t()) :: locale_name | nil
Expand Down

0 comments on commit 3ad972b

Please sign in to comment.