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

Accessing the current locale code from Twig #1056

Closed
Poldovico opened this issue Dec 17, 2019 · 5 comments
Closed

Accessing the current locale code from Twig #1056

Poldovico opened this issue Dec 17, 2019 · 5 comments
Assignees
Labels
internationalization Related to the localization feature
Milestone

Comments

@Poldovico
Copy link
Contributor

I can't seem to figure out how to get the current locale code (say "en_US" or "it_IT") from Twig in a simple way.
I may just be missing how to do it, but in case there currently isn't a self-contained way, I propose adding a dedicated key to each locale translation as a simple fix.

@Poldovico
Copy link
Contributor Author

If we do go with adding a dedicated key, I can make the PR myself but I'm not sure to which file.

@lcharette
Copy link
Member

That's actually a valid point. The default locale can be found in site.locale.default, but this can be overwritten by the user own locale...

Adding a key in the translation files is indeed a quick and easy fix. However, I'm working on improvement on the locale system for the next version, I'll add this to my list.

@lcharette lcharette self-assigned this Dec 17, 2019
@lcharette lcharette added the internationalization Related to the localization feature label Dec 17, 2019
@lcharette lcharette added this to the 4.4.0 milestone Dec 17, 2019
@Poldovico
Copy link
Contributor Author

Poldovico commented Dec 17, 2019 via email

@lcharette
Copy link
Member

Actually, what I meant was, The current locale can be overwritten by the user locale. So site.locale.default will always show the correct default locale, but this value might not be up to date with the user locale...

lcharette added a commit that referenced this issue Jan 11, 2020
@lcharette
Copy link
Member

Implemented in d3f3138 for UF 4.4. Will be available using the currentLocale global Twig variable:

{{ currentLocale }}

Result :

en_US

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internationalization Related to the localization feature
Projects
None yet
Development

No branches or pull requests

2 participants