Merge branch 'optimize_and_fix_i18n' into 'master'

Optimize and fix i18n

Closes #436

See merge request veloren/veloren!743
This commit is contained in:
Joshua Yanovski 2020-01-27 22:10:26 +00:00
commit 56a553c968
11 changed files with 62 additions and 37 deletions

View File

@ -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.
@ -153,6 +154,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",
@ -190,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",

View File

@ -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)",
@ -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",
@ -190,7 +192,7 @@ Activer le mode plein écran
Avancer
Aller à gauche
Aller à droite
Aller en arriere
Reculer
Sauter
@ -198,7 +200,7 @@ Planer
Esquiver
Roullade
Roulade
Escalader
@ -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",
@ -271,12 +273,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 +287,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",

View File

@ -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)
@ -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)

View File

@ -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)

View File

@ -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) -> &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,
}
}

View File

@ -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::<VoxygenLocalization>(&i18n_asset_key(
let localized_strings = load::<VoxygenLocalization>(&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::<VoxygenLocalization>(&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

View File

@ -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;

View File

@ -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)
@ -1135,13 +1139,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)

View File

@ -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.

View File

@ -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,
});
};

View File

@ -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;