Exemple #1
0
        public virtual void LoadLocalizations(TEntity ent)
        {
            TranslateService translateService = ServiceProvider.GetService <TranslateService>();

            foreach (var culture in CultureHelper.Cultures)
            {
                TLocaleModel localeModel = Activator.CreateInstance <TLocaleModel>();

                Type           entType          = ent.GetType();
                Type           localeType       = localeModel.GetType();
                PropertyInfo[] entProperties    = entType.GetProperties();
                PropertyInfo[] localeProperties = localeType.GetProperties();

                foreach (PropertyInfo localeProperty in localeProperties)
                {
                    if (localeProperty.IsStringProperty())
                    {
                        PropertyInfo entProperty = entProperties.FirstOrDefault(w => w.Name == localeProperty.Name);

                        if (entProperty == null)
                        {
                            continue;
                        }

                        localeProperty.SetValue(
                            localeModel,
                            translateService.GetTranslation(entProperty.GetValue(ent, null).ToString(), culture.Code),
                            null
                            );
                    }
                }

                localeModel.CultureCode = culture.Code;
                Localizations.Add(localeModel);
            }
        }