private IStringLocalizer CreateStringLocalizer()
        {
            var db = new LocalizationContext(
                new DbContextOptionsBuilder <LocalizationContext>()
                .UseSqlServer(_connectionString)
                .Options);

            db.Database.Migrate();

            // initial db
            if (!db.Cultures.Any())
            {
                db.AddRange(
                    new Culture
                {
                    Name      = "en",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Hello"
                        },
                        new Resource {
                            Key = "Message", Value = "Welcome"
                        }
                    }
                },
                    new Culture
                {
                    Name      = "ru",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Привет"
                        },
                        new Resource {
                            Key = "Message", Value = "Добро пожаловать"
                        }
                    }
                },
                    new Culture
                {
                    Name      = "de",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Hallo"
                        },
                        new Resource {
                            Key = "Message", Value = "Willkommen"
                        }
                    }
                }
                    );
                db.SaveChanges();
            }
            return(new EFStringLocalizer(db));
        }
Example #2
0
        private IStringLocalizer CreateStringLocalizer()
        {
            LocalizationContext _db = new LocalizationContext(
                new DbContextOptionsBuilder <LocalizationContext>()
                .UseSqlServer(_connectionString)
                .Options);

            // инициализация базы данных
            if (!_db.Cultures.Any())
            {
                _db.AddRange(
                    new Culture
                {
                    Name      = "en",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Hello"
                        },
                        new Resource {
                            Key = "Message", Value = "Welcome"
                        }
                    }
                },
                    new Culture
                {
                    Name      = "ru",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Привет"
                        },
                        new Resource {
                            Key = "Message", Value = "Добро пожаловать"
                        }
                    }
                },
                    new Culture
                {
                    Name      = "de",
                    Resources = new List <Resource>()
                    {
                        new Resource {
                            Key = "Header", Value = "Hallo"
                        },
                        new Resource {
                            Key = "Message", Value = "Willkommen"
                        }
                    }
                }
                    );
                _db.SaveChanges();
            }
            return(new EFStringLocalizer(_db));
        }