An open API service indexing awesome lists of open source software.

https://github.com/elixir-cldr/cldr_html

Phoenix HTML helpers for CLDR
https://github.com/elixir-cldr/cldr_html

Last synced: 12 months ago
JSON representation

Phoenix HTML helpers for CLDR

Awesome Lists containing this project

README

          

# Cldr HTML

Phoenix form select helper functions for CLDR. The functions in this library produce localised selection tags for HTML forms for:

* Currencies
* Units
* Territories
* Locales

## Usage

* `Cldr.HTML.Currency.select/3`. By default the currencies of the locales configured in the default backend. See also the documentation for [ex_cldr_currencies](https://hexdocs.pm/ex_cldr_currencies).

* `Cldr.HTML.Unit.select/3`. By default the units returned by `Cldr.Unit.known_units/0`. See also the documentation for [ex_cldr_units](https://hexdocs.pm/ex_cldr_units).

* `Cldr.HTML.Territory.select/3`. By default the territories returned by `Cldr.known_territories/0`. See also the documentation for [ex_cldr_territories](https://hexdocs.pm/ex_cldr_territories)

* `Cldr.HTML.Locale.select/3`. By default the list of locales known to `Cldr.default_backend!/0`. See also the documentation for [ex_cldr_locale_display](https://hexdocs.pm/ex_cldr_locale_display).

* [Not Yet Implemented] Select days of the week and months of the year in a given locale.

## Currency selection

```elixir
iex> Cldr.HTML.Currency.select(:my_form, :currency, selected: :USD, currencies: ~w(usd eur jpy cop)) |> Phoenix.HTML.safe_to_string()
```
Produces, when formatted:
```html

COP - Colombian Peso
EUR - Euro
JPY - Japanese Yen
USD - US Dollar

```

## Unit selection

```elixir
iex> Cldr.HTML.Unit.select(:my_form, :units) |> Phoenix.HTML.safe_to_string()
```
Produces, when formatted:
```html

acres
acre-feet
amperes
arcminutes
arcseconds
astronomical units
atmospheres
bars
barrels
bits
British thermal units
bushels
bytes
calories
candela
carats
degrees Celsius
....

```

## Territory selection

```elixir
iex> Cldr.HTML.Territory.select(:my_form, :territory, territories: [:US, :AU, :JP]) |> Phoenix.HTML.safe_to_string()
```
Produces, when formatted:
```html

🇦🇺 Australia
🇯🇵 Japan
🇺🇸 United States

```
## Locale selection

```elixir
# Select from the locales configured in `Cldr.default_backend/0` and localize them
# using the locale `Cldr.default_locale/0`
iex> Cldr.HTML.Locale.select(:my_form, :locales) |> Phoenix.HTML.safe_to_string()
```
Produces, when formatted:
```html

Arabic
Chinese (Simplified)
Chinese (Traditional)
English
Hebrew
Thai

```

```elixir
# Select from the locales configured in `Cldr.default_backend/0` and localize them
# using their own locale`
iex> Cldr.HTML.Locale.select(:my_form, :locales, locale: :identity) |> Phoenix.HTML.safe_to_string()
```
Produces, when formatted:
```html

English
עברית
العربية
ไทย
简体中文
繁體中文

```

## Installation

`Cldr.HTML` can be installed by adding `cldr_html` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:cldr_html, "~> 0.6"}
]
end
```
The documentation can be found at [https://hexdocs.pm/cldr_html](https://hexdocs.pm/cldr_html).

## Configuration

The available functions depends on the configured dependencies in `mix.exs`:

For `Cldr.HTML.Currency.select/3`:

{:ex_cldr_currencies, "~> 2.11"},

For `Cldr.HTML.Unit.select/3`:

{:ex_cldr_units, "~> 3.7"},

For `Cldr.HTML.Locale.select/3`:

{:ex_cldr_locale_display, "~> 1.0"},

For `Cldr.HTML.Territory.select/3`:

{:ex_cldr_territories, "~> 2.2"},