#[non_exhaustive]pub enum Language {
Show 25 variants
Afrikaans,
Breton,
Catalan,
Welsh,
Danish,
German,
English,
Esperanto,
Spanish,
French,
Irish,
Galician,
Hungarian,
Icelandic,
Italian,
Latin,
Luxembourgish,
Maltese,
Dutch,
Norwegian,
Occitan,
Portuguese,
Romanian,
Albanian,
Swedish,
}Expand description
The language of a work, for csan’s language-dependent filing rules.
Parse one from an ISO 639 code, a BCP 47 tag or a POSIX locale with
FromStr ("pt-BR".parse()), or from an optional user input with
Language::from_optional. It displays as its canonical code.
Language::strip_initial_article removes a title’s initial
article in that language; the table gives each language’s codes and
articles.
| Language | Codes | Articles |
|---|---|---|
| Afrikaans | af, afr | die, 'n |
| Breton | br, bre | an, al, ar, un, ul, ur, eun, eul, eur |
| Catalan (Valencian) | ca, cat | el, els, la, les, l', un, una |
| Welsh | cy, cym, wel | y, yr |
| Danish | da, dan | de, den, det, en, et |
| German | de, deu, ger | der, die, das, ein, eine |
| English | en, eng | a, an, the |
| Esperanto | eo, epo | la |
| Spanish | es, spa | el, la, los, las, lo, un, una |
| French | fr, fra, fre | le, la, les, l', un, une |
| Irish | ga, gle | an, na |
| Galician | gl, glg | o, a, os, as, un, unha |
| Hungarian | hu, hun | a, az, egy |
| Icelandic | is, isl, ice | hinn, hin, hið, hinir, hinar |
| Italian | it, ita | il, lo, la, l', i, gli, gl', le, un, uno, una, un' |
| Latin | la, lat | |
| Luxembourgish | lb, ltz | den, de, d', deen, dat, déi, en, e, eng |
| Maltese | mt, mlt | il-, l-, iċ-, id-, in-, ir-, is-, it-, ix-, iż-, iz-, ic- |
| Dutch (Flemish) | nl, nld, dut | de, het, een, eene, 't, 'n |
| Norwegian | no, nor, nb, nob, nn, nno | de, dei, den, det, e, ei, ein, eit, en, et |
| Occitan (Provençal) | oc, oci, pro | il, l', la, las, le, les, lh, lhi, li, lis, lo, los, lou, lu, lei, leis, un, una, uno, uns, us |
| Portuguese | pt, por | o, a, os, as, um, uma |
| Romanian (Moldavian) | ro, ron, rum, mo, mol | un, o |
| Albanian | sq, sqi, alb, als, aln, aae, aat | |
| Swedish | sv, swe | de, den, det, en, ett |
An empty Articles cell means the language has no initial articles: its codes are accepted, and nothing is stripped.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Afrikaans
Afrikaans, code af.
Breton
Breton, code br.
Catalan
Catalan (Valencian), code ca.
Welsh
Welsh, code cy.
Danish
Danish, code da.
German
German, code de.
English
English, code en.
Esperanto
Esperanto, code eo.
Spanish
Spanish, code es.
French
French, code fr.
Irish
Irish, code ga.
Its articles may be followed by a t or h mutation prefix, which is
disregarded with them.
Galician
Galician, code gl.
Hungarian
Hungarian, code hu.
Icelandic
Icelandic, code is.
Italian
Italian, code it.
Latin
Latin, code la.
It has no articles (LC G 100 §9): its codes are accepted, and nothing
is stripped.
Luxembourgish
Luxembourgish, code lb.
Maltese
Maltese, code mt.
Its article is joined to the noun by a hyphen.
Dutch
Dutch (Flemish), code nl.
Norwegian
Norwegian, code no.
Bokmål and Nynorsk, in one list.
Occitan
Occitan (Provençal), code oc.
Portuguese
Portuguese, code pt.
Romanian
Romanian (Moldavian), code ro.
Albanian
Albanian, code sq.
It has no initial articles (LC G 100 §9): its codes are accepted, and
nothing is stripped.
Swedish
Swedish, code sv.
Implementations§
Source§impl Language
impl Language
Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
The English name, e.g. "Afrikaans", "Catalan (Valencian)".
Sourcepub const fn codes(self) -> &'static [&'static str]
pub const fn codes(self) -> &'static [&'static str]
Every accepted code, lowercase, canonical first, e.g.
["nl", "nld", "dut"].
Sourcepub const fn articles(self) -> &'static [&'static str]
pub const fn articles(self) -> &'static [&'static str]
The articles recognized at the start of a title: lowercase,
precomposed (NFC), as written. Elided forms end in an
apostrophe (l') and joined forms in a hyphen (Maltese il-).
Irish returns ["an", "na"]; the t/h prefixes that follow
them are a rule, not list entries. Albanian and Latin return
[].
Source§impl Language
impl Language
Sourcepub fn strip_initial_article(self, title: &str) -> Option<&str>
pub fn strip_initial_article(self, title: &str) -> Option<&str>
title without its initial article, when it starts with one that this
language recognizes and a letter or ASCII digit follows; otherwise
None, including for a title that is only an article. The result is a
subslice of title, so nothing is allocated.
The article may follow anything but a letter or ASCII digit: spaces,
punctuation, symbols ("¿El otoño?", "'t Hooft" in quotes). A word
article must then be followed by whitespace ("The, Bear" keeps its
The), an elided one by anything ("L'amour", "L' amour"), and a
joined one by a non-space ("il-Kantilena"). The result starts at the
first letter or ASCII digit after it, since MARC counts the spaces and
punctuation around an initial article as nonfiling too. Letters match
regardless of case but with their diacritics, an apostrophe matches its
typographic variants, and a hyphen its Unicode forms. Irish also loses
the t/h mutation prefix after its article. Only one article is
removed.
Three limits follow from these rules. A digit other than an ASCII one
doesn’t end the leading run, so "1 The Bear" (a fullwidth one)
loses its The. An invisible format character between an article and
its space (U+200B, U+00AD, U+FEFF) hides the article, so nothing is
stripped. And an article in another Unicode form (decomposed, or
fullwidth "The") doesn’t match: there is no normalization.
§Examples
use csan_core::Language;
let english = Language::English;
assert_eq!(english.strip_initial_article("The Bear"), Some("Bear"));
assert_eq!(english.strip_initial_article("\"The 100 best\""), Some("100 best\""));
assert_eq!(english.strip_initial_article("Theory"), None);
assert_eq!(english.strip_initial_article("The"), None);
let french = Language::French;
assert_eq!(french.strip_initial_article("L’Étranger"), Some("Étranger"));
let irish = Language::Irish;
assert_eq!(irish.strip_initial_article("An tUasal"), Some("Uasal"));Sourcepub fn from_optional(
code: Option<&str>,
) -> Result<Option<Self>, UnknownLanguage>
pub fn from_optional( code: Option<&str>, ) -> Result<Option<Self>, UnknownLanguage>
The front door for frontends, like
Attribution::from_parts: None and
blank strings mean no language (Ok(None)), and anything else parses
with FromStr.
§Errors
Returns UnknownLanguage for a non-blank code that no
supported language uses.
§Examples
use csan_core::Language;
assert_eq!(Language::from_optional(None), Ok(None));
assert_eq!(Language::from_optional(Some(" ")), Ok(None));
assert_eq!(
Language::from_optional(Some("pt-BR")),
Ok(Some(Language::Portuguese))
);
assert!(Language::from_optional(Some("xx")).is_err());Sourcepub const fn for_rule(
language: Option<Self>,
enabled: bool,
) -> Result<Option<Self>, MissingLanguage>
pub const fn for_rule( language: Option<Self>, enabled: bool, ) -> Result<Option<Self>, MissingLanguage>
The language that a rule applies with, for frontends that take a
language and an on/off switch per rule (the CLI’s --lang and
--strip-article): Ok(None) when the switch is off, and the language
when it is on.
A language with the switch off is not an error, so that a frontend can
set the language once (Typst’s cutter-sanborn.with(lang: "pt"), a
shell alias) and turn rules on per call.
§Errors
Returns MissingLanguage when the switch is on and no language is
given.
§Examples
use csan_core::{Language, MissingLanguage};
let english = Some(Language::English);
assert_eq!(Language::for_rule(english, true), Ok(english));
assert_eq!(Language::for_rule(english, false), Ok(None));
assert_eq!(Language::for_rule(None, false), Ok(None));
assert_eq!(Language::for_rule(None, true), Err(MissingLanguage));Trait Implementations§
impl Copy for Language
impl Eq for Language
Source§impl FromStr for Language
impl FromStr for Language
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses an ISO 639 code, a BCP 47 tag or a POSIX locale, in any case.
The input is trimmed and cut at its first -, _, . or @, and
that primary subtag is looked up among every language’s
codes: "pt-BR", "ca-ES-valencia", "ca@valencia"
and "pt_BR.UTF-8" all resolve. BCP 47 tags and POSIX locales are ASCII,
so non-ASCII input is an error anywhere after trimming ("en-é").
§Examples
use csan_core::Language;
assert_eq!("EN".parse(), Ok(Language::English));
assert_eq!("dut".parse(), Ok(Language::Dutch));
assert_eq!("ca-valencia".parse(), Ok(Language::Catalan));
assert!("val".parse::<Language>().is_err()); // ISO 639-3: Vehes