Skip to content

Commit

Permalink
lang: uk: add initial support (#19)
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
pavloslav authored Dec 15, 2023
1 parent a57bc21 commit 7c762ac
Show file tree
Hide file tree
Showing 8 changed files with 1,529 additions and 12 deletions.
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ $ num2words --help

Here is a list of all of the supported languages:

| Flag | Code | ISO 639-1 | Language | 42 |
| ---- | --------------- | --------- | -------- | --------- |
| 🇺🇸🇬🇧 | `Lang::English` | `en` | English | forty-two |
| Flag | Code | ISO 639-1 | Language | 42 |
| ---- | ----------------- | --------- | ---------- | --------- |
| 🇺🇸🇬🇧 | `Lang::English` | `en` | English | forty-two |
| 🇺🇦 | `Lang::Ukrainian` | `uk` | Ukrainian | сорок два |

This list can be expanded! Contributions are welcomed.

Expand Down
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 declension: lang::uk::Declension = 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, declension))
}
}
}
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

0 comments on commit 7c762ac

Please sign in to comment.