Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

DbLocalizationProvider with regular strings


Hi i'm using DbLocalizationProvider in a selectionFactory to display the enabled languages in a dropdown. 

But i was wondering if you could dynamically sent translation for a string to the DbLocalizationProvider instead of defined [LocalizedModel]/[LocalizedResource]. 

I want the editors to see the Text of the SelectItem in the language they are in. So translatable ... 

 public class CountrySelectionFactory : ISelectionFactory
        public IEnumerable GetSelections(ExtendedMetadata metadata)
            IList languages = ServiceLocator.Current.GetInstance()
                                                        .Select(lang => new LanguageSelector(lang.LanguageID))

            return languages.Select(ls => 
                                new SelectItem()                
                                    Text = ls.Language.Name, //Want to translate this via DbLocalizationProvider 
                                    Value = ls.Language.TwoLetterISOLanguageName
Edited, Aug 24, 2018 22:58

Hi Vishal, did you check the documentation in GitHub? From the guide: Translating in C#

So you would have the locazation "view model" registered for the languages and then fetch the localized sting using the mentioned code.

Another option would be to ask the question in GitHub on the project so Valdis might spot the question instead of just having it here on the Episerver forums.

Edited, Sep 02, 2018 19:41

Hi Antti,

thanks for your comment, although i have checked github and understand the basic of the viewmodel. Only in my case the text i want to translate comes dynamically from all the languages in Episerver (enabled). So i was looking of a way to translate those. 

Sep 03, 2018 8:41

I meant you would create a dummy view model where you would have the languages listed that you know will be supported and then you would need a mapping from language code for example to a property in the dummy view model. Sort of hack.

What if you just use the "NativeName" property on the CultureInfo object?

Sep 03, 2018 9:06
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.