alanvardy/exzeitable

Localise the data content (like field names and actions)

Closed this issue · 2 comments

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:

  1. 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 calling gettext for the labels.
  2. Localised actions (edit, delete, ...). Similarly, call gettext if a gettext module is configured
  3. 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:

  1. Labels are translated
  2. Action buttons are translated
  3. The :title field is formatted before presentation with Cldr.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.

Hello @kipcole9 !

Thank you for the issue, yes I think that the addition of a formatter function is a great idea. If you create a PR implementing it I would be very happy to work with you to get it merged 👍

PR received and merged 👍

#357