5 releases (1 stable)

Uses old Rust 2015

1.0.0 Dec 12, 2018
0.2.1 Dec 26, 2017
0.2.0 Dec 2, 2017
0.1.1 May 2, 2017
0.1.0 Apr 18, 2017

#46 in Internationalization (i18n)

Download history 340/week @ 2021-01-10 588/week @ 2021-01-17 470/week @ 2021-01-24 483/week @ 2021-01-31 475/week @ 2021-02-07 496/week @ 2021-02-14 525/week @ 2021-02-21 411/week @ 2021-02-28 362/week @ 2021-03-07 597/week @ 2021-03-14 518/week @ 2021-03-21 565/week @ 2021-03-28 439/week @ 2021-04-04 547/week @ 2021-04-11 477/week @ 2021-04-18 332/week @ 2021-04-25

1,867 downloads per month
Used in 14 crates (10 directly)

Apache-1.0

73KB
308 lines

ISO 639 language codes

Build Status · Documentation

Introduction

When dealing with different language inputs and APIs, different standards are used to identify a language. Converting between these in an automated way can be tedious. This crate provides an enum which supports conversion from 639-1 and 639-3 and also into these formats, as well as into English names.

This crate contains the ISO 639 table in statically embedded tables. This is possibly large, but can outweight the benefits, when handling different language code formats, e.g. when handling API data from Wikipedia and FreeDict.

Conditional compilation to reduce code size is not supported at the moment.

This crate is licensed under the Apache 2.0 license, please see LICENSE.md for the details.

Usage

Cargo.toml:

[dependencies]
isolang = "1.0"

Example

use isolang::Language;

assert_eq!(Language::from_639_1("de").unwrap().to_name(), "German");
assert_eq!(Language::from_639_3("spa").unwrap().to_639_1(), Some("es"));
// undefined language (ISO code und)
assert_eq!(Language::default(), Language::Und);

Serde support

This crate also supports serializing the Language enum. To enable this please add the following lines to your Cargo.toml (instead of the above code):

[dependencies.isolang]
features = ["serde_serialize"]
version = "1.0"

Diesel support

This crate also has experimental support for diesel. You can use the Language enum in Queryable and Insertable structs. To enable this please add the following lines to your Cargo.toml.

[dependencies.isolang]
features = ["diesel_sql"]
version = "1.0"

Dependencies

~63–740KB
~16K SLoC