Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gettext/extractor_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule Gettext.ExtractorAgent do

defp merge_messages_after_checks(message_1, message_2) do
message_1
|> Map.put(:references, message_1.references ++ message_2.references)
|> Map.put(:references, Enum.uniq(message_1.references ++ message_2.references))
|> Map.put(
:extracted_comments,
Enum.uniq(message_1.extracted_comments ++ message_2.extracted_comments)
Expand Down
35 changes: 35 additions & 0 deletions test/gettext/extractor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,41 @@ defmodule Gettext.ExtractorTest do
Extractor.disable()
end

test "duplicate references for one message are recorded once" do
Extractor.enable()

code = """
defmodule Gettext.ExtractorTest.SameLineGettext do
use Gettext.Backend, otp_app: :test_application
end

defmodule SameLine do
require Gettext.Macros

def bar do
[Gettext.Macros.gettext_with_backend(Gettext.ExtractorTest.SameLineGettext, "foo"), Gettext.Macros.gettext_with_backend(Gettext.ExtractorTest.SameLineGettext, "foo")]
end
end
Comment thread
rigzad marked this conversation as resolved.
"""

Code.compile_string(code, Path.join(File.cwd!(), "same_line.ex"))

[{_path, {:changed, contents}}] =
:test_application
|> Extractor.pot_files([])
|> Enum.reject(&match?({_path, :unchanged}, &1))

references =
contents
|> IO.iodata_to_binary()
|> String.split("\n")
|> Enum.filter(&String.starts_with?(&1, "#: same_line.ex"))

assert references == ["#: same_line.ex:9"]
after
Extractor.disable()
end

defp write_file(path, contents) do
path |> Path.dirname() |> File.mkdir_p!()
File.write!(path, contents)
Expand Down
Loading