Skip to content

Commit

Permalink
Fix one more gettext dev backend config
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Aug 21, 2024
2 parents 9761648 + 11c3a2d commit 29ba1d0
Show file tree
Hide file tree
Showing 756 changed files with 881 additions and 781 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

**Note that `ex_cldr` version 2.39.0 and later are supported on Elixir 1.12 and later only.**

## Cldr v2.40.1

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

### Bug Fixes

* Fix specs to suport dialyzer flags `:error_handling, :unknown, :underspecs, :extra_return, :missing_return`

## Cldr v2.40.0

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

### Bug Fixes

* Fix parsing of date time avaialable formats and interval formats when building the locale json files. Turns out some locales have formats that have variants and these need to be specifically parsed and grouped.

### Enhancements

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
> does not attempt to read the configuration of either Phoenix of Ecto.
>
> Specifing the `:json_library` parameter under the `:ex_cldr`
> configuration key in `config.exs` is recommended however the availability
> of `Jason` or `Poison` will still be automatically detected and configured
> if the `:json_library` key is not set.
> configuration key in `config.exs` is recommended when executing on OTP
> versions below OTP 27 but the availability of `Jason` or `Poison` will still be
> automatically detected and configured if the `:json_library` key is not set.
## Introduction

Expand Down
3 changes: 2 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config

config :ex_cldr,
default_backend: MyApp.Cldr
default_backend: MyApp.Cldr,
json_library: Jason

config :ex_cldr, MyApp.Gettext, default_locale: "en"
2 changes: 1 addition & 1 deletion dev/gettext_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Application.ensure_all_started(:gettext)
require MyApp.Gettext.Plural

defmodule MyApp.Gettext do
use Gettext,
use Gettext.Backend,
otp_app: Cldr.Config.app_name(),
plural_forms: MyApp.Gettext.Plural,
priv: "priv/gettext_test"
Expand Down
10 changes: 6 additions & 4 deletions lib/cldr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ defmodule Cldr do
"「Quoted String」"
"""
@spec quote(String.t(), backend(), Keyword.t()) :: String.t()
@spec quote(String.t(), backend(), Keyword.t()) :: String.t() | {:error, {module, String.t()}}
def quote(string, backend \\ default_backend!(), options \\ [])

def quote(string, options, []) when is_binary(string) and is_list(options) do
Expand Down Expand Up @@ -1336,7 +1336,8 @@ defmodule Cldr do
"And furthermore … there is much to be done"
"""
@spec ellipsis(String.t() | list(String.t()), backend(), Keyword.t()) :: String.t()
@spec ellipsis(String.t() | list(String.t()), backend(), Keyword.t()) ::
String.t() | {:error, {module, String.t()}}
def ellipsis(string, backend \\ default_backend!(), options \\ [])

def ellipsis(string, options, []) when is_list(options) do
Expand Down Expand Up @@ -2430,8 +2431,9 @@ defmodule Cldr do
|> String.downcase()
|> String.to_existing_atom()
|> validate_measurement_system()
rescue ArgumentError ->
{:error, unknown_measurement_system_error(system)}
rescue
ArgumentError ->
{:error, unknown_measurement_system_error(system)}
end

def validate_measurement_system(system) when system in @measurement_systems do
Expand Down
7 changes: 4 additions & 3 deletions lib/cldr/backend/cldr_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Cldr.Backend do
:"001"
"""
@spec default_territory() :: Locale.territory_code()
@spec default_territory() :: Locale.territory_code() | {:error, {module, String.t()}}
def default_territory do
Cldr.Locale.territory_from_locale(@default_locale)
end
Expand Down Expand Up @@ -474,7 +474,7 @@ defmodule Cldr.Backend do
"「Quoted String」"
"""
@spec quote(String.t(), Keyword.t()) :: String.t()
@spec quote(String.t(), Keyword.t()) :: String.t() | {:error, {module, String.t()}}

def quote(string, options \\ []) when is_binary(string) and is_list(options) do
locale = options[:locale] || Cldr.get_locale()
Expand Down Expand Up @@ -530,7 +530,8 @@ defmodule Cldr.Backend do
"And furthermore … there is much to be done"
"""
@spec ellipsis(String.t() | list(String.t()), Keyword.t()) :: String.t()
@spec ellipsis(String.t() | list(String.t()), Keyword.t()) ::
String.t() | {:error, {module, String.t()}}

def ellipsis(string, options \\ []) when is_list(options) do
locale = options[:locale] || Cldr.get_locale()
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/backend/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Cldr.Locale.Backend do
"""
@spec territory_from_locale(LanguageTag.t() | Locale.locale_name()) ::
Locale.territory_code()
Locale.territory_code() | {:error, {module, String.t()}}

@doc since: "2.18.2"

Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/config/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ defmodule Cldr.Config do
true
"""
@spec gettext_configured?(t()) :: boolean
@spec gettext_configured?(t()) :: boolean | nil
def gettext_configured?(config) do
Application.ensure_all_started(:gettext)
gettext_module = gettext(config)
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/config/dependents.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Cldr.Config.Dependents do
Cldr.Unit => {Cldr.Unit.Backend, :define_unit_module},
Cldr.Territory => {Cldr.Territory.Backend, :define_territory_module},
Cldr.Calendar => {Cldr.Calendar.Backend, :define_calendar_module},
Cldr.PersonName => {Cldr.PersonName.Backend, :define_person_name_module},
Cldr.PersonName => {Cldr.PersonName.Backend, :define_person_name_module}
}
end

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 @@ -122,7 +122,7 @@ defmodule Cldr.Rbnf.Config do
# a valid RBNF locale

def for_locale(locale_name) when Cldr.is_locale_name(locale_name) do
if File.exists?(locale_path(locale_name)) do
if File.exists?(locale_path(locale_name)) do
rules =
locale_name
|> locale_path
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/kino/data_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ defmodule Cldr.Kino.DataTable do
:default
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cldr/language_tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ defmodule Cldr.LanguageTag do
string = Cldr.LanguageTag.to_string(language_tag)
backend = language_tag.backend

"#{inspect backend}.Locale.new!(" <> inspect(string) <> ")"
"#{inspect(backend)}.Locale.new!(" <> inspect(string) <> ")"
# "#Cldr.LanguageTag<" <> language_tag.canonical_locale_name <> " [validated]>"
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/cldr/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,8 @@ defmodule Cldr.Locale do
however it is correctly parsed to support future use.
"""
@spec territory_from_locale(LanguageTag.t() | locale_name() | String.t()) :: territory_code()
@spec territory_from_locale(LanguageTag.t() | locale_name() | String.t()) ::
territory_code() | {:error, {module, String.t()}}

@doc since: "2.18.2"

Expand Down Expand Up @@ -1866,7 +1867,7 @@ defmodule Cldr.Locale do
end
end

@spec gettext_locale_name(Cldr.LanguageTag.t()) :: locale_name | nil
@spec gettext_locale_name(Cldr.LanguageTag.t()) :: String.t() | nil
defp gettext_locale_name(%LanguageTag{} = language_tag) do
language_tag
|> first_match(&known_gettext_locale_name(&1, &2, language_tag.backend))
Expand Down
3 changes: 1 addition & 2 deletions lib/cldr/locale/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule Cldr.Locale.Loader do
"locale_display_names",
"languages",
"lenient_parse",
"dates",
"dates"
]

@doc false
Expand Down Expand Up @@ -201,7 +201,6 @@ defmodule Cldr.Locale.Loader do
Map.put(content, :dates, dates)
end


@doc false
def underscore(string) when is_binary(string) do
string
Expand Down
4 changes: 2 additions & 2 deletions lib/cldr/plural_rules/plural_rule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ defmodule Cldr.Number.PluralRule do
Math.number_or_decimal(),
Locale.locale_name() | LanguageTag.t(),
atom() | pos_integer()
) :: Cldr.Number.PluralRule.plural_type()
) :: Cldr.Number.PluralRule.plural_type() | {:error, {module, String.t()}}

def plural_rule(number, locale, rounding \\ Math.default_rounding())

Expand Down Expand Up @@ -655,7 +655,7 @@ defmodule Cldr.Number.PluralRule do
first :: Cldr.Number.PluralRule.plural_type(),
last :: Cldr.Number.PluralRule.plural_type(),
locale :: Cldr.Locale.locale_name() | Cldr.LanguageTag.t()
) :: Cldr.Number.PluralRule.plural_type()
) :: Cldr.Number.PluralRule.plural_type() | {:error, {module, String.t()}}

def plural_rule(first, last, %Cldr.LanguageTag{language: language}) do
plural_rule(first, last, language)
Expand Down
4 changes: 2 additions & 2 deletions lib/cldr/substitution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Cldr.Substitution do
of templates that simplify and speed up parameter substitution at runtime.
"""
@spec parse(String.t()) :: [String.t() | integer, ...]
@spec parse(String.t()) :: [String.t() | integer, ...] | {:error, String.t()}
def parse("") do
[]
end
Expand Down Expand Up @@ -70,7 +70,7 @@ defmodule Cldr.Substitution do
def substitute(item, [0]) do
[item]
end

def substitute([item], [0]) do
[item]
end
Expand Down
10 changes: 8 additions & 2 deletions 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.39.2"
@version "2.40.1"

def project do
[
Expand All @@ -23,7 +23,13 @@ defmodule Cldr.Mixfile do
dialyzer: [
ignore_warnings: ".dialyzer_ignore_warnings",
plt_add_apps: ~w(gettext inets jason mix sweet_xml nimble_parsec)a,
flags: [:underspecs]
flags: [
:error_handling,
:unknown,
:underspecs,
:extra_return,
:missing_return
]
],
compilers: [:yecc, :leex] ++ Mix.compilers()
]
Expand Down
10 changes: 9 additions & 1 deletion mix/support/consolidate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,22 @@ defmodule Cldr.Consolidate do
special: ~x"./@special"s
)
|> Enum.map(fn
%{source: source, base_unit: target, special: "", offset: offset, factor: factor, systems: systems} ->
%{
source: source,
base_unit: target,
special: "",
offset: offset,
factor: factor,
systems: systems
} ->
{underscore(source),
%{
base_unit: underscore(target),
factor: Parser.parse(factor, 1) |> Expression.run(constants),
offset: Parser.parse(offset, 0) |> Expression.run(constants),
systems: Parser.systems(systems)
}}

%{source: source, base_unit: target, special: special, systems: systems} ->
{underscore(source),
%{
Expand Down
80 changes: 72 additions & 8 deletions mix/support/normalize/normalize_datetime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ defmodule Cldr.Normalize.DateTime do
|> Cldr.Map.deep_map(&group_region_formats/1,
only: "time_zone_names"
)
|> Cldr.Map.deep_map(&group_formats/1,
|> Cldr.Map.deep_map(&group_available_formats/1,
filter: "date_time_formats",
only: "available_formats"
)
|> Cldr.Map.deep_map(&group_interval_formats/1,
filter: "date_time_formats",
only: "interval_formats"
)

Map.put(content, "dates", dates)
end
Expand Down Expand Up @@ -93,9 +97,9 @@ defmodule Cldr.Normalize.DateTime do
end

# Some of these formats may have _count_ structures so we need to
# group these. Assumes that a format is either -count- or -alt-ascii
# but not boht.
defp group_formats({"available_formats" = key, formats}) do
# group these. Assumes that a format is either -count-, -alt-variant
# or -alt-ascii but not both.
defp group_available_formats({"available_formats" = key, formats}) do
formats =
formats
|> Enum.map(fn {name, format} ->
Expand All @@ -110,15 +114,75 @@ defmodule Cldr.Normalize.DateTime do
[ascii_format, ""] -> {ascii_format, %{ascii: format}}
end
end)
|> Enum.map(fn {name, format} ->
case String.split(name, "-alt-variant") do
[_no_count] -> {name, format}
[variant_format, ""] -> {variant_format, %{variant: format}}
end
end)
|> Enum.group_by(&elem(&1, 0), &elem(&1, 1))
|> Enum.map(fn
{key, [item]} -> {key, item}
{key, [format, %{ascii: ascii_format}]} -> {key, %{unicode: format, ascii: ascii_format}}
{key, [%{ascii: ascii_format}, format]} -> {key, %{unicode: format, ascii: ascii_format}}
{key, list} when is_list(list) -> {key, Cldr.Map.merge_map_list(list)}
{key, [item]} ->
{key, item}

{key, [format, %{ascii: ascii_format}]} ->
{key, %{unicode: format, ascii: ascii_format}}

{key, [%{ascii: ascii_format}, format]} ->
{key, %{unicode: format, ascii: ascii_format}}

{key, [format, %{variant: variant_format}]} ->
{key, %{default: format, variant: variant_format}}

{key, [%{variant: variant_format}, format]} ->
{key, %{default: format, variant: variant_format}}

{key, list} when is_list(list) ->
{key, Cldr.Map.merge_map_list(list)}
end)
|> Map.new()

{key, formats}
end

defp group_interval_formats({"interval_formats" = key, formats}) do
formats =
formats
|> Enum.map(fn {interval_name, interval_formats} ->
interval_formats = map_interval_formats(interval_formats)
{interval_name, interval_formats}
end)
|> Map.new()

{key, formats}
end

defp map_interval_formats(interval_formats) when is_map(interval_formats) do
Enum.map(interval_formats, fn
{name, format} ->
case String.split(name, "-alt-variant") do
[_no_count] -> {name, format}
[variant_format, ""] -> {variant_format, %{variant: format}}
end
end)
|> Enum.group_by(&elem(&1, 0), &elem(&1, 1))
|> Enum.map(fn
{key, [item]} ->
{key, item}

{key, [format, %{variant: variant_format}]} ->
{key, %{default: format, variant: variant_format}}

{key, [%{variant: variant_format}, format]} ->
{key, %{default: format, variant: variant_format}}

{key, list} when is_list(list) ->
{key, Cldr.Map.merge_map_list(list)}
end)
|> Map.new()
end

defp map_interval_formats(interval_formats) do
interval_formats
end
end
Loading

0 comments on commit 29ba1d0

Please sign in to comment.