Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ukrainian language support #19

Merged
merged 20 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/.vscode
1 change: 1 addition & 0 deletions src/bin/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ GLOBAL OPTIONS:

AVAILABLE LANGUAGES:
en: English
uk: Ukrainian

AVAILABLE OUTPUTS:
cardinal: forty-two (42)
Expand Down
27 changes: 24 additions & 3 deletions src/lang/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Lang {
/// );
/// ```
English,
Ukrainian,
}

impl FromStr for Lang {
Expand All @@ -31,12 +32,14 @@ impl FromStr for Lang {
/// Parses a string to return a value of this type
///
///
/// | ISO 639-1 | Lang | 42 |
/// | --------- | --------------- | --------- |
/// | `en` | `Lang::English` | forty-two |
/// | ISO 639-1 | Lang | 42 |
/// | --------- | ----------------- | --------- |
/// | `en` | `Lang::English` | forty-two |
/// | `uk` | `Lang::Ukrainian` | сорок два |
fn from_str(input: &str) -> Result<Self, Self::Err> {
match input {
"en" => Ok(Self::English),
"uk" => Ok(Self::Ukrainian),
_ => Err(()),
}
}
Expand All @@ -56,5 +59,23 @@ pub fn to_language(lang: Lang, preferences: Vec<String>) -> Box<dyn Language> {

Box::new(lang::English::new(false, false))
}
Lang::Ukrainian => {
let declination: lang::uk::Declination = preferences
.iter()
.rev()
.find_map(|d| d.parse().ok())
.unwrap_or_default();
let gender: lang::uk::Gender = preferences
.iter()
.rev()
.find_map(|d| d.parse().ok())
.unwrap_or_default();
let number: lang::uk::GrammaticalNumber = preferences
.iter()
.rev()
.find_map(|d| d.parse().ok())
.unwrap_or_default();
Box::new(lang::Ukrainian::new(gender, number, declination))
}
}
}
7 changes: 5 additions & 2 deletions src/lang/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod en;
mod lang;
mod uk;

pub use en::English;
pub use lang::Language;
pub use lang::Lang;
pub use uk::Ukrainian;

pub use lang::to_language;
pub use lang::Lang;
pub use lang::Language;
Loading