mix idiom.extract (idiom v0.6.5)
Extracts keys into a template directory that can be used for localisation.
Setup
In order to be able to extract keys, this task will hook into the compilation step. Since only macro calls are expanded at compile time, calls to Idiom.t/3
directly will not work. To work around this, Idiom includes a __using__/1
macro that exposes the same API while at the same time making calls available
at compile time.
If you are just getting started with Idiom, setting this up is easy: create a new module, for example Project.Localisation
and use Idiom
in it:
defmodule Project.Localisation do
use Idiom
end
Then, you can just import Project.Localisation
and use t/3
as in the documentation for Idiom.
If you are currently directly calling t/3
without use
-ing Idiom, create the same module and in addition replace your import Idiom
calls with
import Project.Localisation
. Afterwards, your keys will be available to mix idiom.extract
.
Arguments
--base-locale
(required): Sets the base locale of the template.--data-dir
: Directory to extract template to. Will default to thedata_dir
configuration setting, orpriv/idiom
if neither command-line option nor setting exist.--default-namespace
: Default namespace. When theidiom.extract
tasks finds a call toIdiom.t/3
that passesnamespace
explicitly, it will be used for extractions. For situations where the namespace is not set explicitly but throughIdiom.put_namespace/1
, you can set the namespace to extract to using this option.--files
: Filters files to extract. When using thedefault-namespace
, you will probably only want to extract keys from specific modules which can be selected using this option. Accepts everything thatPath.wildcard/1
accepts.
Examples
# Extract all keys with English as base
mix idiom.extract --base-locale en
# Extract all keys in the "signup" folder and add them to the "singup" namespace
mix idiom.extract --base-locale en --default-namespace signup --files lib/project_web/live/signup/**