Skip to content

Commit 963e712

Browse files
committed
Release review fixes: NIF unit format honours :format, README pins, and bang-variant doc sections
1 parent 0fda872 commit 963e712

12 files changed

Lines changed: 154 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
* `Localize.Unit.to_string/2` with `backend: :nif` honours the `:format` option: the NIF call now receives the requested width, so `format: :short` renders "100 m" on both backends instead of falling back to the long form.
12+
913
### Removed
1014

1115
* The deprecated locale-scoped delegates are removed: `Language.available_languages/1` and `known_languages/1` (use `languages_for/1` / `language_names_for/1`), `Script.available_scripts/1` and `known_scripts/1` (use `scripts_for/1` / `script_names_for/1`), `Subdivision.available_subdivisions/1` and `known_subdivisions/1` (use `subdivisions_for/1` / `subdivision_names_for/1`), and `Territory.available_styles/0` (use `known_styles/0`).

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Add `localize` to your dependencies in `mix.exs`:
7676
```elixir
7777
def deps do
7878
[
79-
{:localize, "~> 0.47"}
79+
{:localize, "~> 0.50"}
8080
]
8181
end
8282
```
@@ -86,7 +86,7 @@ On OTP 26 only:
8686
```elixir
8787
def deps do
8888
[
89-
{:localize, "~> 0.45"},
89+
{:localize, "~> 0.50"},
9090
{:json_polyfill, "~> 0.2 or ~> 1.0"}
9191
]
9292
end

lib/localize.ex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ defmodule Localize do
528528
> form `Localize.to_string/1` (recommended) or
529529
> `import Localize, except: [to_string: 1, to_string: 2]`.
530530
531+
### Arguments
532+
533+
* `value` is any term that has a `Localize.Chars` implementation.
534+
531535
### Returns
532536
533537
* `{:ok, formatted_string}` on success.
@@ -603,6 +607,16 @@ defmodule Localize do
603607
Same as `to_string/1` but returns the formatted string directly
604608
or raises on error.
605609
610+
### Arguments
611+
612+
* `value` is any term that has a `Localize.Chars` implementation.
613+
614+
### Returns
615+
616+
* The formatted string.
617+
618+
* Raises an exception if formatting fails.
619+
606620
### Examples
607621
608622
iex> Localize.to_string!(1234.5, locale: :de)
@@ -616,11 +630,25 @@ defmodule Localize do
616630
Same as `to_string/2` but returns the formatted string directly
617631
or raises on error.
618632
633+
### Arguments
634+
635+
* `value` is any term that has a `Localize.Chars` implementation.
636+
637+
* `options` is a keyword list of options forwarded to the
638+
underlying formatter. Every implementation accepts at least
639+
`:locale`.
640+
619641
### Options
620642
621643
* See `to_string/2` for the supported options. They are forwarded
622644
unchanged to the type-specific formatter for `value`.
623645
646+
### Returns
647+
648+
* The formatted string.
649+
650+
* Raises an exception if formatting fails.
651+
624652
### Examples
625653
626654
iex> Localize.to_string!(~D[2025-07-10], locale: :de, format: :long)

lib/localize/date.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,23 @@ defmodule Localize.Date do
157157
@doc """
158158
Same as `to_string/2` but raises on error.
159159
160+
### Arguments
161+
162+
* `date` is a `t:Date.t/0` or any map with one or more of
163+
`:year`, `:month`, `:day` keys.
164+
165+
* `options` is a keyword list of options.
166+
160167
### Options
161168
162169
See `to_string/2` for the supported options.
163170
171+
### Returns
172+
173+
* A formatted string.
174+
175+
* Raises an exception if the date cannot be formatted.
176+
164177
### Examples
165178
166179
iex> Localize.Date.to_string!(~D[2017-07-10], locale: :en)

lib/localize/datetime.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,23 @@ defmodule Localize.DateTime do
136136
@doc """
137137
Same as `to_string/2` but raises on error.
138138
139+
### Arguments
140+
141+
* `datetime` is a `t:DateTime.t/0`, `t:NaiveDateTime.t/0`,
142+
or any map with date and time keys.
143+
144+
* `options` is a keyword list of options.
145+
139146
### Options
140147
141148
See `to_string/2` for the supported options.
142149
150+
### Returns
151+
152+
* A formatted string.
153+
154+
* Raises an exception if the datetime cannot be formatted.
155+
143156
### Examples
144157
145158
iex> Localize.DateTime.to_string!(~N[2017-07-10 14:30:00], locale: :en, prefer: :ascii)

lib/localize/language_tag.ex

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ defmodule Localize.LanguageTag do
229229
— this gates atomisation behind a bounded set so untrusted input
230230
cannot exhaust the atom table.
231231
232-
## Arguments
232+
### Arguments
233233
234234
* `locale_id` is any [BCP 47](https://tools.ietf.org/search/bcp47)
235235
string.
236236
237-
## Returns
237+
### Returns
238238
239239
* `{:ok, t:Localize.LanguageTag}` or
240240
@@ -287,12 +287,12 @@ defmodule Localize.LanguageTag do
287287
@doc """
288288
Parse a locale identifier into a `Localize.LanguageTag` struct and raises on error
289289
290-
## Arguments
290+
### Arguments
291291
292292
* `locale_id` is any [BCP 47](https://tools.ietf.org/search/bcp47)
293293
string.
294294
295-
## Returns
295+
### Returns
296296
297297
* `t:Localize.LanguageTag` or
298298
@@ -472,6 +472,17 @@ defmodule Localize.LanguageTag do
472472
Same as `new/1` but returns the struct directly or raises
473473
an exception.
474474
475+
### Arguments
476+
477+
* `locale_id` is any BCP 47 locale string.
478+
479+
### Returns
480+
481+
* A fully resolved `t:Localize.LanguageTag.t/0` struct.
482+
483+
* Raises an exception if parsing, canonicalization, or likely
484+
subtag resolution fails.
485+
475486
### Examples
476487
477488
iex> tag = Localize.LanguageTag.new!("zh-TW")
@@ -591,6 +602,17 @@ defmodule Localize.LanguageTag do
591602
Same as `canonicalize/1` but returns the struct directly
592603
or raises an exception.
593604
605+
### Arguments
606+
607+
* `language_tag` is a `%Localize.LanguageTag{}` struct.
608+
609+
### Returns
610+
611+
* The canonicalized tag with the `canonical_locale_id` field
612+
populated.
613+
614+
* Raises an exception if extension validation fails.
615+
594616
### Examples
595617
596618
iex> tag = Localize.LanguageTag.parse!("en-US-u-nu-arab-ca-gregory")
@@ -973,6 +995,17 @@ defmodule Localize.LanguageTag do
973995
Same as `add_likely_subtags/1` but returns the struct directly
974996
or raises an exception.
975997
998+
### Arguments
999+
1000+
* `language_tag` is a `%Localize.LanguageTag{}` struct.
1001+
1002+
### Returns
1003+
1004+
* The maximized tag with all subtags filled in and
1005+
`canonical_locale_id` updated.
1006+
1007+
* Raises an exception if no likely subtags data is found.
1008+
9761009
### Examples
9771010
9781011
iex> tag = Localize.LanguageTag.parse!("en")
@@ -1102,6 +1135,26 @@ defmodule Localize.LanguageTag do
11021135
Same as `remove_likely_subtags/2` but returns the struct directly
11031136
or raises an exception.
11041137
1138+
### Arguments
1139+
1140+
* `language_tag` is a `%Localize.LanguageTag{}` struct.
1141+
1142+
* `options` is a keyword list of options.
1143+
1144+
### Options
1145+
1146+
* `:favor` selects which subtag survives when either the script
1147+
or the region alone is enough to identify the locale: `:script`
1148+
(the default) keeps the script, `:region` keeps the region.
1149+
1150+
### Returns
1151+
1152+
* The minimized tag with redundant subtags removed and
1153+
`canonical_locale_id` updated.
1154+
1155+
* Raises an exception if maximization fails or `:favor` is
1156+
invalid.
1157+
11051158
### Examples
11061159
11071160
iex> tag = Localize.LanguageTag.parse!("zh-Hant-TW")

lib/localize/message/interpreter.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,9 +1805,9 @@ defmodule Localize.Message.Interpreter do
18051805

18061806
defp map_unit_options(localize_opts, func_opts) do
18071807
case func_opts[:unitDisplay] do
1808-
"long" -> Keyword.put(localize_opts, :style, :long)
1809-
"short" -> Keyword.put(localize_opts, :style, :short)
1810-
"narrow" -> Keyword.put(localize_opts, :style, :narrow)
1808+
"long" -> Keyword.put(localize_opts, :format, :long)
1809+
"short" -> Keyword.put(localize_opts, :format, :short)
1810+
"narrow" -> Keyword.put(localize_opts, :format, :narrow)
18111811
_other -> localize_opts
18121812
end
18131813
end

lib/localize/message/message.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ defmodule Localize.Message do
508508
509509
* See `format_to_safe_list/3` for the supported options.
510510
511+
### Returns
512+
513+
* A list of `safe_node()` tuples.
514+
515+
* Raises an exception on parse or format error, including
516+
unbalanced markup or unbound variables.
517+
511518
### Examples
512519
513520
iex> Localize.Message.format_to_safe_list!("Hello {$name}!", %{"name" => "World"})

lib/localize/number.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ defmodule Localize.Number do
355355
@doc """
356356
Same as `to_range_string/2` but raises on error.
357357
358+
### Arguments
359+
360+
* `range` is an Elixir `t:Range.t/0` (e.g., `3..5`).
361+
362+
* `options` is a keyword list of options. See `to_range_string/3`.
363+
364+
### Returns
365+
366+
* A formatted string.
367+
368+
* Raises an exception if formatting fails.
369+
358370
### Examples
359371
360372
iex> Localize.Number.to_range_string!(3..5, locale: :en)

lib/localize/unit.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,12 @@ defmodule Localize.Unit do
19151915
19161916
See `display_name/2` for the supported options.
19171917
1918+
### Returns
1919+
1920+
* The localized display name string.
1921+
1922+
* Raises an exception if the display name cannot be produced.
1923+
19181924
### Examples
19191925
19201926
iex> Localize.Unit.display_name!("meter", locale: :en)

0 commit comments

Comments
 (0)