Current section
Files
Jump to
Current section
Files
lib/extractly/do_not_edit.ex
defmodule Extractly.DoNotEdit do
@moduledoc """
Implements the storage of DO NOT EDIT warning messages for languages and various
variations.
"""
@warnings %{
en: """
DO NOT EDIT THIS FILE
It has been generated from %article template %template! by Extractly (https://github.com/RobertDober/extractly.git)
and any changes you make in this file will most likely be lost
""",
fr: """
NE PAS EDITER CE FICHIER
Il a été créé à partir %article patron %template! par Extractly (https://github.com/RobertDober/extractly.git)
et toute modification apportée par vos soins va probablement être perdue
"""
}
@articles %{
en: %{
true: "the",
false: "a"
},
fr: %{
true: "du",
false: "d'un"
}
}
@doc """
Resolves to the correctly configured and internationalized message
"""
def warning(opts) do
lang = Keyword.get(opts, :lang, :en)
lang =
if Map.has_key?(@warnings, lang) do
lang
else
IO.puts(:stderr, "Language #{lang} is not supported yet, falling back to :en")
:en
end
template = Keyword.get(opts, :template, false)
definite = !!template
article = @articles[lang][definite]
comment_start = Keyword.get(opts, :comment_start, "<!--\n")
comment_end = Keyword.get(opts, :comment_end, "-->")
message(@warnings[lang], {comment_start, comment_end}, template, article)
end
defp inner_message(base, template, article)
defp inner_message(base, false, article) do
base
|> String.replace("%article", article)
|> String.replace("%template! ", "")
end
defp inner_message(base, template, article) do
base
|> String.replace("%article", article)
|> String.replace("%template!", "`#{template}`")
end
defp message(base, {comment_start, comment_end}, template, article) do
comment_start <> inner_message(base, template, article) <> comment_end
end
end