Skip to content

Commit

Permalink
Fix spec for Cldr.with_locale/3. Closes #215
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Oct 11, 2023
1 parent 903ebf3 commit f66a2c0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
18 changes: 8 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Changelog

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

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

**Note that `ex_cldr` version 2.33.0 and later are supported on Elixir 1.11 and later only.**
This is the changelog for Cldr v2.37.3 released on Octoebr 12th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr/tags)

### Bug Fixes

* Fix spec for `Cldr.with_locale/3` and `MyApp.Cldr.with_locale/2`. Thanks to @nTraum for the PR. Closes #215.

### Enhancements

* Adds `<backend>.put_gettext_locale_name/1`.
* Adds `<backend>.put_gettext_locale/1`.

## Cldr v2.37.2

This is the changelog for Cldr v2.37.2 released on July 4th, 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

* Remove checking Phoenix and Ecto json_library configurations. Ecto no longer configures its `:json_library` in `config.exs` and checking for Phoenix configuration can cause config failures when [building in Docker](https://github.com/elixir-cldr/cldr/issues/208). Thanks to @maciej-szlosarczyk for the report. Closes #208.
Expand All @@ -28,8 +30,6 @@ This is the changelog for Cldr v2.37.2 released on July 4th, 2023. For older ch

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.
Expand All @@ -38,8 +38,6 @@ This is the changelog for Cldr v2.37.1 released on May 7th, 2023. For older cha

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)

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

### Bug Fixes

* Fixes `Cldr.Locale.parent/1` to use `:und` as the ultimate parent rather than the default locale. This brings closer conformance to the [CLDR specification](https://unicode.org/reports/tr35/).
Expand Down
9 changes: 6 additions & 3 deletions lib/cldr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ defmodule Cldr do
"""
@doc since: "2.32.0"

@spec with_locale(Cldr.LanguageTag.t(), fun) :: any
@spec with_locale(LanguageTag.t(), fun) :: any
def with_locale(%Cldr.LanguageTag{} = locale, fun) when is_function(fun) do
current_locale = get_locale(locale.backend)

Expand All @@ -413,7 +413,8 @@ defmodule Cldr do
## Arguments
* `locale` is any valid locale name returned by `Cldr.known_locale_names/1`.
* `locale` is any valid locale name returned by `Cldr.known_locale_names/1`
or a string locale name.
* `backend` is any module that includes `use Cldr` and therefore
is a `Cldr` backend module. The default is `Cldr.default_backend!/0`.
Expand All @@ -432,7 +433,9 @@ defmodule Cldr do
"""
@doc since: "2.27.0"

@spec with_locale(Cldr.Locale.locale_name(), backend(), fun) :: any
@spec with_locale(Locale.locale_reference(), backend(), fun) :: any
@spec with_locale(Locale.locale_reference(), fun) :: any

def with_locale(locale, backend \\ default_backend!(), fun) when is_locale_name(locale) do
with {:ok, locale} = validate_locale(locale, backend) do
with_locale(locale, fun)
Expand Down
6 changes: 4 additions & 2 deletions lib/cldr/backend/cldr_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ defmodule Cldr.Backend do
"Locale #Cldr.LanguageTag<de [validated]> does not map to a known gettext locale name"}}
"""
@doc since: "2.38.0"

@spec put_gettext_locale(LanguageTag.t()) ::
{:ok, binary() | nil} | {:error, {module(), String.t()}}

Expand Down Expand Up @@ -412,7 +414,7 @@ defmodule Cldr.Backend do
"""
@doc since: "2.32.0"

@spec with_locale(Cldr.LanguageTag.t(), fun) :: any
@spec with_locale(LanguageTag.t(), fun) :: any
def with_locale(%Cldr.LanguageTag{} = locale, fun) when is_function(fun) do
Cldr.with_locale(locale, fun)
end
Expand All @@ -439,7 +441,7 @@ defmodule Cldr.Backend do
"""
@doc since: "2.32.0"

@spec with_locale(Cldr.Locale.locale_name(), fun) :: any
@spec with_locale(Locale.locale_reference(), fun) :: any
def with_locale(locale, fun) when Cldr.is_locale_name(locale) do
with {:ok, locale} = validate_locale(locale) do
with_locale(locale, fun)
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.2"
@version "2.37.3"

def project do
[
Expand Down
14 changes: 7 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"cldr_utils": {:hex, :cldr_utils, "2.24.1", "5ff8c8c55f96666228827bcf85a23d632022def200566346545d01d15e4c30dc", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "1820300531b5b849d0bc468e5a87cd64f8f2c5191916f548cbe69b2efc203780"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"},
"earmark_parser": {:hex, :earmark_parser, "1.4.32", "fa739a0ecfa34493de19426681b23f6814573faee95dfd4b4aafe15a7b5b32c6", [:mix], [], "hexpm", "b8b0dd77d60373e77a3d7e8afa598f325e49e8663a51bcc2b88ef41838cca755"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
"ex_doc": {:hex, :ex_doc, "0.30.6", "5f8b54854b240a2b55c9734c4b1d0dd7bdd41f71a095d42a70445c03cf05a281", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bd48f2ddacf4e482c727f9293d9498e0881597eae6ddc3d9562bd7923375109f"},
"expo": {:hex, :expo, "0.4.1", "1c61d18a5df197dfda38861673d392e642649a9cef7694d2f97a587b2cfb319b", [:mix], [], "hexpm", "2ff7ba7a798c8c543c12550fa0e2cbc81b95d4974c65855d8d15ba7b37a1ce47"},
"gettext": {:hex, :gettext, "0.22.3", "c8273e78db4a0bb6fba7e9f0fd881112f349a3117f7f7c598fa18c66c888e524", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "935f23447713954a6866f1bb28c3a878c4c011e802bcd68a726f5e558e4b64bd"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"gettext": {:hex, :gettext, "0.23.1", "821e619a240e6000db2fc16a574ef68b3bd7fe0167ccc264a81563cc93e67a31", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "19d744a36b809d810d610b57c27b934425859d158ebd56561bc41f7eeb8795db"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
"sweet_xml": {:hex, :sweet_xml, "0.7.3", "debb256781c75ff6a8c5cbf7981146312b66f044a2898f453709a53e5031b45b", [:mix], [], "hexpm", "e110c867a1b3fe74bfc7dd9893aa851f0eed5518d0d7cad76d7baafd30e4f5ba"},
"stream_data": {:hex, :stream_data, "0.6.0", "e87a9a79d7ec23d10ff83eb025141ef4915eeb09d4491f79e52f2562b73e5f47", [:mix], [], "hexpm", "b92b5031b650ca480ced047578f1d57ea6dd563f5b57464ad274718c9c29501c"},
"sweet_xml": {:hex, :sweet_xml, "0.7.4", "a8b7e1ce7ecd775c7e8a65d501bc2cd933bff3a9c41ab763f5105688ef485d08", [:mix], [], "hexpm", "e7c4b0bdbf460c928234951def54fe87edf1a170f6896675443279e2dbeba167"},
}
17 changes: 17 additions & 0 deletions mix/for _dialyzer.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Cldr.ForDialyzer do
def with_locale do
import Cldr.LanguageTag.Sigil

Cldr.with_locale "fr", fn -> nil end
Cldr.with_locale :fr, fn -> nil end
Cldr.with_locale ~l"fr", fn -> nil end

Cldr.with_locale "fr", MyApp.Cldr, fn -> nil end
Cldr.with_locale :fr, MyApp.Cldr, fn -> nil end

MyApp.Cldr.with_locale "fr", fn -> nil end
MyApp.Cldr.with_locale :fr, fn -> nil end
MyApp.Cldr.with_locale ~l"fr", fn -> nil end
end

end

0 comments on commit f66a2c0

Please sign in to comment.