DbLocalizationProvider with regular strings

Vote:
 

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()
                                                        .ListEnabled()
                                                        .Select(lang => new LanguageSelector(lang.LanguageID))
                                                        .ToList();

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

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.

#196498
Edited, Sep 02, 2018 19:41
Vote:
 

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. 

#196506
Sep 03, 2018 8:41
Vote:
 

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?

#196507
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.