Module Iso639.Lang_or_family
Individual and collective languages as a unified type.
This module defines an abstract denotation of language codes of ISO 639-3 and ISO 639-5 and provides conversions to and from 2- and 3-letter codes defined in parts 1, 2, 3, and 5 of the standard.
If you only want to represent individual languages, consider using the Lang
module instead.
type t
This type represents an individual language or macrolanguage from ISO 639-3 or a language group from ISO 639-5.
Basic Operations
val equal : t -> t -> bool
equal lang1 lang2
is true iflang1
andlang2
refer to the same individual, macro-, or collective language.
val compare : t -> t -> int
Total order corresponding to lexicographic order of codes within ISO 639-3 and ISO 639-5. The order of elements belonging to different parts of the standard is left unspecified for now, and may change between versions until this notice is removed.
val pp : Stdlib.Format.formatter -> t -> unit
pp ppf lang
prints the ISO 639-3 or 639-5 language code onppf
.
val scope : t -> [> `Individual | `Macro | `Collective | `Special ]
scope lang
is`Individual
,`Macro
, or`Special
iflang
corresponds to an individual language, macro language, or special language code from ISO 639-3, and`Collective
iflang
corresponds to a language group or family form ISO 693-5.
val to_int : t -> int
An injective mapping to 16 bit integers. The result can be used for serialization, but note that the representation may change between versions until this notice is removed. An alternative for permanent storge or operability between versions, is to use
to_part3
orto_part5
or both.
val of_int_exn : int -> t
of_int_exn
is the partial inverse ofto_int
.- raises Invalid_argument
if the argument is out of range.
val of_int_unsafe : int -> t
An unchecked variant of
of_int_exn
. Integers which do not represent ISO language codes are mapped to subterranean languages which at runtime tend to erupt through the logic of the program in unpredictable ways.
Language Code Conversions
val of_string : string -> t option
of_string s
is the language or language family represented by the ISO 639-3 or 639-5 language codes
.
val to_string : t -> string
to_string lang
is the ISO 639-3 language code oflang
iflang
is an individual or macrolanguage and the 639-5 language code oflang
iflang
is a language group or family.
val is_iso639p1 : t -> bool
is_iso639p1 lang
is true ifflang
is represented in ISO 639-1.
val to_iso639p1 : t -> string option
to_iso639p1 lang
is the two-letter ISO 639-2 code forlang
if it exists.
val of_iso639p1 : string -> t option
of_iso639p1 s
is the language represented by the ISO 639-1 language codes
.
val is_iso639p2 : t -> bool
is_iso639p2 lang
is true ifflang
is represented in ISO 639-2.
val to_iso639p2t : t -> string option
to_part3t_string lang
is the three-letter ISO 639-2T code forlang
.
val to_iso639p2b : t -> string option
to_part3b_string lang
is the three-letter ISO 639-2B code forlang
.
val of_iso639p2 : string -> t option
of_iso639p2 s
is the language represented by the ISO 639 part 2T or 2B language codes
.
val is_iso639p3 : t -> bool
is_iso639p3 lang
is true ifflang
is represented in ISO 639-3, i.e. an individual language or macro language.
val to_iso639p3 : t -> string option
to_iso639p3 lang
is the three-letter ISO 639-3 code forlang
. The result coincides with the ISO 639-2 code if it exist, and may clash with an ISO 639-5 code for a language group.
val of_iso639p3 : string -> t option
of_string s
is the language represented by the ISO 639-3 language codes
.
val is_iso639p5 : t -> bool
is_iso639p3 lang
is true ifflang
is represented in ISO 693-5, i.e. a language family or group.
val to_iso639p5 : t -> string option
to_iso639p5 lang
is the three-letter ISO 639-5 code forlang
. The result coincides with the ISO 639-2 code if it exist, and may clash with an ISO 639-3 code for an individual language or macrolanguage.
val of_iso639p5 : string -> t option
of_string s
is the language family or group represented by the ISO 639-5 codes
.