defmodule Mix.Tasks.Holidefs.Gettext.Extract do use Mix.Task alias Holidefs.Definition alias Holidefs.Definition.Store @shortdoc "Extracts a new .pot from the definition files" @moduledoc """ Extracts a new .pot from all the definition files we load on system startup. These template files can be used to generate new locale files or add new translations to the existing ones. Execute the command `mix help gettext.merge` to check how. ## Example mix holidefs.gettext.extract """ @path Application.app_dir(:holidefs, "priv/gettext") @doc false def run(_args) do {:ok, _apps} = Application.ensure_all_started(:holidefs) for %Definition{code: code, name: name, rules: rules} <- Store.all_definitions() do first = """ # Generated by `mix holidefs.gettext.extract` # for the locale #{code |> Atom.to_string() |> String.upcase()} - #{name} #{msg(nil)} """ msgs = rules |> Stream.map(& &1.name) |> Stream.uniq() |> Stream.map(&msg/1) |> Enum.to_list() path = Path.join(@path, "#{code}.pot") File.write!(path, [first | msgs]) Mix.shell().info([:green, "* created ", :reset, path]) end end defp msg(name) do """ msgid "#{name}" msgstr "" """ end end