Skip to content

Commit

Permalink
0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kgv committed Nov 11, 2023
1 parent fc7eead commit 8c62112
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 758 deletions.
10 changes: 0 additions & 10 deletions .github/bors.toml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
interval: monthly

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
interval: monthly
25 changes: 13 additions & 12 deletions .github/workflows/ci.yml → .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: Rust

on:
push:
Expand All @@ -8,6 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings

jobs:
build:
Expand All @@ -18,22 +19,22 @@ jobs:
exclude:
- os: macos-latest
toolchain: nightly

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
toolchain: ${{ matrix.toolchain }}
- name: fmt
if: matrix.toolchain == 'nightly'
run: cargo fmt --all -- --check
- name: check
run: cargo check
- name: update & install
if: runner.os == 'linux'
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: build & test
run: cargo test --verbose
- name: clippy
run: cargo clippy --all
31 changes: 15 additions & 16 deletions Cargo.toml
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"
Expand All @@ -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"] }
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

## Version

| bevy | bevy_fluent |
|-------|-------------|
| 0.11 | 0.7 |
| 0.10 | 0.6 |
| 0.9 | 0.5 |
| 0.8 | 0.4 |
| bevy | bevy_fluent |
|------|-------------|
| 0.12 | 0.8 |
| 0.11 | 0.7 |
| 0.10 | 0.6 |
| 0.9 | 0.5 |
| 0.8 | 0.4 |

## See Also

Expand Down
36 changes: 20 additions & 16 deletions examples/fallback_chain/main.rs
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")
);
}
}
14 changes: 8 additions & 6 deletions examples/minimal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use unic_langid::langid;
pub fn main() {
App::new()
.insert_resource(Locale::new(langid!("en-US")))
.add_plugins(DefaultPlugins.set(AssetPlugin {
asset_folder: "examples/minimal/assets".to_string(),
..default()
}))
.add_plugins(FluentPlugin)
.add_plugins((
DefaultPlugins.set(AssetPlugin {
file_path: "examples/minimal/assets".to_string(),
..default()
}),
FluentPlugin,
))
.add_systems(Update, localized_hello_world)
.run();
}
Expand All @@ -21,7 +23,7 @@ fn localized_hello_world(
mut handle: Local<Option<Handle<BundleAsset>>>,
) {
let handle = &*handle.get_or_insert_with(|| asset_server.load("locales/en-US/main.ftl.yml"));
if let LoadState::Loaded = asset_server.get_load_state(handle) {
if let Some(LoadState::Loaded) = asset_server.get_load_state(handle) {
let bundle = assets.get(handle).unwrap();
assert!(matches!(bundle.content("hello-world"), Some(content) if content == "hello world"));
}
Expand Down
12 changes: 7 additions & 5 deletions examples/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use bevy_fluent::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(AssetPlugin {
asset_folder: "examples/ui/assets".to_string(),
..default()
}))
.add_plugins(FluentPlugin)
.add_plugins((
DefaultPlugins.set(AssetPlugin {
file_path: "examples/ui/assets".to_string(),
..default()
}),
FluentPlugin,
))
.insert_resource(Locale::new(ru::RU).with_default(en::US))
.insert_resource(Locales(vec![de::DE, en::US, ru::BY, ru::RU]))
.init_resource::<Font>()
Expand Down
21 changes: 11 additions & 10 deletions examples/ui/systems/load.rs
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>);
Loading

0 comments on commit 8c62112

Please sign in to comment.