Safe Haskell | None |
---|---|
Language | Haskell2010 |
Human beings on our planet have, past and present, used a number of languages. There are many reasons why one would want to identify the language used when presenting or requesting information.
The language of an information item or a user's language preferences often need to be identified so that appropriate processing can be applied. For example, the user's language preferences in a Web browser can be used to select Web pages appropriately. Language information can also be used to select among tools (such as dictionaries) to assist in the processing or understanding of content in different languages. Knowledge about the particular language used by some piece of information content might be useful or even required by some types of processing, for example, spell-checking, computer-synthesized speech, Braille transcription, or high-quality print renderings.
Synopsis
- data BCP47
- inits :: BCP47 -> [BCP47]
- mkLanguage :: ISO639_1 -> BCP47
- mkLocalized :: ISO639_1 -> Country -> BCP47
- fromText :: Text -> Either Text BCP47
- toText :: BCP47 -> Text
- toSubtags :: BCP47 -> [Subtags]
- data ISO639_1
- language :: BCP47 -> ISO639_1
- languageToText :: ISO639_1 -> Text
- languageFromText :: Text -> Either Text ISO639_1
- data LanguageExtension
- extendedLanguageSubtags :: BCP47 -> Set LanguageExtension
- languageExtensionToText :: LanguageExtension -> Text
- languageExtensionFromText :: Text -> Either Text LanguageExtension
- data Script
- script :: BCP47 -> Maybe Script
- scriptToText :: Script -> Text
- scriptFromText :: Text -> Either Text Script
- data Country
- region :: BCP47 -> Maybe Country
- regionToText :: Country -> Text
- regionFromText :: Text -> Either Text Country
- data Variant
- variants :: BCP47 -> Set Variant
- variantToText :: Variant -> Text
- variantFromText :: Text -> Either Text Variant
- data Extension
- extensions :: BCP47 -> Set Extension
- extensionToText :: Extension -> Text
- extensionFromText :: Text -> Either Text Extension
- data PrivateUse
- privateUse :: BCP47 -> Set PrivateUse
- privateUseToText :: PrivateUse -> Text
- privateUseFromText :: Text -> Either Text (Set PrivateUse)
- en :: BCP47
- es :: BCP47
- sw :: BCP47
- enGB :: BCP47
- enUS :: BCP47
- enTJP :: BCP47
- enGBTJP :: BCP47
Documentation
A language tag
Language tags are used to help identify languages, whether spoken, written, signed, or otherwise signaled, for the purpose of communication. This includes constructed and artificial languages but excludes languages not intended primarily for human communication, such as programming languages.
inits :: BCP47 -> [BCP47] Source #
Produce a list of (<= priority)
language tags
>>>
inits enGBTJP
[en,en-GB,en-GB-t-jp]
Construction
mkLanguage :: ISO639_1 -> BCP47 Source #
Construct a simple language tag
fromText :: Text -> Either Text BCP47 Source #
Parse a language tag from text
>>>
fromText $ pack "en"
Right en
>>>
fromText $ pack "de-CH"
Right de-CH
>>>
fromText $ pack "ru-USR"
Left "fromText:1:3:\n |\n1 | ru-USR\n | ^\nunexpected '-'\n"
>>>
fromText $ pack "en-a-ccc-v-qqq-a-bbb"
Right en-a-bbb-a-ccc-v-qqq
>>>
fromText $ pack "de-Latn-DE"
Right de-Latn-DE
>>>
fromText $ pack "de-Latf-DE"
Right de-Latf-DE
>>>
fromText $ pack "de-CH-1996"
Right de-CH-1996
>>>
fromText $ pack "de-Deva"
Right de-Deva
>>>
fromText $ pack "zh-Hant-CN-x-private1-private2"
Right zh-Hant-CN-x-private1-private2
>>>
fromText $ pack "zh-Hant-CN-x-private1"
Right zh-Hant-CN-x-private1
>>>
fromText $ pack "zh-Hant-CN"
Right zh-Hant-CN
>>>
fromText $ pack "zh-Hant"
Right zh-Hant
>>>
fromText $ pack "zh"
Right zh
Serialization
Subtags
A language tag is composed from a sequence of one or more "subtags", each of which refines or narrows the range of language identified by the overall tag. Subtags, in turn, are a sequence of alphanumeric characters (letters and digits), distinguished and separated from other subtags in a tag by a hyphen ("-", [Unicode] U+002D).
Language
Instances
Enum ISO639_1 | |
Eq ISO639_1 | |
Ord ISO639_1 | |
Defined in Data.LanguageCodes | |
Read ISO639_1 | |
Show ISO639_1 | |
languageToText :: ISO639_1 -> Text Source #
Language Extension
data LanguageExtension Source #
Extended language subtags
These are used to identify certain specially selected languages that, for various historical and compatibility reasons, are closely identified with or tagged using an existing primary language subtag.
Instances
Eq LanguageExtension Source # | |
Defined in Data.BCP47.Internal.LanguageExtension (==) :: LanguageExtension -> LanguageExtension -> Bool # (/=) :: LanguageExtension -> LanguageExtension -> Bool # | |
Ord LanguageExtension Source # | |
Defined in Data.BCP47.Internal.LanguageExtension compare :: LanguageExtension -> LanguageExtension -> Ordering # (<) :: LanguageExtension -> LanguageExtension -> Bool # (<=) :: LanguageExtension -> LanguageExtension -> Bool # (>) :: LanguageExtension -> LanguageExtension -> Bool # (>=) :: LanguageExtension -> LanguageExtension -> Bool # max :: LanguageExtension -> LanguageExtension -> LanguageExtension # min :: LanguageExtension -> LanguageExtension -> LanguageExtension # | |
Show LanguageExtension Source # | |
Defined in Data.BCP47.Internal.LanguageExtension showsPrec :: Int -> LanguageExtension -> ShowS # show :: LanguageExtension -> String # showList :: [LanguageExtension] -> ShowS # | |
Arbitrary LanguageExtension Source # | |
Defined in Data.BCP47.Internal.LanguageExtension |
extendedLanguageSubtags :: BCP47 -> Set LanguageExtension Source #
Look up all language extension subtags
languageExtensionFromText :: Text -> Either Text LanguageExtension Source #
Parse a LanguageExtension
subtag from Text
Language Script
Script subtags
Script subtags are used to indicate the script or writing system variations that distinguish the written forms of a language or its dialects.
scriptToText :: Script -> Text Source #
Region
A country recognized by ISO 3166.
Instances
Bounded Country | |
Enum Country | |
Eq Country | |
Ord Country | |
Show Country | |
Generic Country | |
Hashable Country | |
Defined in Country.Unexposed.Names | |
ToJSON Country | |
Defined in Country.Unexposed.Names | |
FromJSON Country | |
Storable Country | |
NFData Country | |
Defined in Country.Unexposed.Names | |
Prim Country | |
Defined in Country.Unexposed.Names alignment# :: Country -> Int# # indexByteArray# :: ByteArray# -> Int# -> Country # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, Country#) # writeByteArray# :: MutableByteArray# s -> Int# -> Country -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Country -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> Country # readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, Country#) # writeOffAddr# :: Addr# -> Int# -> Country -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> Country -> State# s -> State# s # | |
type Rep Country | |
Defined in Country.Unexposed.Names |
regionToText :: Country -> Text Source #
regionFromText :: Text -> Either Text Country Source #
Parse a region subtag from Text
>>>
regionFromText $ pack "ZW"
Right zimbabwe
>>>
regionFromText $ pack "012"
Right algeria
>>>
regionFromText $ pack "asdf"
Left "regionFromText:1:1:\n |\n1 | asdf\n | ^\nunexpected 'a'\nexpecting 2 or 3 character country code\n"
Variant
Variant subtags
Variant subtags are used to indicate additional, well-recognized variations that define a language or its dialects that are not covered by other available subtags.
variantToText :: Variant -> Text Source #
Extension
Extension subtags
Extensions provide a mechanism for extending language tags for use in various applications. They are intended to identify information that is commonly used in association with languages or language tags but that is not part of language identification.
extensionToText :: Extension -> Text Source #
Private Use
data PrivateUse Source #
Private Use subtags
Private use subtags are used to indicate distinctions in language that are important in a given context by private agreement.
Instances
Eq PrivateUse Source # | |
Defined in Data.BCP47.Internal.PrivateUse (==) :: PrivateUse -> PrivateUse -> Bool # (/=) :: PrivateUse -> PrivateUse -> Bool # | |
Ord PrivateUse Source # | |
Defined in Data.BCP47.Internal.PrivateUse compare :: PrivateUse -> PrivateUse -> Ordering # (<) :: PrivateUse -> PrivateUse -> Bool # (<=) :: PrivateUse -> PrivateUse -> Bool # (>) :: PrivateUse -> PrivateUse -> Bool # (>=) :: PrivateUse -> PrivateUse -> Bool # max :: PrivateUse -> PrivateUse -> PrivateUse # min :: PrivateUse -> PrivateUse -> PrivateUse # | |
Show PrivateUse Source # | |
Defined in Data.BCP47.Internal.PrivateUse showsPrec :: Int -> PrivateUse -> ShowS # show :: PrivateUse -> String # showList :: [PrivateUse] -> ShowS # | |
Arbitrary PrivateUse Source # | |
Defined in Data.BCP47.Internal.PrivateUse arbitrary :: Gen PrivateUse # shrink :: PrivateUse -> [PrivateUse] # |
privateUse :: BCP47 -> Set PrivateUse Source #
Look up all private use subtags
privateUseToText :: PrivateUse -> Text Source #
privateUseFromText :: Text -> Either Text (Set PrivateUse) Source #
Parse a PrivateUse
subtag from Text