Skip to content

Commit

Permalink
feat: add support for i18n (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Sep 30, 2024
1 parent c20e334 commit b9c5aaa
Show file tree
Hide file tree
Showing 36 changed files with 951 additions and 233 deletions.
329 changes: 310 additions & 19 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ petgraph = "0.6.5"
pretty_assertions = "1.4.1"
rand = "0.8.5"
ratatui = "0.28.1"
rust-i18n = "3.1.2"
serde = { version = "1.0.201", default-features = false }
serde_json = { version = "1.0.117", default-features = false }
serde_with = "3.9.0"
serde_yaml = "=0.9.33"
socket2 = "0.5.7"
strum = { version = "0.26.3", default-features = false }
sys-locale = "0.3.1"
test-case = "3.3.1"
thiserror = "1.0.60"
tokio = "1.40.0"
Expand All @@ -76,6 +78,7 @@ tracing = "0.1.40"
tracing-chrome = "0.7.2"
tracing-subscriber = { version = "0.3.18", default-features = false }
tun2 = "2.0.9"
unicode-width = "0.2.0"
widestring = "1.0.2"
windows-sys = "0.52.0"

Expand Down
9 changes: 0 additions & 9 deletions crates/trippy-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ impl PrivilegeMode {
}
}

impl Display for PrivilegeMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Privileged => write!(f, "privileged"),
Self::Unprivileged => write!(f, "unprivileged"),
}
}
}

/// The ICMP extension parsing mode.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum IcmpExtensionParseMode {
Expand Down
3 changes: 3 additions & 0 deletions crates/trippy-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ itertools.workspace = true
maxminddb.workspace = true
petgraph.workspace = true
ratatui.workspace = true
rust-i18n.workspace = true
serde = { workspace = true, default-features = false, features = [ "derive" ] }
serde_json.workspace = true
serde_with.workspace = true
strum = { workspace = true, default-features = false, features = [ "std", "derive" ] }
sys-locale.workspace = true
thiserror.workspace = true
toml = { workspace = true, default-features = false, features = [ "parse" ] }
tracing-chrome.workspace = true
tracing-subscriber = { workspace = true, default-features = false, features = [ "env-filter", "json" ] }
tracing.workspace = true
unicode-width.workspace = true

[dev-dependencies]
insta = { workspace = true, features = ["serde"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/trippy-tui/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// A no-op build script to trigger a recompilation when the locales change.
fn main() {}
221 changes: 221 additions & 0 deletions crates/trippy-tui/locales/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
_version: 2
trippy:
en: "trippy"
auto:
en: "auto"
on:
en: "on"
off:
en: "off"
yes:
en: "Yes"
no:
en: "No"
none:
en: "none"
hidden:
en: "Hidden"
flow:
en: "flow"
flows:
en: "flows"
target:
en: "Target"
config:
en: "Config"
status:
en: "Status"
protocol:
en: "protocol"
as-info:
en: "as-info"
details:
en: "details"
max-hosts:
en: "max-hosts"
privacy:
en: "privacy"
privileged:
en: "privileged"
unprivileged:
en: "unprivileged"
na:
en: "n/a"
discovered:
en: "discovered %{hop_count} hops"
discovered_flows:
en: "discovered %{hop_count} hops and %{flow_count} unique %{plural_flows}"
unknown:
en: "unknown"
icmp:
en: "icmp"
udp:
en: "udp"
tcp:
en: "tcp"
status_failures:
en: "%{failure_count} of %{total_probes} (%{failure_rate}%) probes failed"
status_failed:
en: "Failed"
status_running:
en: "Running"
status_frozen:
en: "Frozen"
awaiting_data:
en: "Awaiting data..."
header_help:
en: "elp"
header_settings:
en: "ettings"
header_quit:
en: "uit"
title_hops:
en: "Hops"
title_frequency:
en: "Frequency"
title_samples:
en: "Samples"
title_traces:
en: "Traces"
title_flows:
en: "Flows"
title_map:
en: "Map"
title_help:
en: "Help"
title_settings:
en: "Settings"
bsod_failed:
en: "Trippy Failed :("
bsod_quit:
en: "Press q to quit"
hop:
en: "Hop"
rtt:
en: "RTT"
title_chart:
en: "Chart"
samples:
en: "Samples"
host:
en: "Host"
no_response:
en: "No response"
dns_failed:
en: "Failed"
dns_timeout:
en: "Timeout"
labels:
en: "labels"
not_enabled:
en: "not enabled"
not_found:
en: "not found"
awaited:
en: "awaited"
name:
en: "Name"
info:
en: "Info"
geo:
en: "Geo"
pos:
en: "Pos"
ext:
en: "Ext"
help_tagline:
en: "A network diagnostic tool"
help_show_settings:
en: "Press [%{key}] to show all settings"
help_show_bindings:
en: "Press [%{key}] to show all bindings"
help_show_columns:
en: "Press [%{key}] to show all columns"
help_license:
en: "Distributed under the Apache License 2.0"
help_copyright:
en: "Copyright 2022 Trippy Contributors"
geoip_not_enabled:
en: "GeoIp not enabled"
geoip_no_data_for_hop:
en: "No GeoIp data for hop"
geoip_multiple_data_for_hop:
en: "Multiple GeoIp locations for hop"
kilometer:
en: "km"
settings_info:
en: "Info"
settings_tab_tui_title:
en: "Tui"
settings_tab_trace_title:
en: "Trace"
settings_tab_dns_title:
en: "DNS"
settings_tab_geoip_title:
en: "GeoIp"
settings_tab_bindings_title:
en: "Bindings"
settings_tab_theme_title:
en: "Theme"
settings_tab_columns_title:
en: "Columns"
settings_tab_tui_desc:
en: "Settings which control how data is displayed in this Tui"
settings_tab_trace_desc:
en: "Settings which control the tracing strategy"
settings_tab_dns_desc:
en: "Settings which control how DNS lookups are performed"
settings_tab_geoip_desc:
en: "Settings relating to GeoIp"
settings_tab_bindings_desc:
en: "Tui key bindings"
settings_tab_theme_desc:
en: "Tui theme colors"
settings_tab_columns_desc:
en: "Tui table columns. Press [%{c}] to toggle a column on or off and use the [%{d}] and [%{u}] keys to change the column order."
settings_table_header_setting:
en: "Setting"
settings_table_header_value:
en: "Value"
column_host:
en: "Host"
column_loss_pct:
en: "Loss%"
column_snd:
en: "Snd"
column_recv:
en: "Recv"
column_last:
en: "Last"
column_avg:
en: "Avg"
column_best:
en: "Best"
column_wrst:
en: "Wrst"
column_stdev:
en: "StDev"
column_sts:
en: "Sts"
column_jttr:
en: "Jttr"
column_javg:
en: "Javg"
column_jmax:
en: "Jmax"
column_jint:
en: "Jint"
column_sprt:
en: "Sprt"
column_dprt:
en: "Dprt"
column_seq:
en: "Seq"
column_type:
en: "Type"
column_code:
en: "Code"
column_nat:
en: "Nat"
column_fail:
en: "Fail"
2 changes: 2 additions & 0 deletions crates/trippy-tui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::config::{LogFormat, LogSpanEvents, Mode, TrippyConfig};
use crate::frontend::TuiConfig;
use crate::geoip::GeoIpLookup;
use crate::locale::set_locale;
use crate::{frontend, report};
use anyhow::{anyhow, Error};
use std::net::IpAddr;
Expand All @@ -14,6 +15,7 @@ use trippy_privilege::Privilege;

/// Run the trippy application.
pub fn run_trippy(cfg: &TrippyConfig, pid: u16) -> anyhow::Result<()> {
set_locale(cfg.tui_locale.as_deref());
let _guard = configure_logging(cfg);
let resolver = start_dns_resolver(cfg)?;
let geoip_lookup = create_geoip_lookup(cfg)?;
Expand Down
4 changes: 4 additions & 0 deletions crates/trippy-tui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ pub struct TrippyConfig {
pub tui_icmp_extension_mode: IcmpExtensionMode,
pub tui_geoip_mode: GeoIpMode,
pub tui_max_addrs: Option<u8>,
pub tui_locale: Option<String>,
pub tui_theme: TuiTheme,
pub tui_bindings: TuiBindings,
pub mode: Mode,
Expand Down Expand Up @@ -537,6 +538,7 @@ impl TrippyConfig {
cfg_file_dns.dns_resolve_method,
constants::DEFAULT_DNS_RESOLVE_METHOD,
);
let tui_locale = cfg_layer_opt(args.tui_locale, cfg_file_tui.tui_locale);
let dns_lookup_as_info = cfg_layer_bool_flag(
args.dns_lookup_as_info,
cfg_file_dns.dns_lookup_as_info,
Expand Down Expand Up @@ -697,6 +699,7 @@ impl TrippyConfig {
tui_icmp_extension_mode,
tui_geoip_mode,
tui_max_addrs,
tui_locale,
tui_theme,
tui_bindings,
mode,
Expand Down Expand Up @@ -749,6 +752,7 @@ impl Default for TrippyConfig {
tui_icmp_extension_mode: constants::DEFAULT_TUI_ICMP_EXTENSION_MODE,
tui_geoip_mode: constants::DEFAULT_TUI_GEOIP_MODE,
tui_max_addrs: None,
tui_locale: None,
tui_theme: TuiTheme::default(),
tui_bindings: TuiBindings::default(),
mode: constants::DEFAULT_MODE,
Expand Down
4 changes: 4 additions & 0 deletions crates/trippy-tui/src/config/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ pub struct Args {
#[arg(long)]
pub tui_privacy_max_ttl: Option<u8>,

/// The locale to use for the TUI [default: auto]
#[arg(long)]
pub tui_locale: Option<String>,

/// The TUI theme colors [item=color,item=color,..]
#[arg(long, value_delimiter(','), value_parser = parse_tui_theme_color_value)]
pub tui_theme_colors: Vec<(TuiThemeItem, TuiColor)>,
Expand Down
2 changes: 2 additions & 0 deletions crates/trippy-tui/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub struct ConfigTui {
pub tui_max_addrs: Option<u8>,
pub geoip_mmdb_file: Option<String>,
pub tui_custom_columns: Option<String>,
pub tui_locale: Option<String>,
#[serde(rename = "tui-max-samples")]
pub deprecated_tui_max_samples: Option<usize>,
#[serde(rename = "tui-max-flows")]
Expand All @@ -265,6 +266,7 @@ impl Default for ConfigTui {
tui_icmp_extension_mode: Some(super::constants::DEFAULT_TUI_ICMP_EXTENSION_MODE),
tui_geoip_mode: Some(super::constants::DEFAULT_TUI_GEOIP_MODE),
tui_max_addrs: Some(super::constants::DEFAULT_TUI_MAX_ADDRS),
tui_locale: None,
geoip_mmdb_file: None,
deprecated_tui_max_samples: None,
deprecated_tui_max_flows: None,
Expand Down
Loading

0 comments on commit b9c5aaa

Please sign in to comment.