-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
235 additions
and
758 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "bevy_fluent" | ||
version = "0.7.0" | ||
version = "0.8.0" | ||
authors = ["g <[email protected]>"] | ||
edition = "2021" | ||
description = "Bevy plugin for localization using Fluent" | ||
|
@@ -10,32 +10,31 @@ repository = "https://github.com/kgv/bevy_fluent" | |
license = "MIT OR Apache-2.0" | ||
keywords = ["bevy", "gamedev", "internationalization", "localization", "plugin"] | ||
categories = [ | ||
"games", | ||
"game-development", | ||
"games", | ||
"internationalization", | ||
"localization", | ||
] | ||
exclude = [".github/**/*"] | ||
|
||
[dependencies] | ||
anyhow = "1.0.70" | ||
bevy = { version = "0.11.0", default-features = false, features = [ | ||
"bevy_asset", | ||
] } | ||
bevy = { version = "0.12", default-features = false, features = ["bevy_asset"] } | ||
fluent = "0.16.0" | ||
fluent-langneg = "0.13.0" | ||
fluent_content = "0.0.5" | ||
globset = "0.4.10" | ||
indexmap = { version = "2.0.0", features = ["serde"] } | ||
fluent-langneg = "0.13.0" | ||
futures-lite = "2.0.0" | ||
indexmap = { version = "2.1.0", features = ["serde"] } | ||
intl-memoizer = "0.5.1" | ||
ron = "0.8.0" | ||
serde = { version = "1.0.160", features = ["derive"] } | ||
serde_yaml = "0.9.21" | ||
thiserror = "1.0.40" | ||
tracing = "0.1.37" | ||
ron = "0.8.1" | ||
serde = { version = "1.0.188", features = ["derive"] } | ||
serde_yaml = "0.9.27" | ||
thiserror = "1.0.50" | ||
tracing = "0.1.40" | ||
unic-langid = { version = "0.9.1", features = ["serde"] } | ||
uuid = { version = "1.3.1", features = ["serde", "v4", "v5"] } | ||
uuid = { version = "1.5.0", features = ["serde", "v4", "v5"] } | ||
# fluent-syntax = { git = "https://github.com/projectfluent/fluent-rs" } | ||
# globset = "0.4.13" | ||
|
||
[dev-dependencies] | ||
bevy = "0.11.0" | ||
bevy = "0.12" | ||
unic-langid = { version = "0.9.1", features = ["macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
use bevy::{asset::LoadState, prelude::*}; | ||
use bevy::{ | ||
asset::{LoadState, LoadedFolder}, | ||
prelude::*, | ||
}; | ||
use bevy_fluent::prelude::*; | ||
use fluent_content::Content; | ||
use unic_langid::langid; | ||
|
||
pub fn main() { | ||
App::new() | ||
.insert_resource(Locale::new(langid!("ru-RU")).with_default(langid!("en-US"))) | ||
.add_plugins(DefaultPlugins.set(AssetPlugin { | ||
asset_folder: "examples/fallback_chain/assets".to_string(), | ||
..default() | ||
})) | ||
.add_plugins(FluentPlugin) | ||
.add_plugins(( | ||
DefaultPlugins.set(AssetPlugin { | ||
file_path: "examples/fallback_chain/assets".to_string(), | ||
..default() | ||
}), | ||
FluentPlugin, | ||
)) | ||
.add_systems(Update, localized_hello_world) | ||
.run(); | ||
} | ||
|
||
fn localized_hello_world( | ||
localization_builder: LocalizationBuilder, | ||
asset_server: Res<AssetServer>, | ||
mut handle: Local<Option<Handle<LoadedFolder>>>, | ||
mut localization: Local<Option<Localization>>, | ||
mut handles: Local<Option<Vec<Handle<BundleAsset>>>>, | ||
) { | ||
let handles = | ||
handles.get_or_insert_with(|| asset_server.load_glob("locales/**/main.ftl.ron").unwrap()); | ||
let load_state = asset_server.get_group_load_state(handles.iter().map(Handle::id)); | ||
if let LoadState::Loaded = load_state { | ||
let localization = | ||
localization.get_or_insert_with(|| localization_builder.build(&*handles)); | ||
let handle = &*handle.get_or_insert_with(|| asset_server.load_folder("locales")); | ||
if let Some(LoadState::Loaded) = asset_server.get_load_state(handle) { | ||
let localization = localization.get_or_insert_with(|| localization_builder.build(handle)); | ||
// From ru-RU bundle, the first in fallback chain. | ||
assert!(matches!(localization.content("hello"), Some(v) if v == "привет")); | ||
assert!(matches!(localization.content("hello"), Some(content) if content == "привет")); | ||
// From ru-BY bundle, the second in fallback chain. | ||
assert!(matches!(localization.content("world"), Some(v) if v == "свету")); | ||
assert!(matches!(localization.content("world"), Some(content) if content == "свету")); | ||
// From en-US bundle, the last in fallback chain, default locale. | ||
assert!(matches!(localization.content("hello-world"), Some(v) if v == "hello world")); | ||
assert!( | ||
matches!(localization.content("hello-world"), Some(content) if content == "hello world") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
use crate::GameState; | ||
use bevy::{asset::LoadState, prelude::*}; | ||
use bevy::{ | ||
asset::{LoadState, LoadedFolder}, | ||
prelude::*, | ||
}; | ||
use bevy_fluent::prelude::*; | ||
|
||
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
let handles = asset_server | ||
.load_glob::<BundleAsset>("locales/**/menu.ftl.ron") | ||
.unwrap(); | ||
commands.insert_resource(Handles(handles)); | ||
let handle = asset_server.load_folder("locales"); | ||
commands.insert_resource(LocaleFolder(handle)); | ||
} | ||
|
||
pub fn update( | ||
mut commands: Commands, | ||
localization_builder: LocalizationBuilder, | ||
asset_server: Res<AssetServer>, | ||
mut next_state: ResMut<NextState<GameState>>, | ||
handles: Res<Handles>, | ||
locale_folder: Res<LocaleFolder>, | ||
) { | ||
if let LoadState::Loaded = asset_server.get_group_load_state(handles.0.iter().map(Handle::id)) { | ||
let localization = localization_builder.build(&handles.0); | ||
commands.remove_resource::<Handles>(); | ||
if let Some(LoadState::Loaded) = asset_server.get_load_state(&locale_folder.0) { | ||
let localization = localization_builder.build(&locale_folder.0); | ||
commands.remove_resource::<LocaleFolder>(); | ||
commands.insert_resource(localization); | ||
next_state.set(GameState::Menu); | ||
} | ||
} | ||
|
||
#[derive(Resource)] | ||
pub struct Handles(Vec<Handle<BundleAsset>>); | ||
pub struct LocaleFolder(Handle<LoadedFolder>); |
Oops, something went wrong.