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

Fixes #12904 UmbracoHelper.GetDictionaryValue defaults to en-US when used in non-front end code #12942

Merged
merged 10 commits into from Jul 6, 2023

Conversation

uppercuut
Copy link
Contributor

Prerequisites

Brief : The main issue that the Method called GetDictionaryValue do not respect the default Umbraco culture//or send a parametric culture specification.

original issue #12904

Description

What's Changed :

### 1
DefaultCultureDictionary class :
this class has a property called Culture which were behaving as follows :
public CultureInfo Culture => _specificCulture ?? Thread.CurrentThread.CurrentUICulture;

though this is an umbraco-framework class it takes the culture of the entire application. hence if the consumer wants to change the default umbraco culture he has to change the entire solution's culture and I don't think its a good idea because we don't want to couple an entire solution which might use other frameworks/library who are culture dependent.

_long story short : _ I think the default culture of Umbraco should be the default Umbraco Context culture which is the default back office culture.

so (I think) it would be better if it was changed to :
public CultureInfo Culture => _specificCulture ?? new CultureInfo( _localizationService.GetDefaultLanguageIsoCode());

### 2

I renamed the method GetDictionaryValue which is overloaded with the altText to GetDictionaryValueOrDefault
and goes by the signature : string GetDictionaryValueOrDefault(string key, string altText)
it's Microsoft convention after all.

### 3

I added two new overloads in UmbracoHelper clss goes the the signatures
string GetDictionaryValueOrDefault(string key, CultureInfo specificCulture, string altText)
string? GetDictionaryValue(string key, CultureInfo specificCulture)

### 4
Added one overload into the ICultureDictionaryFactory which takes the specificCulture and in the implementation I just called DefaultCultureDictionary with the constructor that takes the specificCulture as parameters.

@github-actions
Copy link

github-actions bot commented Sep 3, 2022

Hi there @uppercuut, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@nul800sebastiaan nul800sebastiaan changed the base branch from v10/contrib to v11/contrib October 25, 2022 13:05
@nul800sebastiaan nul800sebastiaan changed the base branch from v11/contrib to contrib January 26, 2023 14:51
@nul800sebastiaan nul800sebastiaan changed the title Issue #12904 Fix Fixes #12904 UmbracoHelper.GetDictionaryValue defaults to en-US when used in non-front end code May 31, 2023
@emmagarland
Copy link
Contributor

Hi @uppercuut

Just going through some of the longer running PRs, and noticed this one has been open for a while with no reply, so firstly, apologies for that.

Just wanted to let you know that I've flagged it internally to get it reviewed in one of the upcoming sprints.

Best wishes,

Emma 🙂

Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

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

Hey @uppercuut, thanks a lot for the PR, it's greatly appreciated.

Over all it looks great, however, I'm afraid we can't change the default culture retuned by the Culture property since this is breaking.

I've taken the liberty of adding a small commit to help the PR better suit our internal code style (we generally don't use this. 😄)

Again thanks a lot 😄

Comment on lines 51 to 53
/// Returns the defualt umbraco's back office culture
/// </summary>
public CultureInfo Culture => _specificCulture ?? Thread.CurrentThread.CurrentUICulture;
public CultureInfo Culture => _specificCulture ?? new CultureInfo( _localizationService.GetDefaultLanguageIsoCode());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid we can't really introduce this change in minor since this is behaviorally breaking, unfortunately. Since this could suddenly change the culture of people's UmbracoCultureDictionary, potentially breaking the code.

However, I do agree that it would make more sense to default to the default language instead, so it may be one for a major 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hello , thanks for replying ,
honestly I don't remember what is this PR for , so I give you full liberty over it. tweak or change what ever u like

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's been quite a while, sorry about that, but I'll go ahead and undo this specific part, and then move that to V13. then we can merge the rest of this PR 😄

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

Successfully merging this pull request may close these issues.

None yet

3 participants