Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

bevy-fluent

/bevy-fluent

Dodaje lokalizację do aplikacji Bevy 0.19 przez es-fluent-manager-bevy: typowane komunikaty EsFluent, FluentText<T> w UI, automatyczną rejestrację zmian języka, I18nPlugin i hot reload plików .ftl.

Repozytorium
bevy-skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
25.08.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
7
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 25.08.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Dodaje lokalizację do aplikacji Bevy 0.19 przez es-fluent-manager-bevy: typowane komunikaty EsFluent, FluentText<T> w UI, automatyczną rejestrację zmian języka, I18nPlugin i hot reload plików .ftl.

Oryginalny opis (EN)

Use when adding localization to a Bevy 0.19 app with `es-fluent-manager-bevy`, defining typed messages with `#[derive(EsFluent)]`, wrapping UI text in `FluentText<T>`, auto-registering locale updates with `#[derive(BevyFluentText)]`, or reacting to locale switches via `LocaleChangeEvent`. Covers `I18nPlugin`, `RequestedLanguageId`, `i18n.toml` config, and hot-reload of `.ftl` assets.

Jak działa

  1. When to use this skill
  2. Canonical pattern — 5-file minimum shape
  3. Topics
  4. Gotchas
  5. See also
Sekcje z nagłówków SKILL.md, w oryginale · 136 linii, 532 słów
Podgląd SKILL.md
---
name: bevy-fluent
description: Use when adding localization to a Bevy 0.19 app with `es-fluent-manager-bevy`, defining typed messages with `#[derive(EsFluent)]`, wrapping UI text in `FluentText<T>`, auto-registering locale updates with `#[derive(BevyFluentText)]`, or reacting to locale switches via `LocaleChangeEvent`. Covers `I18nPlugin`, `RequestedLanguageId`, `i18n.toml` config, and hot-reload of `.ftl` assets.
license: MIT
compatibility: opencode,claude-code,cursor
metadata:
  tier: "2"
  area: i18n
  bevy_version: "0.19"
---

# Bevy 0.19 — Localization (es-fluent)

## When to use this skill

- Adding Fluent-based i18n to a Bevy app (`es-fluent-manager-bevy = "0.19.2"`).
- Defining typed UI messages with `#[derive(EsFluent)]` and `#[derive(BevyFluentText)]`.
- Wrapping a UI text entity with `FluentText<T>` for automatic locale-driven refresh.
- Switching locales at runtime via `LocaleChangeEvent`.
- Reading the current locale from `RequestedLanguageId`.

## Canonical pattern — 5-file minimum shape

`Cargo.toml`:

```toml
[dependencies]
bevy                   = "0.19"
es-fluent              = { version = "0.18.1", features = ["derive"] }
es-fluent-manager-bevy = { version = "0.19.2", features = ["macros"] }
unic-langid            = "0.9"
```

`i18n.toml` (crate root, read at compile time):

```toml
fallback_language = "en"
assets_dir = "assets/locales"
```

`src/i18n.rs`:

```rust
es_fluent_manager_bevy::define_i18n_module!();
```

`src/lib.rs` — **message types must live here** (see Gotchas):

```rust
use bevy::prelude::*;
use es_fluent::EsFluent;
use es_fluent_manager_bevy::{
    BevyFluentText, FluentText, I18nPlugin, LocaleChangeEvent, RequestedLanguageId,
};
use unic_langid::langid;

pub mod i18n;

#[derive(BevyFluentText, Clone, EsFluent)]
#[fluent(namespace = "ui")]
pub enum UiMessage { StartGame, Settings, QuitGame }

pub fn build_i18n_plugin() -> I18nPlugin {
    I18nPlugin::with_language(langid!("en"))
}

pub fn setup_ui(mut commands: Commands) {
    commands.spawn(Camera2d);
    // FluentText<T> writes translations into a sibling Text component.
    commands.spawn((FluentText::new(UiMessage::StartGame), Text::new("")));
}

pub fn switch_locale_on_keypress(
    keys: Res<ButtonInput<KeyCode>>,
    requested: Res<RequestedLanguageId>,
    mut locale_events: MessageWriter<LocaleChangeEvent>,
) {
    if keys.just_pressed(KeyCode::KeyL) {
        let next = if requested.0.to_string() == "en" { langid!("fr") } else { langid!("en") };
        locale_events.write(LocaleChangeEvent(next));
    }
}
```

`src/main.rs` — thin binary entry point:

```rust
use bevy::prelude::*;
use my_game::{build_i18n_plugin, setup_ui, switch_locale_on_keypress};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(build_i18n_plugin())
        .add_systems(Startup, setup_ui)
        .add_systems(Update, switch_locale_on_keypress)
        .run();
}
```

Replace `my_game` with your package name (hyphens become underscores). The full
walkthrough — including the lib-vs-binary rationale, package-name placeholder,
and pure-binary-crate workarounds — is in
[references/lib-target-layout.md](references/lib-target-layout.md).

## Topics

| Topic | Reference |
|-------|-----------|
| Why types must live in the lib target; `cargo es-fluent generate` invisibility footgun; full layout | [references/lib-target-layout.md](references/lib-target-layout.md) |
| `BevyFluentText` derive vs `FluentText<T>` component; `Text::new("")` | [references/components.md](references/components.md) |
| `LocaleChangeEvent` (request) vs `LocaleChangedEvent` (confirmation); `RequestedLanguageId`; Messages vs Events | [references/locale-events.md](references/locale-events.md) |
| `i18n.toml` full schema, `assets_dir`, `I18nPluginConfig` runtime override | [references/i18n-toml.md](references/i18n-toml.md) |
| `generate`, `watch`, `check`, `clean`, `sync`, `tree`, `format` — dev and CI workflows | [references/cli.md](references/cli.md) |
| rustc 1.96+ requirement; `rust-toolchain.toml` pin; failure modes on older toolchains | [references/toolchain.md](references/toolchain.md) |

## Gotchas

1. **`cargo es-fluent generate` only sees the lib target.** Message enums
   declared only in `src/main.rs` are invisible to the CLI and produce empty
   `.ftl` output with no error. Move every `BevyFluentText` / `EsFluent`-derived
   type to `src/lib.rs` (or a module reachable from it). See
   [references/lib-target-layout.md](references/lib-target-layout.md).

2. **`BevyFluentText` is a derive macro; `FluentText<T>` is the component.** The
   derive registers refresh systems via `inventory`. The component is what you
   spawn on UI entities. In 0.19.2 the message type needs
   `FluentMessage + Clone + Send + Sync + 'static`; it does not derive
   `Component` itself. See
   [references/components.md](references/components.md).

3. **Minimum rustc 1.96.** Older toolchains fail with cryptic trait-resolution
   errors that do not mention the version requirement. Pin with
   `rust-toolchain.toml` (`[toolchain]` / `channel = "1.96"`). See
   [references/toolchain.md](references/toolchain.md).

4. **Events are Messages.** Use `MessageWriter<LocaleChangeEvent>` and
   `MessageReader<LocaleChangedEvent>` — not `EventWriter`/`EventReader`
   (renamed in Bevy 0.17). See [references/locale-events.md](references/locale-events.md).

## See also

- `bevy-ui` — `FluentText<T>` is used alongside `Text`, `Node`, and `Button`.
- `bevy-ecs-components` — `#[derive(Component)]` patterns required by `FluentText<T>`.
- `bevy-assets` — how Bevy's `AssetServer` loads `.ftl` files; relevant for hot-reload.
Pliki w paczce (7)
  • SKILL.md 6 KB
  • references/cli.md 3 KB
  • references/components.md 2 KB
  • references/i18n-toml.md 3 KB
  • references/lib-target-layout.md 5 KB
  • references/locale-events.md 3 KB
  • references/toolchain.md 1 KB

Wersje

W bazie nie ma innych skilli o nazwie bevy-fluent.

Migawka bazy z 13.11.2026 · wersja paczki 0aa7236dda2d (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100manage-bevy-assets
    Obsługuje zasoby w grze Bevy (sprite'y, audio, poziomy, dane własne): stan ładowania z uchwytami, jedna tabela zasobów, własne loadery, hot reload w dev, opcjonalne przetwarzanie i wbudowane zasoby dla buildów webowych.
  • 100bevy-assets
    Obsługuje zasoby w Bevy 0.19: wczytywanie przez AssetServer, Handle<T>, sceny glTF WorldAsset, Assets<T>, hot reload, AssetPath i backendy z Reader::seekable.
  • 100bevy-ecs-components
    Obsługuje komponenty ECS w Bevy 0.19: derive Component, wymagane komponenty #[require], obserwatory On<E>, wybór magazynu Table lub SparseSet, hooki cyklu życia i migrację zdarzenia Replace.
  • 100bevy-master
    Stanowi centralny przewodnik po Bevy ECS od wersji 0.20: pomaga zacząć grę, wyznaczyć granice ECS i wybrać odpowiedni skill Bevy.
  • 100bevy-ecs-components
    Definiuje komponenty Bevy 0.20: wymagane komponenty, obserwatory, przechowywanie Table lub SparseSet i hooki cyklu życia.
  • 100structure-bevy-app
    Pomaga dodawać funkcje do gry w Bevy lub porządkować ją: wtyczki na funkcję, stany aplikacji, kolejność systemów i konflikty zapytań.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.