Localization base#272
Conversation
d9a416a to
4d43991
Compare
|
|
||
| commands.spawn(( | ||
| Text::new("No animation clip on selection. Pick a named entity and create one."), | ||
| LocalizedText("no-animation-clip-on-selection"), |
There was a problem hiding this comment.
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..
|
|
||
| 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. |
There was a problem hiding this comment.
this can come later probably?
| // TODO: consider storing a `fluent_content::Request` | ||
| #[derive(Component, Default, Reflect)] | ||
| #[require(Text)] | ||
| pub struct LocalizedText(pub String); |
There was a problem hiding this comment.
using request will enable us to use more advanced formats
| // 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; | ||
| } |
There was a problem hiding this comment.
currently we refresh every frame which is horrible performance wise
a69af11 to
75ea4e1
Compare
f2cfff0 to
d1272ed
Compare
| [features] | ||
|
|
||
| [dependencies] | ||
| bevy.workspace = true |
There was a problem hiding this comment.
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 :')
6cda06f to
30a31da
Compare
| 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" |
There was a problem hiding this comment.
sys-locale is not too maintained, but useful and not much "easy" alternatives to my knowledge
| 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" } |
There was a problem hiding this comment.
targeting my git branch, PR is kgv/bevy_fluent#58
use different asset source
30a31da to
5345647
Compare
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