Packages
gettext
0.7.0
1.0.2
1.0.1
retired
1.0.0
0.26.2
0.26.1
0.26.0
retired
0.25.0
0.24.0
0.23.1
0.23.0
0.22.3
0.22.2
0.22.1
0.22.0
0.21.0
0.20.0
0.19.1
0.19.0
0.18.2
0.18.1
0.18.0
0.17.4
0.17.3
0.17.2
0.17.1
0.17.0
0.16.1
0.16.0
0.15.0
0.14.1
0.14.0
0.13.1
0.13.0
0.12.2
0.12.1
0.12.0
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.1
0.6.0
0.5.0
Internationalization and localization through gettext
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/gettext.extract.ex
defmodule Mix.Tasks.Gettext.Extract do
use Mix.Task
@recursive true
@shortdoc "Extracts translations from source code"
@moduledoc """
Extracts translations by recompiling the Elixir source code.
mix gettext.extract [OPTIONS]
Translations are extracted into POT (Portable Object Template) files (with a
`.pot` extension). The location of these files is determined by the `:otp_app`
and `:priv` options given by gettext modules when they call `use Gettext`. One
POT file is generated for each translation domain.
It is possible to give the `--merge` option to perform merging
for every Gettext backend updated during merge:
mix gettext.extract --merge
All other options passed to `gettext.extract` are forwarded to the
`gettext.merge` task (`Mix.Tasks.Gettext.Merge`), which is called internally
by this task. For example:
mix gettext.extract --merge --no-fuzzy
"""
def run(args) do
pot_files = extract()
for {path, contents} <- pot_files do
Task.async fn ->
File.mkdir_p!(Path.dirname(path))
File.write!(path, contents)
Mix.shell.info "Extracted #{Path.relative_to_cwd(path)}"
end
end |> Enum.map(&Task.await/1)
case args do
[] ->
:ok
["--merge"] ->
run_merge(pot_files, args)
_ ->
Mix.raise "The gettext.extract task only supports the --merge option. " <>
"See `mix help gettext.extract` for more information."
end
:ok
end
defp extract do
Gettext.Extractor.setup
force_compile
Gettext.Extractor.pot_files
after
Gettext.Extractor.teardown
end
defp force_compile do
Enum.map Mix.Tasks.Compile.Elixir.manifests, &make_old_if_exists/1
Mix.Task.run "compile"
end
defp make_old_if_exists(path) do
:file.change_time(path, {{2000, 1, 1}, {0, 0, 0}})
end
defp run_merge(pot_files, argv) do
pot_files
|> Enum.map(fn {path, _} -> Path.dirname(path) end)
|> Enum.uniq
|> Enum.map(&Task.async(fn -> Mix.Tasks.Gettext.Merge.run([&1|argv]) end))
|> Enum.map(&Task.await/1)
end
end