mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'juliancoffee/add_ability_i18n' into 'master'
Add i18n keys to abilities and smol fix Closes #1253 See merge request veloren/veloren!3446
This commit is contained in:
commit
10bbea89e2
35
assets/voxygen/i18n/en/hud/ability.ron
Normal file
35
assets/voxygen/i18n/en/hud/ability.ron
Normal file
@ -0,0 +1,35 @@
|
||||
/// WARNING: Localization files shall be saved in UTF-8 format without BOM
|
||||
|
||||
/// Localization for "global" English
|
||||
(
|
||||
string_map: {
|
||||
// Debug stick
|
||||
"common.abilities.debug.possess.name": "Possessing Arrow",
|
||||
"common.abilities.debug.possess.desc": "Shoots a poisonous arrow. Lets you control your target.",
|
||||
// Sword
|
||||
"common.abilities.sword.spin.name": "Whirlwind",
|
||||
"common.abilities.sword.spin.desc": "Move forward while spinning with your sword.",
|
||||
// Axe
|
||||
"common.abilities.axe.leap.name": "Axe Jump",
|
||||
"common.abilities.axe.leap.desc": "A jump with the slashing leap to position of cursor.",
|
||||
// Hammer
|
||||
"common.abilities.hammer.leap.name": "Smash of Doom",
|
||||
"common.abilities.hammer.leap.desc": "An AOE attack with knockback. Leaps to position of cursor.",
|
||||
// Bow
|
||||
"common.abilities.bow.shotgun.name": "Burst",
|
||||
"common.abilities.bow.shotgun.desc": "Launches a burst of arrows",
|
||||
// Staff
|
||||
"common.abilities.staff.fireshockwave.name": "Ring of Fire",
|
||||
"common.abilities.staff.fireshockwave.desc": "Ignites the ground with fiery shockwave.",
|
||||
// Sceptre
|
||||
"common.abilities.sceptre.wardingaura.name": "Warding Aura",
|
||||
"common.abilities.sceptre.wardingaura.desc": "Wards your allies against enemy attacks.",
|
||||
// Unknown
|
||||
"common.abilities.unknown.name": "Ability has no title",
|
||||
"common.abilities.unknown.desc": "Ability has no description",
|
||||
},
|
||||
|
||||
|
||||
vector_map: {
|
||||
}
|
||||
)
|
35
assets/voxygen/i18n/uk_UA/hud/ability.ron
Normal file
35
assets/voxygen/i18n/uk_UA/hud/ability.ron
Normal file
@ -0,0 +1,35 @@
|
||||
/// WARNING: Localization files shall be saved in UTF-8 format without BOM
|
||||
|
||||
/// Localization for Ukrainian language
|
||||
(
|
||||
string_map: {
|
||||
// Debug stick
|
||||
"common.abilities.debug.possess.name": "Заклинаюча Стріла",
|
||||
"common.abilities.debug.possess.desc": "Стріляє отруйною стрілою. Дає тобі контроль над ціллю.",
|
||||
// Sword
|
||||
"common.abilities.sword.spin.name": "Буревій",
|
||||
"common.abilities.sword.spin.desc": "Рушай вперед кружляючи з мечем.",
|
||||
// Axe
|
||||
"common.abilities.axe.leap.name": "Стрибок Сокири",
|
||||
"common.abilities.axe.leap.desc": "Стрибок з рубаним ударом, слідує за курсором.",
|
||||
// Hammer
|
||||
"common.abilities.hammer.leap.name": "Погром",
|
||||
"common.abilities.hammer.leap.desc": "Атака по області. Стрибок спрямований за курсором.",
|
||||
// Bow
|
||||
"common.abilities.bow.shotgun.name": "Стріловик",
|
||||
"common.abilities.bow.shotgun.desc": "Постріл купою стріл за раз.",
|
||||
// Staff
|
||||
"common.abilities.staff.fireshockwave.name": "Кільце Вогню",
|
||||
"common.abilities.staff.fireshockwave.desc": "Підпалює землю вогненною ударною хвилєю.",
|
||||
// Sceptre
|
||||
"common.abilities.sceptre.wardingaura.name": "Захисна Аура",
|
||||
"common.abilities.sceptre.wardingaura.desc": "Укріплює тебе і твоїх спільників силами природи на деякий час.",
|
||||
// Unknown
|
||||
"common.abilities.unknown.name": "Неназвана Здатність",
|
||||
"common.abilities.unknown.desc": "Здатність без опису",
|
||||
},
|
||||
|
||||
|
||||
vector_map: {
|
||||
}
|
||||
)
|
@ -80,17 +80,12 @@ struct Language {
|
||||
|
||||
impl Language {
|
||||
/// Get a localized text from the given key
|
||||
pub fn get<'a>(&'a self, key: &'a str) -> Option<&str> {
|
||||
self.string_map.get(key).map(String::as_str)
|
||||
}
|
||||
pub fn get(&self, key: &str) -> Option<&str> { self.string_map.get(key).map(String::as_str) }
|
||||
|
||||
/// Get a variation of localized text from the given key
|
||||
///
|
||||
/// `index` should be a random number from `0` to `u16::max()`
|
||||
///
|
||||
/// If the key is not present in the localization object
|
||||
/// then the key is returned.
|
||||
pub fn get_variation<'a>(&'a self, key: &'a str, index: u16) -> Option<&str> {
|
||||
pub fn get_variation(&self, key: &str, index: u16) -> Option<&str> {
|
||||
self.vector_map.get(key).and_then(|v| {
|
||||
if v.is_empty() {
|
||||
None
|
||||
@ -163,19 +158,30 @@ pub struct LocalizationGuard {
|
||||
pub type Localization = LocalizationGuard;
|
||||
|
||||
impl LocalizationGuard {
|
||||
/// Get a localized text from the given key
|
||||
///
|
||||
/// First lookup is done in the active language, second in
|
||||
/// the fallback (if present).
|
||||
pub fn get_opt<'a>(&'a self, key: &str) -> Option<&'a str> {
|
||||
self.active
|
||||
.get(key)
|
||||
.or_else(|| self.fallback.as_ref().and_then(|f| f.get(key)))
|
||||
}
|
||||
|
||||
/// Get a localized text from the given key
|
||||
///
|
||||
/// First lookup is done in the active language, second in
|
||||
/// the fallback (if present).
|
||||
/// If the key is not present in the localization object
|
||||
/// then the key is returned.
|
||||
pub fn get<'a>(&'a self, key: &'a str) -> &str {
|
||||
self.active.get(key).unwrap_or_else(|| {
|
||||
self.fallback
|
||||
.as_ref()
|
||||
.and_then(|f| f.get(key))
|
||||
.unwrap_or(key)
|
||||
})
|
||||
pub fn get<'a>(&'a self, key: &'a str) -> &str { self.get_opt(key).unwrap_or(key) }
|
||||
|
||||
/// Get a localized text from the given key
|
||||
///
|
||||
/// First lookup is done in the active language, second in
|
||||
/// the fallback (if present).
|
||||
pub fn get_or(&self, key: &str, fallback_key: &str) -> Option<&str> {
|
||||
self.get_opt(key).or_else(|| self.get_opt(fallback_key))
|
||||
}
|
||||
|
||||
/// Get a variation of localized text from the given key
|
||||
|
@ -425,9 +425,7 @@ impl<'a> Buttons<'a> {
|
||||
text: widget::Id,
|
||||
) {
|
||||
let key_layout = &self.global_state.window.key_layout;
|
||||
let key_desc = key_mouse
|
||||
.display_shortened(key_layout)
|
||||
.unwrap_or_else(|| key_mouse.display_string(key_layout));
|
||||
let key_desc = key_mouse.display_shortest(key_layout);
|
||||
|
||||
//Create shadow
|
||||
Text::new(&key_desc)
|
||||
|
@ -835,7 +835,7 @@ impl<'a> Widget for Diary<'a> {
|
||||
)
|
||||
.ability_id(Some(self.inventory));
|
||||
let (ability_title, ability_desc) = if let Some(ability_id) = ability_id {
|
||||
util::ability_description(ability_id)
|
||||
util::ability_description(ability_id, self.localized_strings)
|
||||
} else {
|
||||
(Cow::Borrowed("Drag an ability here to use it."), "")
|
||||
};
|
||||
@ -878,7 +878,7 @@ impl<'a> Widget for Diary<'a> {
|
||||
]
|
||||
.get(i)
|
||||
.and_then(|input| keys.get_binding(*input))
|
||||
.map(|key| key.display_string(key_layout))
|
||||
.map(|key| key.display_shortest(key_layout))
|
||||
.unwrap_or_default();
|
||||
|
||||
Text::new(&ability_key)
|
||||
@ -1033,7 +1033,7 @@ impl<'a> Widget for Diary<'a> {
|
||||
.enumerate()
|
||||
{
|
||||
let (ability_title, ability_desc) =
|
||||
util::ability_description(ability_id.unwrap_or(""));
|
||||
util::ability_description(ability_id.unwrap_or(""), self.localized_strings);
|
||||
|
||||
let (align_state, image_offsets) = if id_index < 6 {
|
||||
(state.ids.sb_page_left_align, 120.0 * id_index as f64)
|
||||
|
@ -1425,17 +1425,13 @@ impl<'a> Widget for Map<'a> {
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.zoom_txt, ui);
|
||||
|
||||
Text::new(
|
||||
&location_marker_binding
|
||||
.display_shortened(key_layout)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.right_from(state.ids.zoom_txt, 15.0)
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.graphics_for(state.ids.map_layers[0])
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.waypoint_binding_txt, ui);
|
||||
Text::new(&location_marker_binding.display_shortest(key_layout))
|
||||
.right_from(state.ids.zoom_txt, 15.0)
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.graphics_for(state.ids.map_layers[0])
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.waypoint_binding_txt, ui);
|
||||
|
||||
Text::new(i18n.get("hud.map.mid_click"))
|
||||
.right_from(state.ids.waypoint_binding_txt, 5.0)
|
||||
|
@ -134,7 +134,7 @@ impl<'a> Widget for Controls<'a> {
|
||||
format!(
|
||||
"{} {}",
|
||||
key.display_string(key_layout),
|
||||
key.display_shortened(key_layout)
|
||||
key.try_shortened(key_layout)
|
||||
.map_or("".to_owned(), |short| format!("({})", short))
|
||||
),
|
||||
if controls.has_conflicting_bindings(key) {
|
||||
|
@ -612,7 +612,7 @@ impl<'a> Skillbar<'a> {
|
||||
.get(i)
|
||||
.and_then(|a| Ability::from(*a).ability_id(Some(inventory)))
|
||||
})
|
||||
.map(util::ability_description),
|
||||
.map(|id| util::ability_description(id, self.localized_strings)),
|
||||
})
|
||||
};
|
||||
|
||||
@ -655,9 +655,7 @@ impl<'a> Skillbar<'a> {
|
||||
let position_bg = entry.shortcut_position_bg;
|
||||
let (id, id_bg) = entry.shortcut_widget_ids;
|
||||
|
||||
let key_desc = key
|
||||
.display_shortened(key_layout)
|
||||
.unwrap_or_else(|| key.display_string(key_layout));
|
||||
let key_desc = key.display_shortest(key_layout);
|
||||
// shortcut text
|
||||
Text::new(&key_desc)
|
||||
.position(position)
|
||||
|
@ -356,48 +356,20 @@ pub fn ability_image(imgs: &img_ids::Imgs, ability_id: &str) -> image::Id {
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub fn ability_description(ability_id: &str) -> (Cow<str>, &str) {
|
||||
let (name, desc) = match ability_id {
|
||||
// Debug stick
|
||||
"common.abilities.debug.possess" => (
|
||||
"Possessing Arrow",
|
||||
"Shoots a poisonous arrow. Lets you control your target.",
|
||||
pub fn ability_description<'a>(
|
||||
ability_id: &'a str,
|
||||
loc: &'a i18n::Localization,
|
||||
) -> (Cow<'a, str>, &'a str) {
|
||||
let (name, desc) = (
|
||||
format!("{}.name", ability_id),
|
||||
format!("{}.desc", ability_id),
|
||||
);
|
||||
(
|
||||
Cow::Borrowed(
|
||||
loc.get_or(&name, "common.abilities.unknown.name")
|
||||
.unwrap_or(ability_id),
|
||||
),
|
||||
// Sword
|
||||
"common.abilities.sword.spin" => (
|
||||
"Whirlwind",
|
||||
"Move forward while spinning with your sword.",
|
||||
),
|
||||
// Axe
|
||||
"common.abilities.axe.leap" => (
|
||||
"Axe Jump",
|
||||
"A jump with the slashing leap to position of cursor.",
|
||||
),
|
||||
// Hammer
|
||||
"common.abilities.hammer.leap" => (
|
||||
"Smash of Doom",
|
||||
"An AOE attack with knockback. Leaps to position of cursor.",
|
||||
),
|
||||
// Bow
|
||||
"common.abilities.bow.shotgun" => (
|
||||
"Burst",
|
||||
"Launches a burst of arrows",
|
||||
),
|
||||
// Staff
|
||||
"common.abilities.staff.fireshockwave" => (
|
||||
"Ring of Fire",
|
||||
"Ignites the ground with fiery shockwave.",
|
||||
),
|
||||
// Sceptre
|
||||
"common.abilities.sceptre.wardingaura" => (
|
||||
"Thorn Bulwark",
|
||||
"Protects you and your group with thorns for a short amount of time.",
|
||||
),
|
||||
_ => (
|
||||
"Ability has no title",
|
||||
"Ability has no description."
|
||||
),
|
||||
};
|
||||
(Cow::Borrowed(name), desc)
|
||||
loc.get_or(&desc, "common.abilities.unknown.desc")
|
||||
.unwrap_or(ability_id),
|
||||
)
|
||||
}
|
||||
|
@ -344,10 +344,9 @@ impl KeyMouse {
|
||||
key_string.to_owned()
|
||||
}
|
||||
|
||||
/// Returns shortened key name (e.g. Left Click -> LMB)
|
||||
///
|
||||
/// Use it in case if space does really matter.
|
||||
pub fn display_shortened(&self, _key_layout: &Option<KeyLayout>) -> Option<String> {
|
||||
/// If it exists, returns the shortened version of a key name
|
||||
/// (e.g. Left Click -> M1)
|
||||
pub fn try_shortened(&self, _key_layout: &Option<KeyLayout>) -> Option<String> {
|
||||
use self::KeyMouse::*;
|
||||
use winit::event::{MouseButton, VirtualKeyCode::*};
|
||||
let key_string = match self {
|
||||
@ -366,6 +365,15 @@ impl KeyMouse {
|
||||
|
||||
Some(key_string.to_owned())
|
||||
}
|
||||
|
||||
/// Returns shortest name of key (e.g. Left Click - M1)
|
||||
/// If key doesn't have shorter version, use regular one.
|
||||
///
|
||||
/// Use it in case if space does really matter.
|
||||
pub fn display_shortest(&self, key_layout: &Option<KeyLayout>) -> String {
|
||||
self.try_shortened(key_layout)
|
||||
.unwrap_or_else(|| self.display_string(key_layout))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
|
Loading…
Reference in New Issue
Block a user