Skip to content

An Elixir implementation of the language_list ruby gem

License

Notifications You must be signed in to change notification settings

GunnarPDX/language_list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LanguageList

An Elixir implementation of the language_list ruby gem.

This package provides simple access to iso language names and codes.

Installation

This package can be installed by adding language_list to your list of dependencies in mix.exs:

Hex: https://hex.pm/packages/language_list

def deps do
  [
    {:language_list, "~> 2.0.0"}
  ]
end

Documentation can be found at https://hexdocs.pm/language_list.

Usage:

Standard requests will return a list of maps or strings.

Search requests return the data in a 2-tuple with the standard :ok or :error status.

Calls made to functions with ! return only the result or nil.

all_data

Returns all language data.

iex> LanguageList.all_data

[
  %{common: false, iso_639_1: "az", iso_639_3: "aze", name: "Azerbaijani"},
  %{common: false, iso_639_1: "ba", iso_639_3: "bak", name: "Bashkir"},
  ...
]

all_common_data

Returns all common data.

iex> LanguageList.all_common_data

[
  %{common: true, iso_639_1: "af", iso_639_3: "afr", name: "Afrikaans"},
  %{common: true, iso_639_1: "ar", iso_639_3: "ara", name: "Arabic"},
  ...
]

languages

Returns list of all language names.

iex> LanguageList.languages

["Afar", "Abkhazian", "Afrikaans", "Akan", "Amharic", "Arabic", ...]

common_languages

Returns list of all common languages.

iex> LanguageList.common_languages

["Afrikaans", "Arabic", "Bengali", "Tibetan", "Bulgarian", ...]

find(query, key)

Allows for query of language data by attribute.

Permitted keys: :name , :iso_639_3 , :iso_639_1

LanguageList.find!(query, key) can be called to return w/out tuple.

iex> LanguageList.find("Icelandic", :name)

{:ok, %{common: true, iso_639_1: "is", iso_639_3: "isl", name: "Icelandic"}}

iex> LanguageList.find!("Icelandic", :name)

%{common: true, iso_639_1: "is", iso_639_3: "isl", name: "Icelandic"}

iex> LanguageList.find("pt", :iso_639_1) 

{:ok, %{common: true, iso_639_1: "pt", iso_639_3: "por", name: "Portuguese"}}

iex> LanguageList.find("por", :iso_639_3)

{:ok, %{common: true, iso_639_1: "pt", iso_639_3: "por", name: "Portuguese"}}

iex> LanguageList.find("non-existent-language", :name)

{:error, "No matches found"}

iex> LanguageList.find!("non-existent-language", :name)

nil

TODO:

[] add native language names to json file.

Releases

No releases published

Packages

No packages published

Languages