Cldr for Formatting Person Names

Build statusHex.pmHex.pmHex.pmHex.pm

Introduction and Getting Started

ex_cldr_person_names is an add-on library for ex_cldr that provides localised formatting for peoples' names. It follows the CLDR Person Names specification.

Configuration

A backend module must be defined into which the public API and the CLDR data is compiled. See the ex_cldr documentation for further information on configuration.

In the following examples we assume the presence of a module called MyApp.Cldr defined as:

defmodule MyApp.Cldr do
  use Cldr,
    locales: ["en", "fr"],
    default_locale: "en",
    providers: [Cldr.PersonName]
end

Note the :provider configuration key which is required to include Cldr.PersonName in order for person name formatting to be configured for this backend.

Installation

Note that :ex_cldr_person_names requires Elixir 1.12 or later.

Add ex_cldr_person_names as a dependency to your mix project:

defp deps do
  [
    {:ex_cldr_person_names, "~> 0.1"}
  ]
end

then retrieve ex_cldr_person_names from hex:

mix deps.get
mix deps.compile

Presentations

The livebook used at the launch presentation is also available.

Run in Livebook

Why Person Name Formatting?

ex_cldr_person_names provides formatting for person names, such as John Smith or 宮崎駿 based upon the CLDR Person Names specification. These use patterns to show how a name object (for example, from a database) should be formatted for a particular locale. Name data has fields for the parts of people’s names, such as a given name field with a value of “Maria”, and a surname field value of “Schmidt”.

There is a wide variety in the way that people’s names appear in different languages.

The ex_cldr_person_names functionality is targeted at formatting names for typical usage on computers (e.g. contact names, automated greetings, etc.), rather than being designed for special circumstances or protocol, such addressing royalty. However, the structure may be enhanced in the future when it becomes clear that additional features are needed for some languages.

Not in scope

The following features are currently out of scope for Person Names formating:

Structure of a Person Name

Person name formatting depends on data supplied by a t:Cldr.PersonName.t/0 data structure. A Cldr.PersonName behaviour and a Cldr.PersonName.Format protocol are provided to support easy integration with existing data structures.

The t:Cldr.PersonName.t/0 struct is composed of one or more name parts:

At mininum, a given_name is required. All other name attributes are optional.

Integration with Existing Data

Its clear that existing person name data isn't going to be neatly structured in a t:Cldr.PersonName.t/0. ex_cldr_person_names provides two mechanisms to integrate existing data: