Skip to content

Commit 70e896f

Browse files
committed
Remove several TODOs
1 parent d6e3eb5 commit 70e896f

5 files changed

Lines changed: 4 additions & 130 deletions

File tree

lib/gettext/merger.ex

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ defmodule Gettext.Merger do
5454
{Messages.t(), map()}
5555
def merge(%Messages{} = old, %Messages{} = new, locale, opts, gettext_config)
5656
when is_binary(locale) and is_list(opts) do
57-
opts =
58-
opts
59-
|> handle_deprecated_plural_forms()
60-
|> put_plural_forms_opt(old, locale)
57+
opts = put_plural_forms_opt(opts, old, locale)
6158

6259
stats = %{new: 0, exact_matches: 0, fuzzy_matches: 0, removed: 0, marked_as_obsolete: 0}
6360

@@ -73,32 +70,6 @@ defmodule Gettext.Merger do
7370
{po, stats}
7471
end
7572

76-
# TODO: remove in v0.24.0
77-
defp handle_deprecated_plural_forms(opts) do
78-
plural_forms = Keyword.get(opts, :plural_forms)
79-
80-
cond do
81-
is_nil(plural_forms) ->
82-
opts
83-
84-
Keyword.has_key?(opts, :plural_forms_header) ->
85-
raise ArgumentError, """
86-
--plural-forms (or :plural_forms) and --plural-forms-header (or :plural_forms_header) \
87-
cannot be used together\
88-
"""
89-
90-
true ->
91-
IO.warn("""
92-
The --plural-forms and :plural_forms options are deprecated. If your files \
93-
have a Plural-Forms header, Gettext will use that to determin the number of plural \
94-
forms for the locale. Otherwise, you can pass a Plural-Forms header via the \
95-
--plural-forms-header or :plural_forms_header option.\
96-
""")
97-
98-
Keyword.put(opts, :plural_forms_header, "nplurals=#{plural_forms}")
99-
end
100-
end
101-
10273
defp merge_messages(old, new, opts, gettext_config, stats) do
10374
fuzzy? = Keyword.fetch!(opts, :fuzzy)
10475
fuzzy_threshold = Keyword.fetch!(opts, :fuzzy_threshold)

lib/gettext/plural.ex

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ defmodule Gettext.Plural do
362362

363363
@doc false
364364
def plural_info(locale, messages_struct, plural_mod) do
365-
ensure_compiled!(plural_mod)
365+
Code.ensure_compiled!(plural_mod)
366366

367367
if function_exported?(plural_mod, :init, 1) do
368368
pluralization_context =
@@ -379,7 +379,7 @@ defmodule Gettext.Plural do
379379

380380
@doc false
381381
def plural_forms_header_impl(locale, messages_struct, plural_mod) do
382-
ensure_compiled!(plural_mod)
382+
Code.ensure_compiled!(plural_mod)
383383

384384
plural_forms_header =
385385
if function_exported?(plural_mod, :plural_forms_header, 1) do
@@ -393,20 +393,4 @@ defmodule Gettext.Plural do
393393
"nplurals=#{nplurals}"
394394
end
395395
end
396-
397-
# TODO: remove when we depend on Elixir 1.12+
398-
if function_exported?(Code, :ensure_compiled!, 1) do
399-
defp ensure_compiled!(mod), do: Code.ensure_compiled!(mod)
400-
else
401-
defp ensure_compiled!(mod) do
402-
case Code.ensure_compiled(mod) do
403-
{:module, ^mod} ->
404-
mod
405-
406-
{:error, reason} ->
407-
raise ArgumentError,
408-
"could not load module #{inspect(mod)} due to reason #{inspect(reason)}"
409-
end
410-
end
411-
end
412396
end

lib/mix/tasks/gettext.merge.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ defmodule Mix.Tasks.Gettext.Merge do
129129
fuzzy_threshold: :float,
130130
plural_forms_header: :string,
131131
on_obsolete: :string,
132-
store_previous_message_on_fuzzy_match: :boolean,
133-
134-
# TODO: remove in v0.24.0
135-
plural_forms: :integer
132+
store_previous_message_on_fuzzy_match: :boolean
136133
]
137134

138135
@impl true
@@ -295,7 +292,6 @@ defmodule Mix.Tasks.Gettext.Merge do
295292
|> Keyword.take([
296293
:fuzzy,
297294
:fuzzy_threshold,
298-
:plural_forms,
299295
:plural_forms_header,
300296
:on_obsolete,
301297
:store_previous_message_on_fuzzy_match

test/gettext/merger_test.exs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -496,35 +496,6 @@ defmodule Gettext.MergerTest do
496496
assert stderr =~ ~s(Plural-Forms headers in the form "nplurals=<int>")
497497
end
498498

499-
# TODO: remove in v0.24.0
500-
test "plural forms can be specified as an option, but is deprecated" do
501-
old_po = %Messages{messages: []}
502-
503-
new_pot = %Messages{
504-
messages: [
505-
%Message.Singular{msgid: "a"},
506-
%Message.Plural{msgid: "b", msgid_plural: "bs"}
507-
]
508-
}
509-
510-
opts = [plural_forms: 1] ++ @opts
511-
512-
stderr =
513-
capture_io(:stderr, fn ->
514-
assert {%Messages{messages: [message, plural_message]}, _stats} =
515-
Merger.merge(old_po, new_pot, "en", opts, @gettext_config)
516-
517-
assert message.msgid == "a"
518-
519-
assert plural_message.msgid == "b"
520-
assert plural_message.msgid_plural == "bs"
521-
assert plural_message.msgstr == %{0 => [""]}
522-
end)
523-
524-
assert stderr =~ "warning"
525-
assert stderr =~ "The --plural-forms and :plural_forms options are deprecated"
526-
end
527-
528499
test "custom flags defined by :custom_flag_to_keep config are kept" do
529500
old_po = %Messages{
530501
messages: [

test/mix/tasks/gettext.merge_test.exs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,6 @@ defmodule Mix.Tasks.Gettext.MergeTest do
3636
end
3737
end
3838

39-
@tag :tmp_dir
40-
test "passing :plural_forms alongside :plural_forms_header raises an error", %{tmp_dir: tmp_dir} do
41-
write_file(Path.join(tmp_dir, "foo.pot"), """
42-
msgid "hello"
43-
msgstr ""
44-
""")
45-
46-
write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), "")
47-
48-
assert_raise ArgumentError, ~r/cannot be used together/, fn ->
49-
run([
50-
Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"),
51-
Path.join(tmp_dir, "foo.pot"),
52-
"--plural-forms",
53-
"3",
54-
"--plural-forms-header",
55-
"nplurals=1;plural=n>1;"
56-
])
57-
end
58-
end
59-
60-
# TODO: remove in v0.24.0
61-
@tag :tmp_dir
62-
test ":plural_forms is deprecated", %{tmp_dir: tmp_dir} do
63-
pot_contents = """
64-
msgid "hello"
65-
msgstr ""
66-
"""
67-
68-
write_file(Path.join(tmp_dir, "foo.pot"), pot_contents)
69-
write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), "")
70-
71-
warning =
72-
capture_io(:stderr, fn ->
73-
capture_io(:stdio, fn ->
74-
run([
75-
Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"),
76-
Path.join(tmp_dir, "foo.pot"),
77-
"--plural-forms",
78-
"3"
79-
])
80-
end)
81-
end)
82-
83-
assert warning =~ "warning"
84-
assert warning =~ "The --plural-forms and :plural_forms options are deprecated"
85-
end
86-
8739
@tag :tmp_dir
8840
test "merging an existing PO file with a new POT file", %{tmp_dir: tmp_dir} do
8941
pot_contents = """

0 commit comments

Comments
 (0)