GettextTranslator.Dashboard (gettext_translator v0.2.0)
View SourcePhoenix LiveDashboard integration for GettextTranslator.
This module provides functions to register the GettextTranslator dashboard with your Phoenix application.
Setup
- Add the required dependencies to your mix.exs:
def deps do
[
{:gettext_translator, "~> 0.2.0"},
{:phoenix_live_dashboard, ">= 0.6.0"},
{:phoenix_live_view, ">= 0.17.0"}
]
end
- Add the GettextTranslator supervisor to your application:
# lib/my_app/application.ex
def start(_type, _args) do
children = [
# ... other children
GettextTranslator.Supervisor
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
- Add the dashboard page to your Phoenix router:
# lib/my_app_web/router.ex
import Phoenix.LiveDashboard.Router
scope "/" do
pipe_through [:browser, :admin_auth] # replace with your actual pipeline
live_dashboard "/dashboard",
metrics: MyAppWeb.Telemetry,
additional_pages: GettextTranslator.Dashboard.page_config(gettext_path: "priv/gettext")
end
Usage
Once set up, you can access the Gettext Translations page from your Phoenix LiveDashboard. The dashboard allows you to:
- View all translations across all language files
- Filter translations by language, domain, and status
- Edit translations directly in the UI
- Commit changes back to PO files
- Create Git commits and PRs (if the git_cli dependency is available)
You can also continue to use the mix task for batch translation:
mix gettext_translator.run
Summary
Functions
Checks if the Phoenix.LiveDashboard and Phoenix.LiveView dependencies are available.
Loads translations from the given gettext path.
Returns the gettext dashboard page configuration.
Returns a list of additional pages configuration for Phoenix LiveDashboard.
Helper function to quickly test the dashboard API in IEx.
Starts the translation store process manually if needed.
Functions
Checks if the Phoenix.LiveDashboard and Phoenix.LiveView dependencies are available.
Loads translations from the given gettext path.
This must be called after the translation store is started to load the translations into memory.
Returns {:ok, count}
where count is the number of translations loaded,
or {:error, reason}
if loading failed.
Returns the gettext dashboard page configuration.
Options
:gettext_path
- Path to the gettext directory (default: "priv/gettext")
Example
# When manually constructing the dashboard pages
additional_pages = [
my_custom_page: {MyCustomPage, []},
gettext_translations: GettextTranslator.Dashboard.page()
]
Returns a list of additional pages configuration for Phoenix LiveDashboard.
Options
:gettext_path
- Path to the gettext directory (default: "priv/gettext")
Example
live_dashboard "/dashboard",
metrics: MyAppWeb.Telemetry,
additional_pages: GettextTranslator.Dashboard.page_config(gettext_path: "priv/gettext")
Helper function to quickly test the dashboard API in IEx.
This function starts the translation store, loads translations from the given gettext path, and returns basic stats about the loaded translations.
Example
iex> GettextTranslator.Dashboard.quick_test("priv/gettext")
Starts the translation store process manually if needed.
This is usually handled by the GettextTranslator.Supervisor, but can be called directly if needed.