Example #1
0
        public CultureDetailsViewModel GetCultureDetailsViewModel(string culture) {
            var model = new CultureDetailsViewModel {Culture = culture};
            var session = _sessionLocator.For(typeof (LocalizableStringRecord));
            var query = session.CreateQuery(string.Format(@"
                    select s
                    from {0}Q42.DbTranslations.Models.LocalizableStringRecord as s fetch all properties
                    order by s.Path", DataTablePrefix()));
            var currentPath = "";
            var group = default(CultureDetailsViewModel.TranslationGroupViewModel);
            foreach (LocalizableStringRecord s in query.Enumerable()) {
                if (s.Path != currentPath) {
                    group = new CultureDetailsViewModel.TranslationGroupViewModel {
                        Path = String.Format(s.Path, culture)
                    };
                    if (!group.Path.Contains(culture))
                        throw new Exception("Something went wrong: the culture is not included in the path.");
                    model.Groups.Add(group);
                    currentPath = s.Path;
                }
                if (group != null) {
                    var translation = s.Translations.Where(t => t.Culture == culture).FirstOrDefault();
                    group.Translations.Add(new CultureDetailsViewModel.TranslationViewModel {
                        Context = s.Context,
                        Key = s.StringKey,
                        OriginalString = s.OriginalLanguageString,
                        LocalString = translation != null ? translation.Value : null
                    });
                }
            }

            return model;
        }
        public CultureDetailsViewModel GetCultureDetailsViewModel(string culture)
        {
            var model = new CultureDetailsViewModel { Culture = culture };
            var query = _localizableStringRepository.Table.AsEnumerable();
            var currentPath = "";
            var group = default(CultureDetailsViewModel.TranslationGroupViewModel);
            foreach (LocalizableStringRecord s in query)
            {
                if (s.Path != currentPath)
                {
                    group = new CultureDetailsViewModel.TranslationGroupViewModel
                    {
                        Path = String.Format(s.Path, culture)
                    };
                    if (!group.Path.Contains(culture))
                        throw new Exception("Something went wrong: the culture is not included in the path.");
                    model.Groups.Add(group);
                    currentPath = s.Path;
                }
                if (group != null)
                {
                    var translation = s.Translations.Where(t => t.Culture == culture).FirstOrDefault();
                    group.Translations.Add(new CultureDetailsViewModel.TranslationViewModel
                    {
                        Context = s.Context,
                        Key = s.StringKey,
                        OriginalString = s.OriginalLanguageString,
                        LocalString = translation != null ? translation.Value : null
                    });
                }
            }

            return model;
        }