From f60a68d96dfe2d23b6f79352ce695c392473770b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Tue, 21 Jan 2020 21:05:02 +0100 Subject: [PATCH 1/6] Improve i18n "get" performances by returning a &str --- voxygen/src/i18n.rs | 6 +++--- voxygen/src/menu/char_selection/mod.rs | 3 ++- voxygen/src/menu/char_selection/ui.rs | 4 ++-- voxygen/src/menu/main/mod.rs | 2 +- voxygen/src/menu/main/ui.rs | 8 ++++---- voxygen/src/session.rs | 3 ++- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index aeb4447b7e..62f6e1bf75 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -48,10 +48,10 @@ impl VoxygenLocalization { /// /// If the key is not present in the localization object /// then the key is returned. - pub fn get(&self, key: &str) -> String { + pub fn get<'a>(&'a self, key: &'a str) -> &'a str { match self.string_map.get(key) { - Some(localized_text) => localized_text.to_owned(), - None => key.to_string(), + Some(localized_text) => localized_text, + None => key, } } diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index b1e9440b1f..30c732e9a0 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -128,7 +128,8 @@ impl PlayState for CharSelectionState { clock.get_last_delta(), |_| {}, ) { - global_state.info_message = Some(localized_strings.get("common.connection_lost")); + global_state.info_message = + Some(localized_strings.get("common.connection_lost").to_owned()); error!("[session] Failed to tick the scene: {:?}", err); return PlayStateResult::Pop; diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 223ae50d01..9fc2fe0adb 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -1135,13 +1135,13 @@ impl CharSelectionUi { self.imgs.slider_range, ); let char_slider = move |prev_id, - text: String, + text: &str, text_id, max, selected_val, slider_id, ui_widgets: &mut UiCell| { - Text::new(&text) + Text::new(text) .down_from(prev_id, 22.0) .align_middle_x_of(prev_id) .font_size(18) diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index a5e83b54db..61f264ba31 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -156,7 +156,7 @@ impl PlayState for MainMenuState { if let Some(info) = global_state.info_message.take() { self.main_menu_ui - .show_info(info, localized_strings.get("common.okay")); + .show_info(info, localized_strings.get("common.okay").to_owned()); } // Draw the UI to the screen. diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 44c1706fb3..e0852922fa 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -385,8 +385,8 @@ impl MainMenuUi { self.connect = true; self.connecting = Some(std::time::Instant::now()); self.popup = Some(PopupData { - msg: localized_strings.get("main.connecting") + "...", - button_text: localized_strings.get("common.cancel"), + msg: [localized_strings.get("main.connecting"), "..."].concat(), + button_text: localized_strings.get("common.cancel").to_owned(), popup_type: PopupType::ConnectionInfo, }); @@ -423,8 +423,8 @@ impl MainMenuUi { self.connect = true; self.connecting = Some(std::time::Instant::now()); self.popup = Some(PopupData { - msg: localized_strings.get("main.creating_world") + "...", - button_text: localized_strings.get("common.cancel"), + msg: [localized_strings.get("main.creating_world"), "..."].concat(), + button_text: localized_strings.get("common.cancel").to_owned(), popup_type: PopupType::ConnectionInfo, }); }; diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 1cc8dfc586..18cf119b7a 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -374,7 +374,8 @@ impl PlayState for SessionState { // Perform an in-game tick. if let Err(err) = self.tick(clock.get_avg_delta()) { - global_state.info_message = Some(localized_strings.get("common.connection_lost")); + global_state.info_message = + Some(localized_strings.get("common.connection_lost").to_owned()); error!("[session] Failed to tick the scene: {:?}", err); return PlayStateResult::Pop; From 8946ed8d82c392e69fda4a4e7de5781e8f9033f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Tue, 21 Jan 2020 21:10:49 +0100 Subject: [PATCH 2/6] Add missing translations in voxygen Fix #436 --- assets/voxygen/i18n/en.ron | 1 + voxygen/src/hud/settings_window.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index ad38894438..0df1307fc7 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -153,6 +153,7 @@ Want to free your cursor to close this window? Press TAB! Enjoy your stay in the World of Veloren."#, "hud.settings.general": "General", + "hud.settings.none": "None", "hud.settings.help_window": "Help Window", "hud.settings.debug_info": "Debug Info", "hud.settings.tips_on_startup": "Tips-On-Startup", diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index e5ed0e947f..9a67ed00d9 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -445,7 +445,7 @@ impl<'a> Widget for SettingsWindow<'a> { events.push(Event::UiScale(ScaleChange::ToRelative)); } - Text::new("Relative Scaling") + Text::new(self.localized_strings.get("hud.settings.relative_scaling")) .right_from(state.ids.relative_to_win_button, 10.0) .font_size(14) .font_id(self.fonts.cyri) @@ -480,7 +480,7 @@ impl<'a> Widget for SettingsWindow<'a> { events.push(Event::UiScale(ScaleChange::ToAbsolute)); } - Text::new("Custom Scaling") + Text::new(self.localized_strings.get("hud.settings.custom_scaling")) .right_from(state.ids.absolute_scale_button, 10.0) .font_size(14) .font_id(self.fonts.cyri) From c501b2d0bf18907942a751cbab0ef8f72b860220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Wed, 22 Jan 2020 22:15:19 +0100 Subject: [PATCH 3/6] Use English instead of saved language if loading fails --- voxygen/src/i18n.rs | 2 +- voxygen/src/main.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 62f6e1bf75..2cd90a3457 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -48,7 +48,7 @@ impl VoxygenLocalization { /// /// If the key is not present in the localization object /// then the key is returned. - pub fn get<'a>(&'a self, key: &'a str) -> &'a str { + pub fn get<'a>(&'a self, key: &'a str) -> &str { match self.string_map.get(key) { Some(localized_text) => localized_text, None => key, diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 7898cc2f83..829c0f7162 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -34,7 +34,7 @@ use crate::{ settings::Settings, window::Window, }; -use common::assets::load_expect; +use common::assets::{load, load_expect}; use log::{debug, error}; use std::{mem, panic, str::FromStr}; @@ -139,9 +139,20 @@ fn main() { }; // Try to load the localization and log missing entries - let localized_strings = load_expect::(&i18n_asset_key( + let localized_strings = load::(&i18n_asset_key( &global_state.settings.language.selected_language, - )); + )) + .unwrap_or_else(|error| { + log::warn!( + "Impossible to load {} language: change to the default language (English) instead. Source error: {:?}", + &global_state.settings.language.selected_language, + error + ); + global_state.settings.language.selected_language = i18n::REFERENCE_LANG.to_owned(); + load_expect::(&i18n_asset_key( + &global_state.settings.language.selected_language, + )) + }); localized_strings.log_missing_entries(); // Set up panic handler to relay swish panic messages to the user From c7271d43f10563024c4ef9d368ef744f73619e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Thu, 23 Jan 2020 23:01:14 +0100 Subject: [PATCH 4/6] Improve French translation --- assets/voxygen/i18n/fr_FR.ron | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/voxygen/i18n/fr_FR.ron b/assets/voxygen/i18n/fr_FR.ron index e6f772dd35..f2fa2acf06 100644 --- a/assets/voxygen/i18n/fr_FR.ron +++ b/assets/voxygen/i18n/fr_FR.ron @@ -145,7 +145,7 @@ Profitez de votre séjour dans le monde de Veloren."#, "hud.settings.hotbar": "Barre active", "hud.settings.toggle_bar_experience": "Activer la barre d'experience", - "hud.settings.scrolling_combat_text": "Texte de combat défillant", + "hud.settings.scrolling_combat_text": "Dégats de combat", "hud.settings.single_damage_number": "Dégat adversaire (par dégat)", "hud.settings.cumulated_damage": "Dégat adversaire (cumulé)", "hud.settings.incoming_damage": "Dégat personnage (par dégat)", @@ -190,7 +190,7 @@ Activer le mode plein écran Avancer Aller à gauche Aller à droite -Aller en arriere +Reculer Sauter @@ -198,7 +198,7 @@ Planer Esquiver -Roullade +Roulade Escalader @@ -271,12 +271,12 @@ Commandes du tchat: "esc_menu.quit_game": "Quitter le jeu", - "esc_menu.logout": "Deconnexion", + "esc_menu.logout": "Se déconnecter", "char_selection.beard": "Barbe", "char_selection.hair_style": "Coupe de cheveux", - "char_selection.hair_color": "Couleur de cheveux", + "char_selection.hair_color": "Couleur des cheveux", "char_selection.skin": "Couleur de peau", "char_selection.eyebrows": "Sourcils", "char_selection.eye_color": "Couleur des yeux", @@ -285,7 +285,7 @@ Commandes du tchat: "char_selection.create_new_charater": "Créer un nouveau personnage", "char_selection.human_default": "Humain par défault", "char_selection.uncanny_valley": "Vallée dérangeante", - "char_selection.chest_color": "Couleur du buste", + "char_selection.chest_color": "Couleur du torse", "char_selection.logout": "Se déconnecter", "char_selection.enter_world": "Entrer dans le monde", "char_selection.plains_of_uncertainty": "Plaines de l'incertitude", From 69cc30343a33c560f6689e0b0878dd0d7847c4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Sat, 25 Jan 2020 11:55:40 +0100 Subject: [PATCH 5/6] Fix disclaimer text --- assets/voxygen/i18n/en.ron | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index 0df1307fc7..005b1866bd 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -76,7 +76,8 @@ Before you dive into the fun, please keep a few things in mind: - This is a very early alpha. Expect bugs, extremely unfinished gameplay, unpolished mechanics, and missing features. - If you have constructive feedback or bug reports, you can contact us via Reddit, GitLab, or our community Discord server. -- Veloren is licensed under the GPL 3 open-source licence. That means you're free to play, modify, and redistribute the game however you wish (provided derived work is also under GPL 3). +- Veloren is licensed under the GPL 3 open-source licence. That means you're free to play, modify, and redistribute the game however + you wish (provided derived work is also under GPL 3). - Veloren is a non-profit community project, and everybody working on it is a volunteer. If you like what you see, you're welcome to join the development or art teams! - 'Voxel RPG' is a genre in its own right. First-person shooters used to be called Doom clones. From ce54f27531b805a046b4d5334ba9cc646236ff17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Mon, 27 Jan 2020 20:34:10 +0100 Subject: [PATCH 6/6] Add missing translations --- assets/voxygen/i18n/en.ron | 2 ++ assets/voxygen/i18n/fr_FR.ron | 6 ++++-- voxygen/src/hud/settings_window.rs | 6 +++--- voxygen/src/hud/skillbar.rs | 4 +++- voxygen/src/menu/char_selection/ui.rs | 18 +++++++++++------- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index 005b1866bd..fcf50d5956 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -192,6 +192,8 @@ Enjoy your stay in the World of Veloren."#, "hud.settings.fluid_rendering_mode.cheap": "Cheap", "hud.settings.fluid_rendering_mode.shiny": "Shiny", "hud.settings.cloud_rendering_mode.regular": "Regular", + "hud.settings.fullscreen": "Fullscreen", + "hud.settings.save_window_size": "Save window size", "hud.settings.music_volume": "Music Volume", "hud.settings.sound_effect_volume": "Sound Effects Volume", diff --git a/assets/voxygen/i18n/fr_FR.ron b/assets/voxygen/i18n/fr_FR.ron index f2fa2acf06..d1cbbb75c6 100644 --- a/assets/voxygen/i18n/fr_FR.ron +++ b/assets/voxygen/i18n/fr_FR.ron @@ -166,13 +166,15 @@ Profitez de votre séjour dans le monde de Veloren."#, "hud.settings.view_distance": "Distance d'affichage", "hud.settings.maximum_fps": "Limite FPS", - "hud.settings.fov": "Champs de vision (FOV)", + "hud.settings.fov": "Champs de vision (degrés)", "hud.settings.antialiasing_mode": "Mode anticrénelage", "hud.settings.cloud_rendering_mode": "Rendu des nuages", "hud.settings.fluid_rendering_mode": "Rendu des fluides", "hud.settings.fluid_rendering_mode.cheap": "Rapide", "hud.settings.fluid_rendering_mode.shiny": "Qualité", "hud.settings.cloud_rendering_mode.regular": "Normal", + "hud.settings.fullscreen": "Plein écran", + "hud.settings.save_window_size": "Sauvegarder la taille de fenêtre", "hud.settings.music_volume": "Volume de la musique", "hud.settings.sound_effect_volume": "Volume des effets", @@ -262,7 +264,7 @@ Commandes du tchat: "hud.social": "Social", "hud.social.friends": "Amis", - "hud.social.Faction": "Faction", + "hud.social.faction": "Faction", "hud.social.online": "Jeu en ligne", "hud.social.not_yet_available": "Pas encore disponible", "hud.social.play_online_fmt": "{nb_player} joueurs en ligne", diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 9a67ed00d9..ac77d83da9 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -1518,7 +1518,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.max_fps_value, ui); // FOV - Text::new("Field of View (deg)") + Text::new(&self.localized_strings.get("hud.settings.fov")) .down_from(state.ids.max_fps_slider, 10.0) .font_size(14) .font_id(self.fonts.cyri) @@ -1665,7 +1665,7 @@ impl<'a> Widget for SettingsWindow<'a> { } // Fullscreen - Text::new("Fullscreen") + Text::new(&self.localized_strings.get("hud.settings.fullscreen")) .font_size(14) .font_id(self.fonts.cyri) .down_from(state.ids.fluid_mode_list, 8.0) @@ -1693,7 +1693,7 @@ impl<'a> Widget for SettingsWindow<'a> { .hover_image(self.imgs.settings_button_hover) .press_image(self.imgs.settings_button_press) .down_from(state.ids.fullscreen_label, 12.0) - .label("Save window size") + .label(&self.localized_strings.get("hud.settings.save_window_size")) .label_font_size(14) .label_color(TEXT_COLOR) .label_font_id(self.fonts.cyri) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 1f86ff48c8..b49d3ca359 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -256,7 +256,9 @@ impl<'a> Widget for Skillbar<'a> { Rectangle::fill_with([82.0 * 4.0, 40.0 * 4.0], color::TRANSPARENT) .mid_top_with_margin_on(ui.window, 300.0) .set(state.ids.level_align, ui); - let level_up_text = format!("Level {}", self.stats.level.level() as u32); + let level_up_text = &localized_strings + .get("char_selection.level_fmt") + .replace("{level_nb}", &self.stats.level.level().to_string()); Text::new(&level_up_text) .middle_of(state.ids.level_align) .font_size(30) diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 9fc2fe0adb..5d4e65a910 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -600,14 +600,18 @@ impl CharSelectionUi { .color(TEXT_COLOR) .set(self.ids.character_names[i], ui_widgets); - Text::new("Level 1") //TODO Insert real level here as soon as they get saved - .down_from(self.ids.character_names[i], 4.0) - .font_size(17) - .font_id(self.fonts.cyri) - .color(TEXT_COLOR) - .set(self.ids.character_levels[i], ui_widgets); + Text::new( + &localized_strings + .get("char_selection.level_fmt") + .replace("{level_nb}", "1"), + ) //TODO Insert real level here as soon as they get saved + .down_from(self.ids.character_names[i], 4.0) + .font_size(17) + .font_id(self.fonts.cyri) + .color(TEXT_COLOR) + .set(self.ids.character_levels[i], ui_widgets); - Text::new("Uncanny Valley") + Text::new(&localized_strings.get("char_selection.uncanny_valley")) .down_from(self.ids.character_levels[i], 4.0) .font_size(17) .font_id(self.fonts.cyri)