Skip to content

Commit

Permalink
Merge pull request #181 from theseus-rs/add-i18n-support-to-expanded-…
Browse files Browse the repository at this point in the history
…format

feat: add i18n support to expanded format
  • Loading branch information
brianheineman authored Aug 25, 2024
2 parents 93d8f1c + 6458b34 commit 169350a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 36 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install cargo audit
run: cargo install cargo-audit
- name: Audit dependencies
run: cargo audit --ignore RUSTSEC-2023-0071 --ignore RUSTSEC-2024-0320
run: cargo audit --ignore RUSTSEC-2023-0071 --ignore RUSTSEC-2024-0320 --ignore RUSTSEC-2024-0363

check:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -50,19 +50,19 @@ jobs:
run: |
cargo clippy --all-targets --all-features --examples --tests
# deny:
# runs-on: ubuntu-22.04
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Install Rust
# uses: dtolnay/rust-toolchain@master
# with:
# toolchain: stable
# - name: Install cargo deny
# run: cargo install cargo-deny
# - name: Check licenses
# run: cargo deny check --allow duplicate
deny:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Install cargo deny
run: cargo install cargo-deny
- name: Check licenses
run: cargo deny check --allow duplicate

doc:
runs-on: ubuntu-22.04
Expand Down
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sqlx = "0.7.4"
supports-color = "3.0.0"
sys-locale = "0.3.1"
syntect = "5.2.0"
tabled = "0.15.0"
tabled = "0.16.0"
tempfile = "3.11.0"
termbg = "0.5.0"
test-log = "0.2.16"
Expand All @@ -71,7 +71,7 @@ tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-indicatif = "0.3.6"
tracing-subscriber = "0.3.18"
unicode-width = "0.1.13"
unicode-width = "0.1.11"
url = "2.5.2"
uuid = "1.10.0"

Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ allow = [
ignore = [
"RUSTSEC-2023-0071",
"RUSTSEC-2024-0320",
"RUSTSEC-2024-0363",
]

# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html
Expand Down
20 changes: 9 additions & 11 deletions rsql_formatters/src/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::writers::Output;
use crate::Results;
use crate::Results::Query;
use async_trait::async_trait;
use num_format::Locale;
use num_format::{Locale, ToFormattedString};
use rsql_drivers::{QueryResult, Value};
use std::str::FromStr;
use tabled::tables::ExtendedTable;
Expand Down Expand Up @@ -36,14 +36,12 @@ impl crate::Formatter for Formatter {
let mut data: Vec<Vec<String>> = Vec::new();
data.push(query_result.columns().await);
rows = process_data(options, query_result, &mut data).await?;
// let locale = options.locale.clone();
let table = ExtendedTable::from(data);
// Update to defined version once https://github.com/zhiburt/tabled/pull/412 is released
// let table = ExtendedTable::from(data).template(move |index| {
// let format_locale = Locale::from_str(&locale).unwrap_or(Locale::en);
// let record = (index + 1).to_formatted_string(&format_locale);
// t!("expanded_record", locale = &locale, record = record).to_string()
// });
let locale = options.locale.clone();
let table = ExtendedTable::from(data).template(move |index| {
let format_locale = Locale::from_str(&locale).unwrap_or(Locale::en);
let record = (index + 1).to_formatted_string(&format_locale);
t!("expanded_record", locale = &locale, record = record).to_string()
});

writeln!(output, "{table}")?;
}
Expand Down Expand Up @@ -115,10 +113,10 @@ mod tests {

let expanded_output = output.to_string().replace("\r\n", "\n");
let expected = indoc! {r"
-[ RECORD 0 ]-
-[ RECORD 1 ]-
id | 1,234
value | foo
-[ RECORD 1 ]-
-[ RECORD 2 ]-
id | 5,678
value | NULL
2 rows (9ns)
Expand Down

0 comments on commit 169350a

Please sign in to comment.