Exemple #1
0
        public MenuItem(string alias, ILocalizedTextService textService)
            : this()
        {
            var values = textService.GetAllStoredValues(Thread.CurrentThread.CurrentUICulture);

            values.TryGetValue($"visuallyHiddenTexts/{alias}_description", out var textDescription);

            Alias           = alias;
            Name            = textService.Localize($"actions/{Alias}");
            TextDescription = textDescription;
        }
Exemple #2
0
        public async Task <Dictionary <string, Dictionary <string, string> > > LocalizedText(string culture = null)
        {
            CultureInfo cultureInfo;

            if (string.IsNullOrWhiteSpace(culture))
            {
                // Force authentication to occur since this is not an authorized endpoint, we need this to get a user.
                AuthenticateResult authenticationResult = await this.AuthenticateBackOfficeAsync();

                // We have to get the culture from the Identity, we can't rely on thread culture
                // It's entirely likely for a user to have a different culture in the backoffice, than their system.
                var user = authenticationResult.Principal?.Identity;

                cultureInfo = (authenticationResult.Succeeded && user is not null)
                    ? user.GetCulture()
                    : CultureInfo.GetCultureInfo(_globalSettings.DefaultUILanguage);
            }
            else
            {
                cultureInfo = CultureInfo.GetCultureInfo(culture);
            }

            var allValues    = _textService.GetAllStoredValues(cultureInfo);
            var pathedValues = allValues.Select(kv =>
            {
                var slashIndex = kv.Key.IndexOf('/');
                var areaAlias  = kv.Key.Substring(0, slashIndex);
                var valueAlias = kv.Key.Substring(slashIndex + 1);
                return(new
                {
                    areaAlias,
                    valueAlias,
                    value = kv.Value
                });
            });

            var nestedDictionary = pathedValues
                                   .GroupBy(pv => pv.areaAlias)
                                   .ToDictionary(pv => pv.Key, pv =>
                                                 pv.ToDictionary(pve => pve.valueAlias, pve => pve.value));

            return(nestedDictionary);
        }
Exemple #3
0
        internal MenuItem CreateMenuItem <T>(ILocalizedTextService textService, bool hasSeparator = false, bool opensDialog = false)
            where T : IAction
        {
            var item = Current.Actions.GetAction <T>();

            if (item == null)
            {
                return(null);
            }

            var values = textService.GetAllStoredValues(Thread.CurrentThread.CurrentUICulture);

            values.TryGetValue($"visuallyHiddenTexts/{item.Alias}Description", out var textDescription);

            var menuItem = new MenuItem(item, textService.Localize($"actions/{item.Alias}"))
            {
                SeparatorBefore = hasSeparator,
                OpensDialog     = opensDialog,
                TextDescription = textDescription,
            };

            return(menuItem);
        }