Packages

Elixir library for accessing ISO3166-1 (country) and ISO3166-2 (subdivision) data. Source data comes from the upstream [debian iso-codes](https://salsa.debian.org/iso-codes-team/iso-codes) package.

Current section

Files

Jump to
iso_codes lib mix tasks update_data_files.ex
Raw

lib/mix/tasks/update_data_files.ex

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(&copy_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