Rename ItemL10n to ItemI18n

This commit is contained in:
juliancoffee 2024-01-16 18:40:12 +02:00
parent db569513f3
commit d3fcade857
10 changed files with 78 additions and 74 deletions

View File

@ -489,7 +489,7 @@ type I18nId = String;
// TODO: probably make a Resource if used outside of voxygen
// TODO: add hot-reloading similar to how ItemImgs does it?
// TODO: make it work with plugins (via Concatenate?)
/// To be used with ItemDesc::l10n
/// To be used with ItemDesc::i18n
///
/// NOTE: there is a limitation to this manifest, as it uses ItemKey and
/// ItemKey isn't uniquely identifies Item, when it comes to modular items.
@ -501,19 +501,23 @@ type I18nId = String;
/// Translations currently do the same, but *maybe* they shouldn't in which case
/// we should either extend ItemKey or use new identifier. We could use
/// ItemDefinitionId, but it's very generic and cumbersome.
pub struct ItemL10n {
pub struct ItemI18n {
/// maps ItemKey to i18n identifier
map: HashMap<ItemKey, I18nId>,
}
impl assets::Asset for ItemL10n {
impl assets::Asset for ItemI18n {
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
impl ItemL10n {
pub fn new_expect() -> Self { ItemL10n::load_expect("common.item_l10n").read().clone() }
impl ItemI18n {
pub fn new_expect() -> Self {
ItemI18n::load_expect("common.item_i18n_manifest")
.read()
.clone()
}
/// Returns (name, description) in Content form.
// TODO: after we remove legacy text from ItemDef, consider making this
@ -1482,11 +1486,11 @@ pub trait ItemDesc {
}
/// Return name's and description's localization descriptors
fn l10n(&self, l10n: &ItemL10n) -> (Content, Content) {
fn i18n(&self, i18n: &ItemI18n) -> (Content, Content) {
let item_key: ItemKey = self.into();
#[allow(deprecated)]
l10n.item_text_opt(item_key).unwrap_or_else(|| {
i18n.item_text_opt(item_key).unwrap_or_else(|| {
(
Content::Plain(self.name().to_string()),
Content::Plain(self.description().to_string()),
@ -1743,7 +1747,7 @@ mod tests {
}
#[test]
fn test_item_l10n() { let _ = ItemL10n::new_expect(); }
fn test_item_i18n() { let _ = ItemI18n::new_expect(); }
#[test]
// Probably can't fail, but better safe than crashing production server
@ -1753,7 +1757,7 @@ mod tests {
// All items in Veloren should have localization.
// If no, add some common dummy i18n id.
fn ensure_item_localization() {
let manifest = ItemL10n::new_expect();
let manifest = ItemI18n::new_expect();
let items = all_items_expect();
for item in items {
let item_key: ItemKey = (&item).into();

View File

@ -21,7 +21,7 @@ use common::{
combat::{combat_rating, perception_dist_multiplier_from_stealth, Damage},
comp::{
inventory::InventorySortOrder,
item::{ItemDef, ItemDesc, ItemL10n, MaterialStatManifest, Quality},
item::{ItemDef, ItemDesc, ItemI18n, MaterialStatManifest, Quality},
Body, Energy, Health, Inventory, Poise, SkillSet, Stats,
},
};
@ -81,7 +81,7 @@ pub struct InventoryScroller<'a> {
slot_manager: &'a mut SlotManager,
pulse: f32,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
show_stats: bool,
show_bag_inv: bool,
on_right: bool,
@ -106,7 +106,7 @@ impl<'a> InventoryScroller<'a> {
slot_manager: &'a mut SlotManager,
pulse: f32,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
show_stats: bool,
show_bag_inv: bool,
on_right: bool,
@ -129,7 +129,7 @@ impl<'a> InventoryScroller<'a> {
slot_manager,
pulse,
localized_strings,
item_l10n,
item_i18n,
show_stats,
show_bag_inv,
on_right,
@ -374,7 +374,7 @@ impl<'a> InventoryScroller<'a> {
{
// TODO: we do double the work here, optimize?
let (name, _) =
util::item_text(i, self.localized_strings, self.item_l10n);
util::item_text(i, self.localized_strings, self.item_i18n);
name
},
i.amount(),
@ -470,7 +470,7 @@ impl<'a> InventoryScroller<'a> {
.set(state.ids.inv_slots[i], ui);
}
if self.details_mode {
let (name, _) = util::item_text(item, self.localized_strings, self.item_l10n);
let (name, _) = util::item_text(item, self.localized_strings, self.item_i18n);
Text::new(&name)
.top_left_with_margins_on(
state.ids.inv_alignment,
@ -652,7 +652,7 @@ pub struct Bag<'a> {
slot_manager: &'a mut SlotManager,
pulse: f32,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
stats: &'a Stats,
skill_set: &'a SkillSet,
health: &'a Health,
@ -678,7 +678,7 @@ impl<'a> Bag<'a> {
slot_manager: &'a mut SlotManager,
pulse: f32,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
stats: &'a Stats,
skill_set: &'a SkillSet,
health: &'a Health,
@ -702,7 +702,7 @@ impl<'a> Bag<'a> {
slot_manager,
pulse,
localized_strings,
item_l10n,
item_i18n,
stats,
skill_set,
energy,
@ -822,7 +822,7 @@ impl<'a> Widget for Bag<'a> {
self.pulse,
self.msm,
self.localized_strings,
self.item_l10n,
self.item_i18n,
)
.title_font_size(self.fonts.cyri.scale(20))
.parent(ui.window)
@ -839,7 +839,7 @@ impl<'a> Widget for Bag<'a> {
self.slot_manager,
self.pulse,
self.localized_strings,
self.item_l10n,
self.item_i18n,
self.show.stats,
self.show.bag_inv,
true,

View File

@ -19,7 +19,7 @@ use common::{
item_key::ItemKey,
modular::{self, ModularComponent},
tool::{AbilityMap, ToolKind},
Item, ItemBase, ItemDef, ItemDesc, ItemKind, ItemL10n, ItemTag, MaterialStatManifest,
Item, ItemBase, ItemDef, ItemDesc, ItemI18n, ItemKind, ItemTag, MaterialStatManifest,
Quality, TagExampleInfo,
},
slot::{InvSlotId, Slot},
@ -151,7 +151,7 @@ pub struct Crafting<'a> {
imgs: &'a Imgs,
fonts: &'a Fonts,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
pulse: f32,
rot_imgs: &'a ImgsRot,
item_tooltip_manager: &'a mut ItemTooltipManager,
@ -172,7 +172,7 @@ impl<'a> Crafting<'a> {
imgs: &'a Imgs,
fonts: &'a Fonts,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
pulse: f32,
rot_imgs: &'a ImgsRot,
item_tooltip_manager: &'a mut ItemTooltipManager,
@ -189,7 +189,7 @@ impl<'a> Crafting<'a> {
imgs,
fonts,
localized_strings,
item_l10n,
item_i18n,
pulse,
rot_imgs,
item_tooltip_manager,
@ -358,7 +358,7 @@ impl<'a> Widget for Crafting<'a> {
self.pulse,
self.msm,
self.localized_strings,
self.item_l10n,
self.item_i18n,
)
.title_font_size(self.fonts.cyri.scale(20))
.parent(ui.window)
@ -745,7 +745,7 @@ impl<'a> Widget for Crafting<'a> {
(title, _) = util::item_text(
recipe.output.0.as_ref(),
self.localized_strings,
self.item_l10n,
self.item_i18n,
);
&title
};
@ -874,7 +874,7 @@ impl<'a> Widget for Crafting<'a> {
(title, _) = util::item_text(
recipe.output.0.as_ref(),
self.localized_strings,
self.item_l10n,
self.item_i18n,
);
&title
};
@ -1239,7 +1239,7 @@ impl<'a> Widget for Crafting<'a> {
if let Some(output_item) = output_item {
let (name, _) =
util::item_text(&output_item, self.localized_strings, self.item_l10n);
util::item_text(&output_item, self.localized_strings, self.item_i18n);
Button::image(animate_by_pulse(
&self
.item_imgs
@ -1994,7 +1994,7 @@ impl<'a> Widget for Crafting<'a> {
let (name, _) = util::item_text(
item_def.as_ref(),
self.localized_strings,
self.item_l10n,
self.item_i18n,
);
Text::new(&name)
.right_from(state.ids.ingredient_frame[i], 10.0)
@ -2009,7 +2009,7 @@ impl<'a> Widget for Crafting<'a> {
let (name, _) = util::item_text(
item_def.as_ref(),
self.localized_strings,
self.item_l10n,
self.item_i18n,
);
name
@ -2028,7 +2028,7 @@ impl<'a> Widget for Crafting<'a> {
let (name, _) = util::item_text(
def.as_ref(),
self.localized_strings,
self.item_l10n,
self.item_i18n,
);
name

View File

@ -6,7 +6,7 @@ use super::{
};
use crate::ui::{fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable};
use client::Client;
use common::comp::inventory::item::{Item, ItemDesc, ItemL10n, MaterialStatManifest, Quality};
use common::comp::inventory::item::{Item, ItemDesc, ItemI18n, MaterialStatManifest, Quality};
use conrod_core::{
color,
position::Dimension,
@ -58,7 +58,7 @@ pub struct LootScroller<'a> {
rot_imgs: &'a ImgsRot,
fonts: &'a Fonts,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
msm: &'a MaterialStatManifest,
item_tooltip_manager: &'a mut ItemTooltipManager,
pulse: f32,
@ -77,7 +77,7 @@ impl<'a> LootScroller<'a> {
rot_imgs: &'a ImgsRot,
fonts: &'a Fonts,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
msm: &'a MaterialStatManifest,
item_tooltip_manager: &'a mut ItemTooltipManager,
pulse: f32,
@ -92,7 +92,7 @@ impl<'a> LootScroller<'a> {
rot_imgs,
fonts,
localized_strings,
item_l10n,
item_i18n,
msm,
item_tooltip_manager,
pulse,
@ -156,7 +156,7 @@ impl<'a> Widget for LootScroller<'a> {
self.pulse,
self.msm,
self.localized_strings,
self.item_l10n,
self.item_i18n,
)
.title_font_size(self.fonts.cyri.scale(20))
.parent(ui.window)
@ -357,7 +357,7 @@ impl<'a> Widget for LootScroller<'a> {
"amount" => amount,
"item" => {
let (name, _) =
util::item_text(&item, self.localized_strings, self.item_l10n);
util::item_text(&item, self.localized_strings, self.item_i18n);
name
},
},

View File

@ -98,7 +98,7 @@ use common::{
},
item::{
tool::{AbilityContext, ToolKind},
ItemDefinitionIdOwned, ItemDesc, ItemL10n, MaterialStatManifest, Quality,
ItemDefinitionIdOwned, ItemDesc, ItemI18n, MaterialStatManifest, Quality,
},
loot_owner::LootOwnerKind,
pet::is_mountable,
@ -1286,7 +1286,7 @@ pub struct Hud {
world_map: (/* Id */ Vec<Rotations>, Vec2<u32>),
imgs: Imgs,
item_imgs: ItemImgs,
item_l10n: ItemL10n,
item_i18n: ItemI18n,
fonts: Fonts,
rot_imgs: ImgsRot,
failed_block_pickups: HashMap<VolumePos, CollectFailedData>,
@ -1343,7 +1343,7 @@ impl Hud {
// Load item images.
let item_imgs = ItemImgs::new(&mut ui, imgs.not_found);
// Load item text ("reference" to name and description)
let item_l10n = ItemL10n::new_expect();
let item_i18n = ItemI18n::new_expect();
// Load fonts.
let fonts = Fonts::load(global_state.i18n.read().fonts(), &mut ui)
.expect("Impossible to load fonts!");
@ -1383,7 +1383,7 @@ impl Hud {
world_map,
rot_imgs,
item_imgs,
item_l10n,
item_i18n,
fonts,
ids,
failed_block_pickups: HashMap::default(),
@ -2012,7 +2012,7 @@ impl Hud {
// Item
overitem::Overitem::new(
util::describe(item, i18n, &self.item_l10n).into(),
util::describe(item, i18n, &self.item_i18n).into(),
quality,
distance,
fonts,
@ -2096,13 +2096,13 @@ impl Hud {
},
BlockInteraction::Unlock(kind) => {
let item_name = |item_id: &ItemDefinitionIdOwned| {
// TODO: get ItemKey and use it with l10n?
// TODO: get ItemKey and use it with i18n?
item_id
.as_ref()
.itemdef_id()
.map(|id| {
let item = Item::new_from_asset_expect(id);
util::describe(&item, i18n, &self.item_l10n)
util::describe(&item, i18n, &self.item_i18n)
})
.unwrap_or_else(|| "modular item".to_string())
};
@ -3178,7 +3178,7 @@ impl Hud {
item_tooltip_manager,
&mut self.slot_manager,
i18n,
&self.item_l10n,
&self.item_i18n,
&msm,
self.floaters.combo_floater,
&context,
@ -3226,7 +3226,7 @@ impl Hud {
&mut self.slot_manager,
self.pulse,
i18n,
&self.item_l10n,
&self.item_i18n,
player_stats,
skill_set,
health,
@ -3271,7 +3271,7 @@ impl Hud {
item_tooltip_manager,
&mut self.slot_manager,
i18n,
&self.item_l10n,
&self.item_i18n,
&msm,
self.pulse,
&mut self.show,
@ -3352,7 +3352,7 @@ impl Hud {
&self.imgs,
&self.fonts,
i18n,
&self.item_l10n,
&self.item_i18n,
self.pulse,
&self.rot_imgs,
item_tooltip_manager,
@ -3519,7 +3519,7 @@ impl Hud {
&self.rot_imgs,
&self.fonts,
i18n,
&self.item_l10n,
&self.item_i18n,
&msm,
item_tooltip_manager,
self.pulse,

View File

@ -26,7 +26,7 @@ use common::comp::{
ability::{AbilityInput, Stance},
item::{
tool::{AbilityContext, ToolKind},
ItemDesc, ItemL10n, MaterialStatManifest,
ItemDesc, ItemI18n, MaterialStatManifest,
},
skillset::SkillGroupKind,
Ability, ActiveAbilities, Body, CharacterState, Combo, Energy, Health, Inventory, Poise,
@ -307,7 +307,7 @@ pub struct Skillbar<'a> {
item_tooltip_manager: &'a mut ItemTooltipManager,
slot_manager: &'a mut slots::SlotManager,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
pulse: f32,
#[conrod(common_builder)]
common: widget::CommonBuilder,
@ -344,7 +344,7 @@ impl<'a> Skillbar<'a> {
item_tooltip_manager: &'a mut ItemTooltipManager,
slot_manager: &'a mut slots::SlotManager,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
msm: &'a MaterialStatManifest,
combo_floater: Option<ComboFloater>,
context: &'a AbilityContext,
@ -376,7 +376,7 @@ impl<'a> Skillbar<'a> {
item_tooltip_manager,
slot_manager,
localized_strings,
item_l10n,
item_i18n,
msm,
combo_floater,
context,
@ -1010,7 +1010,7 @@ impl<'a> Skillbar<'a> {
self.pulse,
self.msm,
self.localized_strings,
self.item_l10n,
self.item_i18n,
)
.title_font_size(self.fonts.cyri.scale(20))
.parent(ui.window)
@ -1033,7 +1033,7 @@ impl<'a> Skillbar<'a> {
hotbar.get(slot).and_then(|content| match content {
hotbar::SlotContents::Inventory(i, _) => inventory.get_by_hash(i).map(|item| {
let (title, desc) =
util::item_text(item, self.localized_strings, self.item_l10n);
util::item_text(item, self.localized_strings, self.item_i18n);
(title.into(), desc.into())
}),

View File

@ -10,7 +10,7 @@ use vek::*;
use client::Client;
use common::{
comp::{
inventory::item::{ItemDesc, ItemL10n, MaterialStatManifest, Quality},
inventory::item::{ItemDesc, ItemI18n, MaterialStatManifest, Quality},
Inventory, Stats,
},
trade::{PendingTrade, SitePrices, TradeAction, TradePhase},
@ -99,7 +99,7 @@ pub struct Trade<'a> {
common: widget::CommonBuilder,
slot_manager: &'a mut SlotManager,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
msm: &'a MaterialStatManifest,
pulse: f32,
show: &'a mut Show,
@ -118,7 +118,7 @@ impl<'a> Trade<'a> {
item_tooltip_manager: &'a mut ItemTooltipManager,
slot_manager: &'a mut SlotManager,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
msm: &'a MaterialStatManifest,
pulse: f32,
show: &'a mut Show,
@ -135,7 +135,7 @@ impl<'a> Trade<'a> {
common: widget::CommonBuilder::default(),
slot_manager,
localized_strings,
item_l10n,
item_i18n,
msm,
pulse,
show,
@ -349,7 +349,7 @@ impl<'a> Trade<'a> {
self.pulse,
self.msm,
self.localized_strings,
self.item_l10n,
self.item_i18n,
)
.title_font_size(self.fonts.cyri.scale(20))
.parent(ui.window)
@ -367,7 +367,7 @@ impl<'a> Trade<'a> {
self.slot_manager,
self.pulse,
self.localized_strings,
self.item_l10n,
self.item_i18n,
false,
true,
false,
@ -537,7 +537,7 @@ impl<'a> Trade<'a> {
.invslot
.and_then(|i| inventory.get(i))
.map(|i| {
let (name, _) = util::item_text(&i, self.localized_strings, self.item_l10n);
let (name, _) = util::item_text(&i, self.localized_strings, self.item_i18n);
Cow::Owned(name)
})

View File

@ -5,7 +5,7 @@ use common::{
item::{
armor::{Armor, ArmorKind, Protection},
tool::{Hands, Tool, ToolKind},
Effects, Item, ItemDefinitionId, ItemDesc, ItemKind, ItemL10n, MaterialKind,
Effects, Item, ItemDefinitionId, ItemDesc, ItemI18n, ItemKind, MaterialKind,
MaterialStatManifest,
},
BuffKind,
@ -64,9 +64,9 @@ pub fn price_desc<'a>(
pub fn item_text<'a, I: ItemDesc + ?Sized>(
item: &I,
i18n: &'a Localization,
l10n_spec: &'a ItemL10n,
i18n_spec: &'a ItemI18n,
) -> (String, String) {
let (title, desc) = item.l10n(l10n_spec);
let (title, desc) = item.i18n(i18n_spec);
(i18n.get_content(&title), i18n.get_content(&desc))
}
@ -74,9 +74,9 @@ pub fn item_text<'a, I: ItemDesc + ?Sized>(
pub fn describe<'a, I: ItemDesc + ?Sized>(
item: &I,
i18n: &'a Localization,
l10n_spec: &'a ItemL10n,
i18n_spec: &'a ItemI18n,
) -> String {
let (title, _) = item_text(item, i18n, l10n_spec);
let (title, _) = item_text(item, i18n, i18n_spec);
let amount = item.amount();
if amount.get() > 1 {

View File

@ -10,7 +10,7 @@ use common::{
comp::{
item::{
armor::Protection, item_key::ItemKey, modular::ModularComponent, Item, ItemDesc,
ItemKind, ItemL10n, ItemTag, MaterialStatManifest, Quality,
ItemI18n, ItemKind, ItemTag, MaterialStatManifest, Quality,
},
Energy,
},
@ -296,7 +296,7 @@ pub struct ItemTooltip<'a> {
item_imgs: &'a ItemImgs,
pulse: f32,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
}
#[derive(Clone, Debug, Default, PartialEq, WidgetStyle)]
@ -361,7 +361,7 @@ impl<'a> ItemTooltip<'a> {
pulse: f32,
msm: &'a MaterialStatManifest,
localized_strings: &'a Localization,
item_l10n: &'a ItemL10n,
item_i18n: &'a ItemI18n,
) -> Self {
ItemTooltip {
common: widget::CommonBuilder::default(),
@ -379,7 +379,7 @@ impl<'a> ItemTooltip<'a> {
item_imgs,
pulse,
localized_strings,
item_l10n,
item_i18n,
}
}
@ -453,7 +453,7 @@ impl<'a> Widget for ItemTooltip<'a> {
} = args;
let i18n = &self.localized_strings;
let item_l10n = &self.item_l10n;
let item_i18n = &self.item_i18n;
let inventories = self.client.inventories();
let inventory = match inventories.get(self.info.viewpoint_entity) {
@ -469,7 +469,7 @@ impl<'a> Widget for ItemTooltip<'a> {
let equipped_item = inventory.equipped_items_replaceable_by(item_kind).next();
let (title, desc) = util::item_text(item, i18n, item_l10n);
let (title, desc) = util::item_text(item, i18n, item_i18n);
let item_kind = util::kind_text(item_kind, i18n).to_string();
@ -1271,7 +1271,7 @@ impl<'a> Widget for ItemTooltip<'a> {
let item = &self.item;
// TODO: we do double work here, does it need optimization?
let (_, desc) = util::item_text(item, self.localized_strings, self.item_l10n);
let (_, desc) = util::item_text(item, self.localized_strings, self.item_i18n);
let (text_w, _image_w) = self.text_image_width(260.0);