Fix gettext line break reject

This commit is contained in:
Simon Prévost 2023-01-16 13:08:51 -05:00
parent 042dc7e0a2
commit 773fd24f2a
3 changed files with 9 additions and 9 deletions

View File

@ -7,8 +7,8 @@ defmodule Langue.Formatter.Gettext.Parser do
def parse(%{render: render, document: document}) do
{:ok, po} = Gettext.PO.parse_string(render)
entries = parse_translations(po)
top_of_the_file_comment = join_string(po.top_of_the_file_comments)
header = join_string(po.headers)
top_of_the_file_comment = join_string(po.top_of_the_file_comments, "\n")
header = join_string(po.headers, "\n")
%Langue.Formatter.ParserResult{
entries: entries,
@ -73,8 +73,9 @@ defmodule Langue.Formatter.Gettext.Parser do
]
end
defp join_string([]), do: nil
defp join_string(list), do: Enum.join(list, "\n")
defp join_string(list, joiner \\ "")
defp join_string([], _joiner), do: nil
defp join_string(list, joiner), do: Enum.join(list, joiner)
defp key_suffix(id), do: ".__KEY__#{id}"

View File

@ -91,7 +91,6 @@ defmodule Langue.Formatter.Gettext.Serializer do
["\n" | rest] -> ["" | rest]
values -> values
end
|> Enum.reject(&(&1 === "\n"))
end
defp remove_key_suffix(string), do: String.replace(string, ".__KEY___", "")

View File

@ -172,15 +172,15 @@ defmodule LangueTest.Formatter.Gettext.Expectation do
def render do
"""
msgid "test"
msgstr ""
"a\\n"
"a\\n"
msgstr "This is a test\\n"
"\\n"
"multi line break"
"""
end
def entries do
[
%Entry{index: 1, key: "test", value: "\na\n\na\n", value_type: "string"}
%Entry{index: 1, key: "test", value: "This is a test\n\nmulti line break", value_type: "string"}
]
end
end