Skip to content

Commit f457629

Browse files
committed
Update for Gettext 0.21 and later
1 parent 88329b5 commit f457629

File tree

9 files changed

+60
-46
lines changed

9 files changed

+60
-46
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Cldr_Messages v1.0.1
4+
5+
This is the changelog for Cldr_Messages v1.0.1 released on March 18th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_messages/tags)
6+
7+
### Bug Fixes
8+
9+
* Update documentation, code and tests to reflect the Gettext API as of verison 0.20
10+
311
## Cldr_Messages v1.0.0
412

513
This is the changelog for Cldr_Messages v1.0.0 released on October 5th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_messages/tags)

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,18 @@ end
173173

174174
# Define a gettext module with ICU message interpolation
175175
defmodule MyApp.Gettext do
176-
use Gettext, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation
176+
use Gettext.Backend, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation
177177
end
178178

179+
# Use the backend in your modules
180+
defmodule MyApp do
181+
use Gettext, backend: MyApp.Gettext
182+
183+
def my_module do
184+
gettext("Created at {created_at}", created_at: ~D[2022-01-22])
185+
end
186+
end
179187
```
188+
180189
Now you can proceed to use `Gettext` in the normal manner, most typically with the `gettext/3` macro.
181190

lib/cldr/messages/sigil.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ defmodule Cldr.Message.Sigil do
4949
"An ICU message"
5050
5151
However, if you want to re-use the sigil character itself on
52-
the string, you need to escape it:
53-
54-
iex> ~M((\))
55-
"()"
52+
the string, you need to escape it.
5653
5754
"""
5855
defmacro sigil_M({:<<>>, _meta, [message]}, modifiers) when is_binary(message) do

mix.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Cldr.Messages.MixProject do
22
use Mix.Project
33

4-
@version "1.0.0"
4+
@version "1.0.1"
55

66
def project do
77
[
@@ -44,16 +44,16 @@ defmodule Cldr.Messages.MixProject do
4444

4545
defp deps do
4646
[
47-
{:ex_cldr_dates_times, "~> 2.13", optional: true},
47+
{:ex_cldr_dates_times, "~> 2.22", optional: true},
4848
{:ex_money, "~> 5.9", optional: true},
49-
{:ex_cldr_units, "~> 3.12", optional: true},
49+
{:ex_cldr_units, "~> 3.18", optional: true},
5050
{:ex_cldr_lists, "~> 2.10", optional: true},
5151

5252
{:nimble_parsec, "~> 1.0"},
5353
{:jason, "~> 1.1"},
5454
{:dialyxir, "~> 1.0", optional: true, only: [:dev, :test], runtime: false},
5555
{:ex_doc, "~> 0.20", optional: true, runtime: false},
56-
{:gettext, "~> 0.19", optional: true}
56+
{:gettext, "~> 0.21", optional: true}
5757
]
5858
end
5959

mix.lock

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

mix/my_app2_gettext.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ defmodule MyApp.Gettext.Interpolation2 do
33
end
44

55
defmodule MyApp2.Gettext do
6-
use Gettext, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation2
6+
use Gettext.Backend, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation2
77
end

mix/my_app_gettext_use.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule MyApp.Gettext.Use do
2-
import MyApp.Gettext
2+
use Gettext, backend: MyApp.Gettext
33

44
def translate_compile_time(bindings \\ nil)
55

mix/my_app_getttext.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ defmodule MyApp.Gettext.Interpolation do
33
end
44

55
defmodule MyApp.Gettext do
6-
use Gettext, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation
6+
use Gettext.Backend, otp_app: :ex_cldr_messages, interpolation: MyApp.Gettext.Interpolation
77
end

test/gettext_interpolation_test.exs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Cldr.Messages.GettextInterpolationtest do
77
import Cldr.Message.TestHelpers
88

99
test "interpolates compile time translation" do
10-
import MyApp.Gettext
10+
use Gettext, backend: MyApp.Gettext
1111

1212
assert "Hello World!" == Use.translate_compile_time(name: "World")
1313

@@ -17,7 +17,7 @@ defmodule Cldr.Messages.GettextInterpolationtest do
1717
end
1818

1919
test "interpolates runtime translation" do
20-
import MyApp.Gettext
20+
use Gettext, backend: MyApp.Gettext
2121

2222
assert "runtime MXP 1.00" ==
2323
gettext("runtime {one, number, currency}", %{one: {1, currency: :MXP}})
@@ -29,7 +29,7 @@ defmodule Cldr.Messages.GettextInterpolationtest do
2929
end
3030

3131
test "interpolates runtime translation with backend that has no message formats configured" do
32-
import MyApp2.Gettext
32+
use Gettext, backend: MyApp.Gettext
3333

3434
assert "runtime MXP 1.00" ==
3535
gettext("runtime {one, number, currency}", %{one: {1, currency: :MXP}})
@@ -41,7 +41,7 @@ defmodule Cldr.Messages.GettextInterpolationtest do
4141
end
4242

4343
test "interpolation with sigil_m" do
44-
import MyApp.Gettext
44+
use Gettext, backend: MyApp.Gettext
4545
import Cldr.Message.Sigil
4646

4747
assert gettext(~m"runtime {one, number, currency}", %{one: {1, currency: :MXP}}) ==
@@ -54,10 +54,10 @@ defmodule Cldr.Messages.GettextInterpolationtest do
5454
end
5555

5656
test "number formatting in gettext finds the CLDR backend" do
57-
require MyApp.Gettext
57+
use Gettext, backend: MyApp.Gettext
5858

5959
with_no_default_backend(fn ->
60-
assert MyApp.Gettext.gettext("Message {number}", number: 7) == "Message 7"
60+
assert gettext("Message {number}", number: 7) == "Message 7"
6161
end)
6262
end
6363

@@ -72,21 +72,21 @@ defmodule Cldr.Messages.GettextInterpolationtest do
7272
end
7373

7474
test "datetime interpolation" do
75-
require MyApp.Gettext
75+
use Gettext, backend: MyApp.Gettext
7676

7777
with_no_default_backend(fn ->
78-
assert MyApp.Gettext.gettext("Created at {created_at}", created_at: ~D[2022-01-22]) ==
78+
assert gettext("Created at {created_at}", created_at: ~D[2022-01-22]) ==
7979
"Created at Jan 22, 2022"
80-
assert MyApp.Gettext.gettext("Created at {created_at}", created_at: ~U[2022-01-22T09:43:56.0Z]) ==
80+
assert gettext("Created at {created_at}", created_at: ~U[2022-01-22T09:43:56.0Z]) ==
8181
"Created at Jan 22, 2022, 9:43:56 AM"
82-
assert MyApp.Gettext.gettext("Created at {created_at}", created_at: ~T[09:43:56]) ==
82+
assert gettext("Created at {created_at}", created_at: ~T[09:43:56]) ==
8383
"Created at 9:43:56 AM"
8484
end)
8585
end
8686

8787
test "unit interpolation" do
88-
require MyApp.Gettext
89-
import MyApp.Gettext
88+
use Gettext, backend: MyApp.Gettext
89+
Cldr.put_locale MyApp.Cldr, "en"
9090

9191
with_no_default_backend(fn ->
9292
assert gettext("It weighs {weight}", weight: Cldr.Unit.new!("kilogram", 23)) == "It weighs 23 kilograms"

0 commit comments

Comments
 (0)