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

Specifying a culture in GetDictionaryValue overrides the culture dictionary for the rest of the request #15765

Closed
matthewcare opened this issue Feb 26, 2024 · 5 comments · Fixed by #15908

Comments

@matthewcare
Copy link
Contributor

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.1.0

Bug summary

When using the Umbraco.GetDictionaryValue the culture dictionary is cached, if you use the overload to specify you want a dictionary value for a specific culture, then that culture is cached, and all future method calls will return values for that culture.

Specifics

I have a language switcher, and want to display a dictionary defined value for that culture

<ul>
@foreach (var (culture, _) in Model.Cultures.Where(x => !string.Equals(x.Key, CultureInfo.CurrentCulture.Name, StringComparison.InvariantCultureIgnoreCase)))
{
    <li><a href="@Model.Url(culture)">@Umbraco.GetDictionaryValue($"LanguageSwitcher.{culture}", CultureInfo.GetCultureInfo(culture))</a></li>
}
</ul>

Because I am specifying a culture in the GetDictionaryValue call, all future calls will use the culture of the last culture in the loop.

Steps to reproduce

On an Umbraco install with multiple configured languages, create a dictionary item and specify values for all cultures.

  • In a view call Umbraco.GetDictionaryValue("ItemKey") and observe the value is that of the current culture
  • Call Umbraco.GetDictionaryValue("ItemKey", CultureInfo.GetCultureInfo("you-other-culture")) and observe that the value is the specified culture.
  • Call Umbraco.GetDictionaryValue("ItemKey") once more, and observe that the value is the previously specified culture, and NOT the current culture.

e.g

<p>@Umbraco.GetDictionaryValue("FormInput.Email")</p> // E-mail
<p>@Umbraco.GetDictionaryValue("FormInput.Email", CultureInfo.GetCultureInfo("sv"))</p> // E-postadress
<p>@Umbraco.GetDictionaryValue("FormInput.Email")</p> // E-postadress. All future method calls will be "sv" culture

Expected result / actual result

Expected:
After specifying a culture for one method call, future calls with no culture specified should return values for the current culture

Actual:
After specifying a culture for one method call, future calls with no culture specified returns values for the culture supplied in whatever culture was used in a previous call.

Copy link

Hi there @matthewcare!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@elit0451
Copy link
Contributor

Thanks for reaching out @matthewcare 💪

I can indeed reproduce this. I managed to trace it back to when the new GetDictionaryValue overload was introduced: #12942

I can see you already started on a PR, so I will map this as up-for-grabs 🙂

Copy link

Hi @matthewcare,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post.

Thanks muchly, from your friendly Umbraco GitHub bot :-)

@elit0451 elit0451 removed their assignment Mar 19, 2024
@matthewcare
Copy link
Contributor Author

Hi @elit0451
Though marked as up-for-grabs, my PR was already finished and ready to go - just in case someone else comes along looking to fix it.

@elit0451
Copy link
Contributor

elit0451 commented May 6, 2024

Great, thanks for letting us know! 🙌 I will change to the appropriate label 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants