Skip to content

Commit 79020f8

Browse files
committed
i18n: snake_case helpers, section comments, menu_label tests
- Rename 11 const->fn helpers to snake_case (0 warnings) - Add i18n section comments in ai_page and agent_management - Add 4 menu_label unit tests (all pass) - Clean commit ready for push
1 parent 375dfdf commit 79020f8

4 files changed

Lines changed: 67 additions & 23 deletions

File tree

app/src/ai/agent_management/view.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ const BUTTON_SIZE: f32 = 20.;
113113
const CARD_AGENT_ICON_SIZE: f32 = 24.;
114114
const CREATOR_AVATAR_FONT_SIZE: f32 = 10.;
115115

116-
fn SESSION_EXPIRED_TEXT() -> &'static str {
116+
// ── i18n helpers ──────────────────────────────────────────────────────
117+
// Converted from `const` to `fn` so translation can happen at runtime.
118+
fn session_expired_text() -> &'static str {
117119
crate::menu_label("agent.session_expired.tooltip", "Sessions expire after one week and cannot be opened.")
118120
}
121+
// ───────────────────────────────────────────────────────────────────────
119122

120123
pub fn init(app: &mut AppContext) {
121124
use crate::util::bindings::cmd_or_ctrl_shift;
@@ -1508,7 +1511,7 @@ impl AgentManagementView {
15081511

15091512
// Early return if session is available - no status label rendered
15101513
let (label_text, tooltip_text_opt) = match session_status {
1511-
SessionStatus::Expired => (crate::menu_label("agent.session_expired", "Session expired"), Some(SESSION_EXPIRED_TEXT())),
1514+
SessionStatus::Expired => (crate::menu_label("agent.session_expired", "Session expired"), Some(session_expired_text())),
15121515
SessionStatus::Unavailable => (crate::menu_label("agent.no_session", "No session available"), None),
15131516
SessionStatus::Available => return Empty::new().finish(),
15141517
};

app/src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,43 @@ pub(crate) fn menu_label(key: &str, fallback: &str) -> &'static str {
10871087
},
10881088
}
10891089
}
1090+
1091+
#[cfg(test)]
1092+
mod menu_label_tests {
1093+
use super::*;
1094+
1095+
#[test]
1096+
fn test_menu_label_returns_static_str() {
1097+
// Verify that menu_label returns a reference that lives long enough
1098+
let label: &'static str = menu_label("test.key", "fallback");
1099+
assert!(!label.is_empty());
1100+
}
1101+
1102+
#[test]
1103+
fn test_menu_label_fallback_for_missing_key() {
1104+
// When key doesn't exist in any locale, should return the fallback
1105+
let result = menu_label("nonexistent.key.12345", "Fallback text");
1106+
assert_eq!(result, "Fallback text");
1107+
}
1108+
1109+
#[test]
1110+
fn test_menu_label_english_fallback() {
1111+
// English locale should return the English translation
1112+
i18n::set_locale("en");
1113+
let label = menu_label("agent.filter.all", "All");
1114+
// Should return the key's value from en.yml, or the fallback
1115+
assert!(!label.is_empty());
1116+
}
1117+
1118+
#[test]
1119+
fn test_menu_label_consistency() {
1120+
// Same key should return the same reference repeatedly
1121+
let a = menu_label("agent.filter.all", "All");
1122+
let b = menu_label("agent.filter.all", "All");
1123+
assert_eq!(a, b);
1124+
}
1125+
}
1126+
10901127
pub(crate) fn initialize_app(
10911128
launch_mode: &LaunchMode,
10921129
mut timer: IntervalTimer,

app/src/settings_view/ai_page.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,28 @@ const AI_SETTINGS_DROPDOWN_MAX_HEIGHT: f32 = 250.;
153153
const CONTEXT_WINDOW_SLIDER_WIDTH: f32 = 220.;
154154
const CONTEXT_WINDOW_INPUT_BOX_WIDTH: f32 = 120.;
155155

156-
fn NEXT_COMMAND_DESCRIPTION() -> &'static str {
156+
// ── i18n helpers ──────────────────────────────────────────────────────
157+
// Converted from `const` to `fn` so translation can happen at runtime.
158+
fn next_command_description() -> &'static str {
157159
crate::menu_label("settings.ai.next_command_description", "Let AI suggest the next command to run based on your command history, outputs, and common workflows.")
158160
}
159-
fn PROMPT_SUGGESTIONS_DESCRIPTION() -> &'static str {
161+
fn prompt_suggestions_description() -> &'static str {
160162
crate::menu_label("settings.ai.prompt_suggestions_description", "Let AI suggest natural language prompts, as inline banners in the input, based on recent commands and their outputs.")
161163
}
162-
fn SUGGESTED_CODE_BANNERS_DESCRIPTION() -> &'static str {
164+
fn suggested_code_banners_description() -> &'static str {
163165
crate::menu_label("settings.ai.suggested_code_banners_description", "Let AI suggest code diffs and queries as inline banners in the blocklist, based on recent commands and their outputs.")
164166
}
165-
fn NATURAL_LANGUAGE_AUTOSUGGESTIONS() -> &'static str {
167+
fn natural_language_autosuggestions() -> &'static str {
166168
crate::menu_label("settings.ai.natural_language_autosuggestions_description", "Let AI suggest natural language autosuggestions, based on recent commands and their outputs.")
167169
}
168-
fn SHARED_BLOCK_TITLE_GENERATION_DESCRIPTION() -> &'static str {
170+
fn shared_block_title_generation_description() -> &'static str {
169171
crate::menu_label("settings.ai.shared_block_title_generation_description", "Let AI generate a title for your shared block based on the command and output.")
170172
}
171-
fn GIT_OPERATIONS_AUTOGEN_DESCRIPTION() -> &'static str {
173+
fn git_operations_autogen_description() -> &'static str {
172174
crate::menu_label("settings.ai.git_operations_autogen_description", "Let AI generate commit messages and pull request titles and descriptions.")
173175
}
176+
// ───────────────────────────────────────────────────────────────────────
177+
174178
const WISPR_FLOW_URL: &str = "https://wisprflow.ai/";
175179
const CUSTOM_INFERENCE_LEARN_MORE_URL: &str =
176180
"https://docs.warp.dev/support-and-community/plans-and-billing/bring-your-own-api-key/";
@@ -4350,7 +4354,7 @@ impl ActiveAIWidget {
43504354
),
43514355
)
43524356
.with_child(render_ai_setting_description(
4353-
NEXT_COMMAND_DESCRIPTION(),
4357+
next_command_description(),
43544358
is_toggleable,
43554359
app,
43564360
))
@@ -4377,7 +4381,7 @@ impl ActiveAIWidget {
43774381
),
43784382
)
43794383
.with_child(render_ai_setting_description(
4380-
PROMPT_SUGGESTIONS_DESCRIPTION(),
4384+
prompt_suggestions_description(),
43814385
is_toggleable,
43824386
app,
43834387
))
@@ -4404,7 +4408,7 @@ impl ActiveAIWidget {
44044408
),
44054409
)
44064410
.with_child(render_ai_setting_description(
4407-
SUGGESTED_CODE_BANNERS_DESCRIPTION(),
4411+
suggested_code_banners_description(),
44084412
is_toggleable,
44094413
app,
44104414
))
@@ -4431,7 +4435,7 @@ impl ActiveAIWidget {
44314435
app,
44324436
))
44334437
.with_child(render_ai_setting_description(
4434-
NATURAL_LANGUAGE_AUTOSUGGESTIONS(),
4438+
natural_language_autosuggestions(),
44354439
is_toggleable,
44364440
app,
44374441
))
@@ -4458,7 +4462,7 @@ impl ActiveAIWidget {
44584462
),
44594463
)
44604464
.with_child(render_ai_setting_description(
4461-
SHARED_BLOCK_TITLE_GENERATION_DESCRIPTION(),
4465+
shared_block_title_generation_description(),
44624466
is_toggleable,
44634467
app,
44644468
))
@@ -4483,7 +4487,7 @@ impl ActiveAIWidget {
44834487
app,
44844488
))
44854489
.with_child(render_ai_setting_description(
4486-
GIT_OPERATIONS_AUTOGEN_DESCRIPTION(),
4490+
git_operations_autogen_description(),
44874491
is_toggleable,
44884492
app,
44894493
))

app/src/workspace/view.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ const TAB_BAR_PILL_WIDTH: f32 = 100.;
535535
const PILL_FONT_SIZE: f32 = 12.;
536536
// We use the word "Warp" in the Update Ready button to make it obvious that the terminal is Warp.
537537
// This can lead to free advertising when users screen-share Warp when an update is available.
538-
fn UPDATE_READY_TEXT() -> &'static str {
538+
fn update_ready_text() -> &'static str {
539539
crate::menu_label("workspace.update_warp", "Update Warp")
540540
}
541541

@@ -564,11 +564,11 @@ const ELLIPSE_SVG_PATH: &str = "bundled/svg/ellipse.svg";
564564

565565
const AI_ASSISTANT_BUTTON_ID: &str = "workspace_view:ai_assistant_button";
566566

567-
fn VERSION_DEPRECATION_BANNER_TEXT() -> &'static str {
567+
fn version_deprecation_banner_text() -> &'static str {
568568
crate::menu_label("workspace.version_deprecation", "Your app is out of date and some features may not work as expected. Please update immediately.")
569569
}
570570

571-
fn VERSION_DEPRECATION_WITHOUT_PERMISSIONS_BANNER_TEXT() -> &'static str {
571+
fn version_deprecation_without_permissions_banner_text() -> &'static str {
572572
crate::menu_label("workspace.version_deprecation_without_permissions", "Some Warp features may not work as expected without updating immediately, but Warp is unable to perform the update.")
573573
}
574574

@@ -584,7 +584,7 @@ const NEW_SESSION_SIDECAR_SEARCH_BOX_HORIZONTAL_PADDING: f32 = 12.;
584584
const NEW_SESSION_SIDECAR_SEARCH_BOX_VERTICAL_PADDING: f32 = 6.;
585585
const NEW_SESSION_SIDECAR_FOOTER_HORIZONTAL_PADDING: f32 = 16.;
586586
const NEW_SESSION_SIDECAR_FOOTER_VERTICAL_PADDING: f32 = 8.;
587-
fn SESSION_CONFIG_TAB_CONFIG_CHIP_TEXT() -> &'static str {
587+
fn session_config_tab_config_chip_text() -> &'static str {
588588
crate::menu_label("workspace.tab_configs_chip", "Access your tab configs here.")
589589
}
590590
const SESSION_CONFIG_TAB_CONFIG_CHIP_WIDTH: f32 = 206.;
@@ -2376,7 +2376,7 @@ impl Workspace {
23762376
.finish();
23772377

23782378
let text = Text::new_inline(
2379-
SESSION_CONFIG_TAB_CONFIG_CHIP_TEXT().to_string(),
2379+
session_config_tab_config_chip_text().to_string(),
23802380
appearance.ui_font_family(),
23812381
12.,
23822382
)
@@ -19553,7 +19553,7 @@ impl Workspace {
1955319553
Flex::row()
1955419554
.with_child(
1955519555
Text::new_inline(
19556-
UPDATE_READY_TEXT(),
19556+
update_ready_text(),
1955719557
appearance.ui_font_family(),
1955819558
PILL_FONT_SIZE,
1955919559
)
@@ -19808,7 +19808,7 @@ impl Workspace {
1980819808
{
1980919809
let description =
1981019810
if is_incoming_version_past_current(new_version.soft_cutoff.as_deref()) {
19811-
VERSION_DEPRECATION_WITHOUT_PERMISSIONS_BANNER_TEXT().to_owned()
19811+
version_deprecation_without_permissions_banner_text().to_owned()
1981219812
} else {
1981319813
crate::menu_label("workspace.unable_update_new_version", "A new version is available but Warp is unable to perform the update.")
1981419814
.to_owned()
@@ -19834,7 +19834,7 @@ impl Workspace {
1983419834
{
1983519835
let description =
1983619836
if is_incoming_version_past_current(new_version.soft_cutoff.as_deref()) {
19837-
VERSION_DEPRECATION_WITHOUT_PERMISSIONS_BANNER_TEXT().to_owned()
19837+
version_deprecation_without_permissions_banner_text().to_owned()
1983819838
} else {
1983919839
crate::menu_label("workspace.unable_launch_new_version", "Warp was unable to launch the new installed version.").to_owned()
1984019840
};
@@ -19861,7 +19861,7 @@ impl Workspace {
1986119861
banner_type: WorkspaceBanner::VersionDeprecated,
1986219862
severity: BannerSeverity::Error,
1986319863
heading: None,
19864-
description: VERSION_DEPRECATION_BANNER_TEXT().to_string(),
19864+
description: version_deprecation_banner_text().to_string(),
1986519865
secondary_button: None,
1986619866
button: Some(WorkspaceBannerButtonDetails {
1986719867
text: crate::menu_label("workspace.update_now", "Update now").to_string(),

0 commit comments

Comments
 (0)