Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing locale at runtime #4

Closed
TheLeonsver1 opened this issue May 18, 2021 · 9 comments
Closed

Replacing locale at runtime #4

TheLeonsver1 opened this issue May 18, 2021 · 9 comments

Comments

@TheLeonsver1
Copy link

TheLeonsver1 commented May 18, 2021

I've tried to look at the code for ways to replace the chosen locale at runtime and I've noticed
that Snapshot has an IndexMap for the locales and their bundles.

But Snapshot's only being loaded with one locale(and I've discussed this with the community and they agree that it's better to hold in memory only the bundle for the locale used), the default locale that's set inside FluentSettings.

(It should be mentioned that I haven't checked if you load all the locale assets and keep them in memory even though they are not loaded into Snapshot)

I think that in this case, the IndexMap can be replaced with just a struct that holds a bundle and the locale used.

I've also seen that you cannot replace the locale used in-game unless you init_resource for the Snapshot again(after replacing the locale in FluentSettings), but that is not possible at the current version because you check that the resource wasn't already initiated in the world.

So it's currently impossible to replace the locale at runtime which I think would be really useful for your users.
would love to hear your input about these issues, thanks for the crate!

@kgv
Copy link
Owner

kgv commented May 19, 2021

@TheLeonsver1 Thanks for feedback

I am still undecided on the architecture of the plugin.

Snapshot from the main branch contains locale fallback chain only for current settings (not all available locales).
You can see how it constructs

You can take a look at debug branch. This branch implements locale change.

@TheLeonsver1
Copy link
Author

TheLeonsver1 commented May 19, 2021

Great :D would you be fine with adding this crate to 'awesome_bevy`?
I've already opened an issue about adding it to a new category there:
bevyengine/bevy-assets#96

@kgv
Copy link
Owner

kgv commented May 19, 2021

Thank you for your help.

I was planning to announce this plugin (including adding it to awesome-bevy) as soon as I have precisely defined its internal architecture.
But I think the current debug branch is what I wanted.
I think it will be quite possible to announce when the debug branch will be merged to main branch.

@TheLeonsver1
Copy link
Author

Cool! glad to hear :D

@TheLeonsver1
Copy link
Author

Hi, i'm trying to use the debug branch and ran into a problem with the syn dependency,
I fixed it with

[patch.'https://github.com/kgv/format']
format = { version = "0.2.4", git = "https://github.com//kgv/format", branch = "syn-1.0.65", optional = true, features = ["ext"] }

with help from the bevy discord,
could bevy_fluent depend on that branch of format by default maybe? at least for the 0.5 release,

I've been told that syn was updated on main already but bevy_fluent's debug branch is for 0.5 right?

@TheLeonsver1
Copy link
Author

I think there might be another issue, the assets loaded by FluentServer are never registered as LoadState::Loaded it seems. That is sort of an issue since I can't know when I can use them to update my text this way.

@kgv
Copy link
Owner

kgv commented May 25, 2021

branch = "syn-1.0.65" - the correct branch, it is my fail that i didn't change it in debug.

I've been told that syn was updated on main already but bevy_fluent's debug branch is for 0.5 right?

right

Be careful, the debug branch is not intended to be used, it can change at any time.

I am waiting bevyengine/bevy#2224 for merge debug with main.

assets loaded by FluentServer are never registered as LoadState::Loaded

The resulting asset (Localization) is not actually loaded. It is created based on several loaded components.
For this reason, it uses HandleId::Id, not HandleId::AssetPathId.
And (from the bevy source) HandleId::Id will always have the status LoadState::NotLoaded.

    pub fn get_load_state<H: Into<HandleId>>(&self, handle: H) -> LoadState {
        match handle.into() {
            HandleId::AssetPathId(id) => { ... }
            HandleId::Id(_, _) => LoadState::NotLoaded,
        }
    }

In the example, I solved this problem like this.

@TheLeonsver1
Copy link
Author

oh, got it, thank you very much for the help! :)

@kgv
Copy link
Owner

kgv commented May 31, 2021

Fixed: #5

@kgv kgv closed this as completed May 31, 2021
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

No branches or pull requests

2 participants