Skip to content

Reactive Current Locale #200

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

Merged
merged 2 commits into from
Mar 29, 2025

Conversation

sylvano-tombo
Copy link
Contributor

@sylvano-tombo sylvano-tombo commented Feb 13, 2025

Add reactive current locale - Related to this #192

Copy link

@rottifant rottifant left a comment

Choose a reason for hiding this comment

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

I have just looked to see if there is a way to reactively retrieve the current language and have now discovered this PR.
Looks good.
Would be great if this could be merged asap :)

@rottifant
Copy link

@xiCO2k, are there any plans to merge this PR soon?

@xiCO2k xiCO2k changed the title Reactive current locale - Related to this #192 Reactive Current Locale Mar 29, 2025
@xiCO2k xiCO2k merged commit 8d8adbf into xiCO2k:main Mar 29, 2025
@xiCO2k
Copy link
Owner

xiCO2k commented Mar 29, 2025

Thanks for that.

@tcytra
Copy link

tcytra commented Mar 30, 2025

I believe this broke something. Prior to this I was using loadLanguageAsync() to switch locales and getActiveLanguage() would detect the change, Now it always returns the original html lang. The languages do switch, loadLanguageAsync() works, but after switching locales getActiveLanguage() doesn't detect the change. I'm going to need to freeze this at the previous version.

@sylvano-tombo
Copy link
Contributor Author

I believe this broke something. Prior to this I was using loadLanguageAsync() to switch locales and getActiveLanguage() would detect the change, Now it always returns the original html lang. The languages do switch, loadLanguageAsync() works, but after switching locales getActiveLanguage() doesn't detect the change. I'm going to need to freeze this at the previous version.

Hi @tcytra,

Could you provide a sample to reproduce the issue? This change shouldn’t affect anything else—it simply sets currentLanguage, which maintains its own value. All tests involving loadLanguageAsync() and getActiveLanguage() are passing on my end.

Maybe you forgot the await in loadLanguageAsync before calling getActiveLanguage()?

@tcytra
Copy link

tcytra commented Mar 31, 2025

Thanks for the response. I revisited this morning and (without changing anything) it's working for me again. I don't know why it stopped working or why it started working again. My apologies for a false alarm.

Comment on lines +36 to +38
export const currentLocale: ComputedRef<string> = computed(() => {
return I18n.getSharedInstance().getCurrentLanguage().value
})
Copy link

@Fuzzyma Fuzzyma Apr 28, 2025

Choose a reason for hiding this comment

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

Just saw this change in the release (thx!). But this part here is incorrect.
Whenever the locale change, you call getCurrentLanguage() (because its in the computed). and that method creates a new computed, returns it and you grab the value from it. By definition, computeds should never be recreated inside another computed.

So the correct approach here would be to simply use the computed directly:

export const currentLocale = I18n.getSharedInstance().getCurrentLanguage()

(You also wouldnt write computed(() => computed(() => something).value))

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.

5 participants