Skip to content

Localization base#272

Open
ThierryBerger wants to merge 1 commit into
jbuehler23:mainfrom
ThierryBerger:localization
Open

Localization base#272
ThierryBerger wants to merge 1 commit into
jbuehler23:mainfrom
ThierryBerger:localization

Conversation

@ThierryBerger
Copy link
Copy Markdown
Contributor

@ThierryBerger ThierryBerger commented May 21, 2026

  • Using bevy_fluent for localization
  • a custom asset source, because I couldn't make it work with embedded
  • only a few translation keys added, to avoid conflicts and validate the approach first. I suggest adding keys in follow ups.
Visual representation of the logic

flowchart TD
    subgraph Startup
        SYS[sys_locale::get_locale] --> SL0[SelectedLocale]
        SYS --> LOC0[Locale requested + default en-US]
        LF[load_editor_locales] -->|asset_server.load_folder| FH[LocaleFolder = Handle<LoadedFolder>]
    end

    subgraph User
        U[User picks language] --> SL[SelectedLocale.locale mutated]
    end

    SL -->|resource_changed SelectedLocale| UUL[update_used_locale]
    UUL -->|writes Locale.requested| LOC[Locale]

    AS[AssetServer loads folder + .ftl.yml bundles] --> EV1[AssetEvent<LoadedFolder> LoadedWithDependencies]
    AS --> EV2[AssetEvent<BundleAsset> LoadedWithDependencies / Modified]

    LOC -->|is_changed| RC{localization_needs_rebuild}
    EV1 --> RC
    EV2 --> RC

    RC -->|true| RB[rebuild_localization]
    RB -->|LocalizationBuilder.build folder| LZN[Localization resource]

    LZN -->|resource_changed Localization| UAT[update_all_text]
    UAT -->|iter all LocalizedText| TXT[Text rendered]

    NEW[Spawn LocalizedText] -->|Changed<LocalizedText>| UCT[update_changed_text]
    EDIT[Mutate LocalizedText.0] -->|Changed<LocalizedText>| UCT
    UCT -->|reads| LZN
    UCT --> TXT

    classDef trigger fill:#eef,stroke:#669
    classDef build fill:#efe,stroke:#494
    class SL,EV1,EV2,LOC trigger
    class RB,LZN build
Loading

@ThierryBerger ThierryBerger force-pushed the localization branch 2 times, most recently from d9a416a to 4d43991 Compare May 21, 2026 23:56

commands.spawn((
Text::new("No animation clip on selection. Pick a named entity and create one."),
LocalizedText("no-animation-clip-on-selection"),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, to be clear, I'm not entirely happy with this whole "string as key to translation" solution, it's error prone, and difficult to test.

using an enum or some constants could enable us to verify that our locale files are correct 🤔

I'd lean towards keeping it simple for now..

Comment thread crates/jackdaw_localization/src/lib.rs Outdated

impl Plugin for LocalizationPlugin {
fn build(&self, app: &mut App) {
// TODO: use default platform locale then offer a way for user (or dev) to customize it.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can come later probably?

Comment thread crates/jackdaw_localization/src/lib.rs Outdated
Comment on lines +25 to +28
// TODO: consider storing a `fluent_content::Request`
#[derive(Component, Default, Reflect)]
#[require(Text)]
pub struct LocalizedText(pub String);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using request will enable us to use more advanced formats

Comment thread crates/jackdaw_localization/src/lib.rs Outdated
Comment on lines +39 to +44
// TODO: be clever about it and don't update it each frame
mut q_text: Query<(&LocalizedText, &mut Text)>,
) {
if q_text.is_empty() {
return;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently we refresh every frame which is horrible performance wise

@ThierryBerger ThierryBerger force-pushed the localization branch 2 times, most recently from a69af11 to 75ea4e1 Compare May 22, 2026 00:09
@ThierryBerger ThierryBerger changed the title WIP: Localization Localization base May 22, 2026
@ThierryBerger ThierryBerger force-pushed the localization branch 2 times, most recently from f2cfff0 to d1272ed Compare May 22, 2026 13:53
[features]

[dependencies]
bevy.workspace = true
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to split this in multiple crates, but that's what @janhohenheim is exploring on another PR, last to be merged gets to update :')

@ThierryBerger ThierryBerger force-pushed the localization branch 2 times, most recently from 6cda06f to 30a31da Compare May 22, 2026 14:32
Comment thread Cargo.toml
fluent_content = "0.0.5"
bevy_fluent = { git = "https://github.com/ThierryBerger/bevy_fluent.git", branch = "asset_path_resolve" }
unic-langid = { version = "0.9", features = ["macros"] }
sys-locale = "0.2"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys-locale is not too maintained, but useful and not much "easy" alternatives to my knowledge

Comment thread Cargo.toml
winit = "0.30.13"
image = { version = "0.25.10", default-features = false, features = ["png"] }
fluent_content = "0.0.5"
bevy_fluent = { git = "https://github.com/ThierryBerger/bevy_fluent.git", branch = "asset_path_resolve" }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targeting my git branch, PR is kgv/bevy_fluent#58

use different asset source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant