Options: Horizon's own captions read a bundled language namespace (#1672)

The settings screen's own options (controller, vibration, dead zones and the
rest) are not vanilla options and have no vanilla keys, so their captions
were English literals. They now read horizon.options.* from assets/horizon/lang,
which the client bundles as one more language source placed first, so a pack
or the prepared root can still override it. English and Russian ship here.
This commit is contained in:
Alexander Krylov
2026-10-25 02:51:11 +03:00
parent 76638aaf80
commit e30166f23b
4 changed files with 80 additions and 14 deletions
@@ -0,0 +1,16 @@
{
"horizon.menu.friends": "Friends",
"horizon.options.controller": "Controller",
"horizon.options.vibration": "Vibration",
"horizon.options.adaptive_triggers": "Adaptive Triggers",
"horizon.options.lightbar": "Lightbar",
"horizon.options.look_sensitivity": "Look Sensitivity",
"horizon.options.invert_x": "Invert Look X",
"horizon.options.invert_y": "Invert Look Y",
"horizon.options.sneak_button": "Sneak Button",
"horizon.options.move_deadzone": "Move Deadzone",
"horizon.options.look_deadzone": "Look Deadzone",
"horizon.options.button_glyphs": "Button Glyphs",
"horizon.options.menu_navigation": "Menu Navigation",
"horizon.options.on_screen_keyboard": "On-Screen Keyboard"
}
@@ -0,0 +1,16 @@
{
"horizon.menu.friends": "Друзья",
"horizon.options.controller": "Геймпад",
"horizon.options.vibration": "Вибрация",
"horizon.options.adaptive_triggers": "Адаптивные триггеры",
"horizon.options.lightbar": "Подсветка",
"horizon.options.look_sensitivity": "Чувствительность обзора",
"horizon.options.invert_x": "Инверсия обзора по X",
"horizon.options.invert_y": "Инверсия обзора по Y",
"horizon.options.sneak_button": "Кнопка приседания",
"horizon.options.move_deadzone": "Мёртвая зона движения",
"horizon.options.look_deadzone": "Мёртвая зона обзора",
"horizon.options.button_glyphs": "Символы кнопок",
"horizon.options.menu_navigation": "Навигация по меню",
"horizon.options.on_screen_keyboard": "Экранная клавиатура"
}
+33
View File
@@ -29,6 +29,22 @@ pub const DEFAULT: &str = "en_us";
static CURRENT: RwLock<Option<Arc<Language>>> = RwLock::new(None);
/// Horizon's own strings, compiled in so they need no prepared resources.
struct Bundled;
impl ResourceSource for Bundled {
fn read(&self, path: &str) -> Option<Vec<u8>> {
let body = match path {
"assets/horizon/lang/en_us.json" => include_str!("../assets/horizon/lang/en_us.json"),
"assets/horizon/lang/ru_ru.json" => include_str!("../assets/horizon/lang/ru_ru.json"),
_ => return None,
};
Some(body.as_bytes().to_vec())
}
fn namespaces(&self) -> Vec<String> {
vec!["horizon".into()]
}
}
/// A source of resource files: the prepared root plus packs, highest priority last.
pub trait ResourceSource {
fn read(&self, path: &str) -> Option<Vec<u8>>;
@@ -86,6 +102,12 @@ impl Language {
if code != DEFAULT {
codes.push(code);
}
// Horizon's own strings first, so a pack or the prepared root can still
// override them. Vanilla has no key for "Controller vibration".
let bundled = Bundled;
let mut all: Vec<&dyn ResourceSource> = vec![&bundled];
all.extend_from_slice(sources);
let sources = all.as_slice();
let namespaces: std::collections::BTreeSet<String> =
sources.iter().flat_map(|s| s.namespaces()).collect();
for c in codes {
@@ -204,6 +226,17 @@ mod tests {
self.0.get(path).cloned()
}
}
#[test]
fn bundled_horizon_strings_follow_the_language() {
// No prepared resources at all: the namespace is compiled in.
let empty = Mem(HashMap::new());
let en = Language::load(&[&empty], "en_us");
assert_eq!(en.get("horizon.options.controller"), Some("Controller"));
let ru = Language::load(&[&empty], "ru_ru");
assert_eq!(ru.get("horizon.options.controller"), Some("Геймпад"));
assert_eq!(ru.get("horizon.menu.friends"), Some("Друзья"));
}
#[test]
fn layers_selected_language_over_english() {
let base = Mem(HashMap::from([
+15 -14
View File
@@ -267,20 +267,21 @@ impl Opt {
Opt::HighContrastBlockOutlines => "options.accessibility.high_contrast_block_outline",
Opt::ForceUnicode => "options.forceUnicodeFont",
Opt::JapaneseGlyphs => "options.japaneseGlyphVariants",
// Horizon's own options: English captions (no vanilla keys).
Opt::PadEnabled => "Controller",
Opt::PadVibration => "Vibration",
Opt::PadAdaptiveTriggers => "Adaptive Triggers",
Opt::PadLightbar => "Lightbar",
Opt::PadLookSensitivity => "Look Sensitivity",
Opt::PadInvertX => "Invert Look X",
Opt::PadInvertY => "Invert Look Y",
Opt::PadToggleSneak => "Sneak Button",
Opt::PadMoveDeadzone => "Move Deadzone",
Opt::PadLookDeadzone => "Look Deadzone",
Opt::PadGlyphs => "Button Glyphs",
Opt::PadMenuNav => "Menu Navigation",
Opt::PadKeyboard => "On-Screen Keyboard",
// Horizon's own options: vanilla has no keys for them, so they read
// the namespace the client bundles (assets/horizon/lang).
Opt::PadEnabled => "horizon.options.controller",
Opt::PadVibration => "horizon.options.vibration",
Opt::PadAdaptiveTriggers => "horizon.options.adaptive_triggers",
Opt::PadLightbar => "horizon.options.lightbar",
Opt::PadLookSensitivity => "horizon.options.look_sensitivity",
Opt::PadInvertX => "horizon.options.invert_x",
Opt::PadInvertY => "horizon.options.invert_y",
Opt::PadToggleSneak => "horizon.options.sneak_button",
Opt::PadMoveDeadzone => "horizon.options.move_deadzone",
Opt::PadLookDeadzone => "horizon.options.look_deadzone",
Opt::PadGlyphs => "horizon.options.button_glyphs",
Opt::PadMenuNav => "horizon.options.menu_navigation",
Opt::PadKeyboard => "horizon.options.on_screen_keyboard",
}
}
pub(crate) fn kind(self, s: &Settings) -> Kind {