GettextOps.Config (gettext_ops v0.1.1)
View SourceConfiguration and path resolution for gettext_ops.
This module provides functions to read configuration from the Application environment and resolve paths to .po and .pot files in Phoenix's gettext directory structure.
Configuration
Configure gettext_ops in your config/config.exs:
config :gettext_ops,
gettext_path: "priv/gettext",
default_domain: "default"Path Structure
gettext_ops follows Phoenix Gettext conventions:
.pofiles:priv/gettext/{locale}/LC_MESSAGES/{domain}.po.pottemplate:priv/gettext/{domain}.pot
Examples
iex> GettextOps.Config.po_file_path("sv")
"priv/gettext/sv/LC_MESSAGES/default.po"
iex> GettextOps.Config.pot_file_path()
"priv/gettext/default.pot"
Summary
Functions
Get the default domain name.
Get the configured gettext path.
List all available locales.
List all available .po files.
Check if a .po file exists for the given locale.
Resolve the path to a locale's .po file.
Find the path to a .pot template file.
Functions
@spec default_domain() :: String.t()
Get the default domain name.
Returns the default domain for .po files. Defaults to "default" if not configured.
Examples
iex> GettextOps.Config.default_domain()
"default"
@spec gettext_path() :: String.t()
Get the configured gettext path.
Returns the path to the gettext directory. Defaults to "priv/gettext" if not configured.
Examples
iex> GettextOps.Config.gettext_path()
"priv/gettext"
@spec list_locales() :: [String.t()]
List all available locales.
Scans the gettext directory structure and returns a list of all locale codes found (directory names directly under the gettext path). Returns an empty list if the gettext directory doesn't exist.
@spec list_po_files() :: [String.t()]
List all available .po files.
Recursively scans the gettext directory and returns paths to all .po files found. Returns an empty list if the gettext directory doesn't exist.
Check if a .po file exists for the given locale.
Returns true if the locale directory exists under the configured
gettext path, false otherwise.
Resolve the path to a locale's .po file.
Returns the full path to a .po file for the given locale and domain. If domain is not provided, uses the configured default domain.
Examples
iex> GettextOps.Config.po_file_path("sv")
"priv/gettext/sv/LC_MESSAGES/default.po"
iex> GettextOps.Config.po_file_path("sv", "errors")
"priv/gettext/sv/LC_MESSAGES/errors.po"
Find the path to a .pot template file.
Returns the path to the .pot template file for the given domain. If domain is not provided, uses the configured default domain.
Note: This returns the path regardless of whether the file exists.
Use File.exists?/1 to check if the template file is present.
Examples
iex> GettextOps.Config.pot_file_path()
"priv/gettext/default.pot"
iex> GettextOps.Config.pot_file_path("errors")
"priv/gettext/errors.pot"