How to return dictionary items in the correct language?
Hello! Thanks for this great package!
I am attempting to use the data list editor to let the user pick from a checkbox list of localised dictionary terms.
In the back-end it still shows the names in English even though I have them set up for another language (Polish) as well. When I pull the items through onto the page it still shows in English!
It turns out that the Umbraco Dictionary Items data-source hasn't been working as intended. It (currently) only shows the labels of whichever language has been set to default.
I've been investigating with the code since you posted, and I can get the labels displaying in the other languages... but due to how the UI of switching between languages/cultures works, I've found that it's not always playing nicely with the Data List editor. e.g. sometimes it'll show the wrong language - which would be bad.
I'll have a think of how it could work, but can't make any promises to have a solution/workaround for it.
Hi Lee,
Thanks for getting back to me.
I did pull the code and have a tinker, unfortunately I'm not great with the backoffice stuff. I couldn't for the life of me figure out how to get the current language selected for the tab
I was messing around something like the below (UmbracoDictionaryDatalistSource.cs) but I think I may have been barking up the wrong tree. Either way I never got it to work. I'm not even sure if VariationContextAccessor is the right thing to be trying, documentation seems a bit sparse.
I guess alternatively you could add a language dropdown to the UI so you can choose which language you pull the dictionary items from?
I did a workaround in the end and just did a dictionary lookup on the page using the English key value (our dictionary key names are the same as their English value)
The culture code is passed through as a HTTP header (named X-UMB-CULTURE). It'll have the culture of whatever the content-tree is using at that point, which is promising - but if the culture is then switched with the in-page navigation (in the node name textfield), then it doesn't update.
I think the proper solution for this is for a dedicated property-editor that can populate the checkbox list values on the client-side, e.g. making an fetch/AJAX request with the correct culture code.
The issue with Data List is that it gets the data-source items in the initial payload, it doesn't do any client-side fetch/requests. Meaning that it isn't aware of any UI changes client-side.
Hope this makes sense? (or some of it at least? feels like I'm brain dumping)
How to return dictionary items in the correct language?
Hello! Thanks for this great package!
I am attempting to use the data list editor to let the user pick from a checkbox list of localised dictionary terms. In the back-end it still shows the names in English even though I have them set up for another language (Polish) as well. When I pull the items through onto the page it still shows in English!
Thanks
Hi Sam,
It turns out that the Umbraco Dictionary Items data-source hasn't been working as intended. It (currently) only shows the labels of whichever language has been set to default.
I've been investigating with the code since you posted, and I can get the labels displaying in the other languages... but due to how the UI of switching between languages/cultures works, I've found that it's not always playing nicely with the Data List editor. e.g. sometimes it'll show the wrong language - which would be bad.
I'll have a think of how it could work, but can't make any promises to have a solution/workaround for it.
On the off chance that anyone else has any ideas - I'm open to suggestions - the source-code for the Dictionary data-source is here: https://github.com/leekelleher/umbraco-contentment/blob/develop/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs#L75-L86
Thanks,
- Lee
Hi Lee, Thanks for getting back to me. I did pull the code and have a tinker, unfortunately I'm not great with the backoffice stuff. I couldn't for the life of me figure out how to get the current language selected for the tab
I was messing around something like the below (UmbracoDictionaryDatalistSource.cs) but I think I may have been barking up the wrong tree. Either way I never got it to work. I'm not even sure if VariationContextAccessor is the right thing to be trying, documentation seems a bit sparse.
I guess alternatively you could add a language dropdown to the UI so you can choose which language you pull the dictionary items from?
I did a workaround in the end and just did a dictionary lookup on the page using the English key value (our dictionary key names are the same as their English value)
Thanks Sam. It was the
VariationContextI was exploring with too, like you say it didn't work (as I'd expect it to work).I had more success using the
HttpContext, e.g.The culture code is passed through as a HTTP header (named
X-UMB-CULTURE). It'll have the culture of whatever the content-tree is using at that point, which is promising - but if the culture is then switched with the in-page navigation (in the node name textfield), then it doesn't update.I think the proper solution for this is for a dedicated property-editor that can populate the checkbox list values on the client-side, e.g. making an fetch/AJAX request with the correct culture code.
The issue with Data List is that it gets the data-source items in the initial payload, it doesn't do any client-side fetch/requests. Meaning that it isn't aware of any UI changes client-side.
Hope this makes sense? (or some of it at least? feels like I'm brain dumping)
Cheers,
- Lee
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.