defmodule Mix.Tasks.UpdateDataFiles do use Mix.Task @iso_codes_dir Application.app_dir(:iso_codes, "/priv/iso-codes") @gettext_dir Application.app_dir(:iso_codes, "/priv/gettext") def run(_args) do update_domain("iso_3166-1") update_domain("iso_3166-2") end defp update_domain(domain) do Path.join(@iso_codes_dir, domain) |> File.ls!() |> Enum.filter(&(String.ends_with?(&1, ".po"))) |> Enum.each(©_locale_file(domain, &1)) template_file_src = Path.join(@iso_codes_dir, domain) |> Path.join(domain <> ".pot") template_file_dest = Path.join(@gettext_dir, domain) |> Path.join(domain <> ".pot") File.cp!(template_file_src, template_file_dest) end defp copy_locale_file(domain, locale) do [locale, ""] = String.split(locale, ".po") source_file = Path.join(@iso_codes_dir, domain) |> Path.join(locale <> ".po") dest_file = Path.join(@gettext_dir, locale) |> Path.join(domain <> ".po") File.mkdir_p!(Path.join(@gettext_dir, locale)) File.cp!(source_file, dest_file) end end