Localise the data content (like field names and actions)
Closed this issue · 2 comments
kipcole9 commented
Its great to see that the UI chrome can be customised with the :text
option which can therefore make it straight forward to localise the table text. However the field names and actions appear to be static text?
This feature request is to support localised labels, actions and formatting for data content:
- Localised field labels. One option would be to call
gettext
on the existing label and add a gettext module to the table configuration to trigger callinggettext
for the labels. - Localised actions (edit, delete, ...). Similarly, call
gettext
if agettext
module is configured - Localised content. I recognise that this can be achieved by defining all the fields as
:virtual
and implementing a function for each field. But perhaps a:formatter
option for the:field
definition could be added that would make this configurable.
With these suggestions, a configuration could look like:
defmodule YourAppWeb.Live.File do
@moduledoc "User's File table"
alias YourAppWeb.Router.Helpers, as: Routes
import Ecto.Query
use Exzeitable,
# Required
repo: YourApp.Repo,
gettext: YourApp.Gettext,
routes: Routes,
path: :file_path,
action_buttons: [:show, :edit, :custom_button],
query: from(f in File),
fields: [
image: [virtual: true],
title: [hidden: true, formatter: &Cldr.to_string/1],
description: [hidden: true],
]
Which is completely backwards compatible but has the following behaviour because :gettext
is specified:
- Labels are translated
- Action buttons are translated
- The
:title
field is formatted before presentation withCldr.to_string/1
(which in this case happens to localise dates, times, units of measure, money, .....)
If this is something you see as being in scope for the project, I will consider creating a PR along these lines.
BTW, found your project via elixircasts - what a great find, really happy you built this.