Description
Localised list formatting based upon the CLDR data.
Ex_Cldr_Lists alternatives and similar packages
Based on the "Text and Numbers" category.
Alternatively, view Ex_Cldr_Lists alternatives based on common mentions on social networks and blogs.
-
money
Working with Money safer, easier, and fun, interpretation of the Fowler's Money pattern. -
Ex_Money
Money arithmetic, conversion, serialisation with Ecto and exchange rate service integration. -
hashids
Hashids lets you obfuscate numerical identifiers via reversible mapping. -
number
Number is a pretentiously-named Elixir library which provides functions to convert numbers into a variety of different formats. -
slugger
Slugger can generate slugs from given strings that can be used in URLs or file names. -
nanoid
Elixir port of NanoID, a secure and URL-friendly unique ID generator. -
ua_inspector
User agent parser library like piwik/device-detector. -
secure_random
Convenience library for random base64 strings modeled after my love for Ruby's SecureRandom. -
chinese_translation
Translate between traditional chinese and simplified chinese based on wikipedia data, and translate chinese words/characters to pinyin (or slug with or without tone). -
veritaserum
Sentiment analysis based on afinn-165, emojis and some enhancements. -
brcpfcnpj
Number format and Validate, to the documents brazilians (CPF/CNPJ). -
sentient
Simple sentiment analysis based on the AFINN-111 wordlist. -
inet_cidr
Classless Inter-Domain Routing (CIDR) for Elixir that is compatible with :inet and supports both IPv4 and IPv6. -
haikunator
Generate Heroku-like memorable random names to use in your apps or anywhere else. -
Ex_Cldr_Numbers
CLDR-based Number and Currency Localization and Formatting -
mbcs
Wrapper for erlang-mbcs. This module provides functions for character encoding conversion. -
expr
An Elixir library for parsing and evaluating mathematical expressions. -
unit_fun
Attempt to add units to numbers in elixir to give some added type saftey when dealing with numeric quantities. -
mt940
MT940 (standard structured SWIFT Customer Statement message) parser for Elixir. -
custom_base
Allow you to make custom base conversion in Elixir. -
Ex_Cldr_Units
SI Unit formatting, localisation, arithmetic and conversion based on the CLDR data -
bencode
A Bencode encoder and decoder for Elixir. The decoder will return the checksum value of the info dictionary, if an info dictionary was found in the input.
Scout APM - Leading-edge performance monitoring starting at $39/month
Do you think we are missing an alternative of Ex_Cldr_Lists or a related project?
README
Cldr for Lists
Introduction and Getting Started
ex_cldr_lists
is an add-on library for ex_cldr that provides localisation and formatting for lists.
Cldr
interprets the CLDR rules for list formatting in a locale-specific way.
Configuration
From ex_cldr version 2.0, 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"
end
Installation
Note that :ex_cldr_lists
requires Elixir 1.5 or later.
Add ex_lists
as a dependency to your mix
project:
defp deps do
[
{:ex_cldr_lists, "~> 2.0"}
]
end
then retrieve ex_cldr_lists
from hex:
mix deps.get
mix deps.compile
Public API & Examples
There are two common public API functions:
MyApp.Cldr.List.to_string/2
&MyApp.Cldr.List.to_string!/2
which take a list of terms and returns a string. Each item in the list must be understood byKernel.to_string/1
MyApp.Cldr.List.intersperse/2
&MyApp.Cldr.List.intersperse!/2
which takes a list of terms and returns a list interspersed within the list format. This function can be helpful when creating a list fromPhoenix
safe strings which are of the format{:safe, "some string"}
For help in iex
:
iex> h MyApp.Cldr.List.to_string
iex> h MyApp.Cldr.List.intersperse
List Formatting
iex> MyApp.Cldr.List.list_formats_for "en"
[:or, :standard, :standard_short, :unit, :unit_narrow, :unit_short]
iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "en")
{:ok, "a, b, and c"}
iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "en", format: :or)
{:ok, "a, b, or c"}
iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "en", format: :unit)
{:ok, "a, b, c"}
iex> MyApp.Cldr.List.to_string!(["a", "b", "c"], locale: "en", format: :unit)
"a, b, c"
iex> MyApp.Cldr.List.intersperse(["a", "b", "c"], locale: "en")
{:ok, ["a", ", ", "b", ", and ", "c"]}
List Formats
List formats are referred to by a pattern style the standardises the way to refernce different formats in a locale. See MyApp.Cldr.List.list_formats_for/1
. For example:
iex> MyApp.Cldr.List.list_formats_for "en"
[:standard, :standard_short, :unit, :unit_narrow, :unit_short]
iex> MyApp.Cldr.List.list_formats_for "ru"
[:standard, :standard_short, :unit, :unit_narrow, :unit_short]
iex> MyApp.Cldr.List.list_formats_for "th"
[:standard, :standard_short, :unit, :unit_narrow, :unit_short]
Known formats
The common formats for a locale are:
- :or,
- :or_narrow,
- :or_short,
- :standard,
- :standard_narrow,
- :standard_short,
- :unit,
- :unit_narrow,
- :unit_short
This list is not fixed or definitive, other formats may be present for a locale.
The definitions of these formats can be explored through MyApp.Cldr.List.list_patterns_for/1
. For example:
iex> MyApp.Cldr.List.list_patterns_for "fr"
%{standard: %{"2": "{0} et {1}", end: "{0} et {1}", middle: "{0}, {1}",
start: "{0}, {1}"},
standard_short: %{"2": "{0} et {1}", end: "{0} et {1}", middle: "{0}, {1}",
start: "{0}, {1}"},
unit: %{"2": "{0} et {1}", end: "{0} et {1}", middle: "{0}, {1}",
start: "{0}, {1}"},
unit_narrow: %{"2": "{0} {1}", end: "{0} {1}", middle: "{0} {1}",
start: "{0} {1}"},
unit_short: %{"2": "{0} et {1}", end: "{0} et {1}", middle: "{0}, {1}",
start: "{0}, {1}"}}