9 releases (4 breaking)

0.5.0 Mar 1, 2024
0.4.0 Dec 5, 2023
0.3.0 Jul 23, 2023
0.2.1 Jun 26, 2023
0.1.3 Dec 26, 2022

#211 in Game dev

Download history 3/week @ 2024-02-14 16/week @ 2024-02-21 138/week @ 2024-02-28 12/week @ 2024-03-06 6/week @ 2024-03-13 47/week @ 2024-03-27 57/week @ 2024-04-03

104 downloads per month

MIT/Apache

44KB
179 lines

bevy_easy_localize

Crates.io

A simple crate to localize your game using .csv files.

Features

  • Loading from .csv files
  • Loading the translation file from the asset folder
  • Automatically updating text components
  • Hot reloading
  • Lightweight

Upcoming features

  • Per-language fonts
  • More flexible and customizable .csv file loading

How to use

The .csv file currently must be arranged in this order:

Keyword Comments Language_0 Language_1 ...
word comment translation0 translation1 ...

image

In your project:

use bevy::prelude::*;
use bevy_easy_localize::Localize;
pub fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(bevy_easy_localize::LocalizePlugin)
        //Insert the resource from an asset path
        .insert_resource(Localize::from_asset_path("translations.csv"))
        .add_systems(Startup, translate)
        .run();
}
fn translate(
    keyboard:Res<ButtonInput<KeyCode>>,
    mut localize:ResMut<Localize>,
){
    //Easily set the language
    localize.set_language("German");
    if keyboard.just_pressed(KeyCode::Space){
        //Use the get() method to get a translated word for the specified keyword
        println!("{}",localize.get("start_game"));
    }
}

Using the LocalizeText component:

commands.spawn((
    TextBundle::from_section(
        "default value",
        TextStyle {
            font: asset_server.load("font.ttf"),
            font_size: 100.0,
            color: Color::WHITE,
        },
    ),
    //add this component to automatically translate text
    LocalizeText::from_section("my_keyword")
));

Examples

  • simple – Reading from a file to initialize the resource.
  • asset – Using asset handles to initialize the resource.
  • text – Using the LocalizeText component to update text.

Bevy Compatibility

bevy bevy_easy_localize
0.13 0.5
0.12 0.4
0.11 0.3
0.10 0.2
0.9 0.1

About

I made this crate for my personal projects. The obvious alternative is bevy_fluent, but my goal is to just translate some text and I don't need all of the fancy features it offers. I will definitely be updating this crate and if you want to add a feature, please submit a pull request.

Dependencies

~42–82MB
~1.5M SLoC