Crates.io | bevy-translation-table |
lib.rs | bevy-translation-table |
version | 0.1.0 |
source | src |
created_at | 2024-07-12 12:29:12.694113 |
updated_at | 2024-07-12 12:29:12.694113 |
description | A super basic translation table system for bevy supporting generic data, CSV, and ODS |
homepage | https://github.com/QueenOfSquiggles/bevy-translation-table |
repository | https://github.com/QueenOfSquiggles/bevy-translation-table |
max_upload_size | |
id | 1300627 |
size | 96,611 |
This crate allows simple translation to be done within Bevy Engine using a global Resource
(Translations
). Support for different file formats is entirely optional allowing stripping unneeded implementations and dependencies.
The goal of this plugin was to allow loading string translation data from table style files such as CSV and Open Document Spreadsheet (ODS) files. Additionally supporting injection of raw key-value data for more customization if needed.
The features of this crate are to be:
Code from examples/minimal.rs
Initialize Resource
// Here you can replace 'world' with 'app' if using bevy instead of just bevy-ecs
world.insert_resource(
// initialize as default
Translations::default()
// select a CSV file and a default locale
.csv_file(&Path::new("assets/lang.csv"), &"en".into())
// optionally switch the current locale
.use_locale("es")
// Strips mutability to easily finish inserting into the world.
.build(),
);
Poll Translated String(s)
// A system that uses a read-only reference to the translations table.
// This allows better parallelization of translation lookups when not needing to change the tables
fn system_use_translation(trans: Res<Translations>) {
for key in ["hello", "green", "invalid"] {
// using Res<Translations>.tr('key') to perform the key-value lookup.
// Without the feature `catch-missing-values` enabled, this will simply provide the key again when failing to find a matching value for the current locale.
println!("{} = {}", key, trans.tr(key))
}
}
Following the precedent set by bevy itself, this crate is dual licensed under either MIT or Apache-2.0