Cases a name for the context it stands in, as CLDR's context transforms say.
CLDR writes a name as it appears in the middle of a sentence. French writes language names in lower case, "français", and a menu of languages capitalizes them: "Français". CLDR records, for each locale, which kinds of name change case in which contexts, and transform/4 applies that record.
Usages
The kind of name, as CLDR names it: :languages, :script, :key_value, :calendar_field, :currency_name, :day_format_except_narrow, :day_standalone_except_narrow, :month_format_except_narrow, :month_standalone_except_narrow, :era_abbr, :era_name, :number_spellout, :relative and :typographic_names.
Contexts
:middle_of_sentenceleaves the name as CLDR writes it.:begin_sentencetitlecases its first word, in every locale.:ui_list_or_menuis a name in a menu or a list, such as a language picker. Its case is the locale's.:stand_aloneis a name that stands by itself, such as a month in a calendar header. Its case is the locale's.
Titlecasing changes the first letter of the first word and nothing else, so "español (México)" becomes "Español (México)". It follows the language's casing: Turkish and Azerbaijani titlecase "i" as "İ", and Dutch "ij" as "IJ".
Summary
Functions
Returns the contexts a name may stand in.
Cases a name for the context it stands in.
Returns the usages a context transform applies to.
Types
@type context() ::
:middle_of_sentence | :begin_sentence | :ui_list_or_menu | :stand_alone
A context a name stands in.
@type usage() ::
:languages
| :script
| :key_value
| :calendar_field
| :currency_name
| :day_format_except_narrow
| :day_standalone_except_narrow
| :month_format_except_narrow
| :month_standalone_except_narrow
| :era_abbr
| :era_name
| :number_spellout
| :relative
| :typographic_names
A kind of name a context transform applies to.
Functions
@spec contexts() :: [context(), ...]
Returns the contexts a name may stand in.
Returns
- A list of context atoms.
Examples
iex> Localize.ContextTransform.contexts()
[:middle_of_sentence, :begin_sentence, :ui_list_or_menu, :stand_alone]
@spec transform(String.t(), usage(), context(), Keyword.t()) :: {:ok, String.t()} | {:error, Exception.t()}
Cases a name for the context it stands in.
Arguments
nameis the name as CLDR writes it, a string.usageis the kind of name; see "Usages" in the module documentation.contextis the context it stands in; see "Contexts" in the module documentation.optionsis a keyword list of options.
Options
:localeis the locale the name is written in. The default isLocalize.get_locale/0.
Returns
{:ok, name}cased for the context, or{:error, exception}whennameis not a string,usageorcontextis not one listed above, or:localeis not a valid locale.
Examples
iex> Localize.ContextTransform.transform("français", :languages, :ui_list_or_menu, locale: :fr)
{:ok, "Français"}
iex> Localize.ContextTransform.transform("français", :languages, :middle_of_sentence, locale: :fr)
{:ok, "français"}
iex> Localize.ContextTransform.transform("janvier", :month_standalone_except_narrow, :stand_alone, locale: :fr)
{:ok, "Janvier"}
@spec usages() :: [usage(), ...]
Returns the usages a context transform applies to.
Returns
- A list of usage atoms.
Examples
iex> :languages in Localize.ContextTransform.usages()
true