public static string Localize(this string key)
        {
            var cultureCode = LocalizationConfig.ActualCultureCode();

            culturesResources.TryGetValue(cultureCode, out ResourceManager dictionary);
            return(dictionary?.GetString(key) ?? string.Empty);
        }
예제 #2
0
        /// <summary>
        /// Call it before use any other method
        /// </summary>
        public static void Init()
        {
            config = new RuntimeConfigRepository().Get();

            if (config == null)
            {
                throw new NullReferenceException(nameof(LocalizationConfig));
            }

            translationDatabase = new TranslationDatabase(
                new TranslationRepository(
                    new TranslationStorageProvider()));

            defaultCulture = CultureMap.Get(config.DefaultCulture);
            translations   = new RuntimeTranslationInfoRepository().GetAll();

            if (translations.Length == 0)
            {
                Debug.LogWarning("No cultures found.");
            }

            isInit = true;

            SetDefaultCulture();
        }
예제 #3
0
        /// <summary>
        /// Gets the message.
        /// </summary>
        /// <param name="baseMessage">The base exceptions message to allow framework texts if not default message is specified.</param>
        /// <returns></returns>
        public string GetMessage(string baseMessage)
        {
            string text    = null;
            var    manager = LocalizationConfig.TextManagerResolver != null?
                             LocalizationConfig.TextManagerResolver() : null;

            if (manager != null)
            {
                text = manager.Get(Key, _parameters,
                                   callingAssembly: For.GetType().Assembly,
                                   returnNullOnMissing: true,
                                   encode: false);
            }

            if (text == null)
            {
                if (!string.IsNullOrEmpty(DefaultMessage))
                {
                    var args = new List <object>();
                    for (int i = 0; _parameters.Contains("" + i); i++)
                    {
                        args.Add(_parameters.GetObject("" + i));
                    }

                    text = string.Format(DefaultMessage, args.ToArray());
                }
                else
                {
                    text = baseMessage;
                }
            }

            return(text);
        }
예제 #4
0
 public bool AddLocalizationConfig(LocalizationConfig config)
 {
     config.Timestamp = config.Timestamp == DateTime.MinValue ? DateTime.UtcNow : config.Timestamp;
     config.Username  = config.Username ?? "Unknown";
     _context.LocalizationConfigs.Add(config);
     return(_context.SaveChanges() > 0);
 }
예제 #5
0
        public async Task <ActionResult> Edit(LocalizationConfigViewModel model, params string[] selectedRole)
        {
            if (ModelState.IsValid)
            {
                var config = _appEntities.GetLocalizationConfigById(model.Id);
                if (config == null)
                {
                    return(new StatusCodeResult(StatusCodes.Status404NotFound));
                }


                config = new LocalizationConfig()
                {
                    Id        = model.Id,
                    Culture   = model.Culture,
                    Parent    = model.Parent,
                    Key       = model.Key,
                    Value     = model.Value,
                    Timestamp = model.Timestamp,
                    Username  = model.Username,
                    IsActive  = model.IsActive
                };

                _appEntities.UpsertLocalizationConfig(config);
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Something failed.");
            return(View());
        }
예제 #6
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
            var container = new Container();
            var provider  = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            container.RegisterSingle <ILocalizedStringProvider>(provider);

            var factory = new UowHandlerFactory(container);

            factory.Register <SchoolContext>(lifestyle: new WebApiRequestLifestyle());
            container.RegisterWebApiRequest <IUowHandlerFactory>(() => factory);

            container.Verify();

            IoC.SetContainerProvider(() => container);
            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
            FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration);
        }
예제 #7
0
        private void RepaintView()
        {
            LocalizationConfig   config         = this._configRepository.Get();
            EditorInternalConfig internalConfig = this._configRepository.GetInternalConfig();

            this._localizationConfigWindow.DefaultCulture     = config.DefaultCulture;
            this._localizationConfigWindow.SceneExcludePrefix = internalConfig.SceneExcludePrefix;
        }
예제 #8
0
        public void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            //TODO: Why is this done? --Aaron
            var textManager = LocalizationConfig.SetupDefault();

            containerBuilder.ForFactory(x => LocalizationConfig.TextManager)
            .ScopedAs.Singleton();
        }
예제 #9
0
    public void Init(string _language, Action <string> _doIt)
    {
        actionChoose += _doIt;
        id            = _language;
        LocalizationConfig _config = LocalizationData.GetConfig(id);

        txtName.text = _config.name;
        tick.SetActive(false);
    }
예제 #10
0
 private void OnEnable()
 {
     HasFolder = Directory.Exists(Directory.GetCurrentDirectory() + "\\Localization\\");
     if (HasFolder)
     {
         test = new LocalizationConfig();
         test.ReadConfig();
     }
 }
예제 #11
0
        public ScanningRegistry()
        {
            var provider = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            For <ILocalizedStringProvider>().Use(provider);
            For <IUnitOfWork>().Use <UnitOfWork>();
            For <IDataContext>().Use <SchoolContext>();
            AssemblyScanner.FindValidatorsInAssemblyContaining <StudentEditValidator>()
            .ForEach(result => For(result.InterfaceType).Singleton().Use(result.ValidatorType));
        }
예제 #12
0
 public bool UpsertLocalizationConfig(LocalizationConfig config)
 {
     if (config.Id == 0)
     {
         return(AddLocalizationConfig(config));
     }
     else
     {
         return(UpdateLocalizationConfig(config));
     }
 }
예제 #13
0
    void OnGUI()
    {
        if (_config == null)
        {
            _config = LocalizationManager.Config;
        }

        Editor editor = Editor.CreateEditor(_config);

        editor.DrawDefaultInspector();
    }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public FakeFrameworkContext()
        {
            var fakeMapperList = new List <Lazy <AbstractMappingEngine, TypeMapperMetadata> >();

            TypeMappers      = new MappingEngineCollection(fakeMapperList);
            CurrentLanguage  = Thread.CurrentThread.CurrentCulture;
            TextManager      = LocalizationConfig.SetupDefault();
            ScopedFinalizer  = new NestedLifetimeFinalizer();
            TaskManager      = new ApplicationTaskManager(Enumerable.Empty <Lazy <AbstractTask, TaskMetadata> >());
            ApplicationCache = new HttpRuntimeApplicationCache();
            ScopedCache      = new ThreadStaticScopedCache();
        }
        public void LanguageEntityIsIdentifiedLCID()
        {
            LocalizationConfig.RegisterLocalizationEntity <Language>(l => l.LCID);
            LocalizationConfig.RegisterCultureMapper(c => c.LCID);

            var beerCategory = GetCategories()
                               .Where(c => c.Id == 1)
                               .Select(c => new { ID = c.Id, Name = c.Name })
                               .Localize()
                               .First();

            Assert.AreEqual("Bières", beerCategory.Name);
        }
예제 #16
0
        protected void Application_Start()
        {
            // register the localization routes
            // note: this must be invoked before the RouteConfig.RegisterRoutes
            //LocalizationConfig.RegisterRoutes(RouteTable.Routes);
            // specify the localiztion resource provider (and culture name resolver)
            LocalizationConfig.RegisterResourceProvider(() => new LocalizationDbResourceProvider());
            // register the localizable model providers
            LocalizationConfig.RegisterModelProviders();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
예제 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public FakeFrameworkContext(ISerializer serializer = null)
        {
            serializer = serializer ?? new ServiceStackSerialiser();
            var fakeMapperList = new List <Lazy <AbstractMappingEngine, TypeMapperMetadata> >();

            TypeMappers      = new MappingEngineCollection(fakeMapperList);
            CurrentLanguage  = Thread.CurrentThread.CurrentCulture;
            TextManager      = LocalizationConfig.SetupDefault();
            ScopedFinalizer  = new NestedLifetimeFinalizer();
            TaskManager      = new ApplicationTaskManager(Enumerable.Empty <Lazy <AbstractTask, TaskMetadata> >());
            ApplicationCache = new HttpRuntimeApplicationCache();
            ScopedCache      = new DictionaryScopedCache();
            Caches           = new DefaultFrameworkCaches(new DictionaryCacheProvider(), new RuntimeCacheProvider());
            Serialization    = new SerializationService(serializer);
        }
예제 #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();
            LocalizationConfig.Configure(services);
            services.AddMvc()
            .AddDataAnnotationsLocalization()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
        }
예제 #19
0
        public void SaveConfig()
        {
            var newConfig = new LocalizationConfig
            {
                DefaultCulture = this._localizationConfigWindow.DefaultCulture
            };

            var newInternalConfig = new EditorInternalConfig
            {
                SceneExcludePrefix        = this._localizationConfigWindow.SceneExcludePrefix,
                TranslationExportProvider = this._localizationConfigWindow.SelectedExportProvider,
                TranslationImportProvider = this._localizationConfigWindow.SelectedImportProvider
            };

            this._configRepository.Save(newConfig);
            this._configRepository.SaveInternalConfig(newInternalConfig);

            this.RepaintView();
        }
예제 #20
0
 public static string Get(string key)
 {
             #if UNITY_EDITOR
     if (!Application.isPlaying)
     {
         return(key);
     }
             #endif
     if (configSet == null)
     {
         configSet = Coo.configManager.GetConfig <string, LocalizationConfig>();
     }
     LocalizationConfig config = configSet[key];
     if (config != null)
     {
         return(config.content);
     }
     return(key);
 }
예제 #21
0
        public async Task <ActionResult> Create(LocalizationConfigsModel model, params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                var culture = new CultureInfo(model.SelectedLocalizationConfig.Culture);
                var config  = new LocalizationConfig()
                {
                    Id      = model.SelectedLocalizationConfig.Id,
                    Culture = model.SelectedLocalizationConfig.Culture,
                    Parent  = culture.Parent.Name,
                    Key     = model.SelectedLocalizationConfig.Key,
                    Value   = model.SelectedLocalizationConfig.Value,
                };

                var b = _appEntities.UpsertLocalizationConfig(config);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #22
0
        public static void Register(HttpConfiguration config)
        {
            //var cors = new EnableCorsAttribute("*", "*", "*");
            //config.EnableCors(cors);

            MediaTypeFormattingConfig.Configure(config);
            RoutingConfig.Configure(config);
            IoCConfig.Configure(config);
            TracingConfig.Configure(config, IoCConfig.Container);
            LoggingConfig.Configure();
            ExceptionHandlingConfig.Configure(config);
            ValidationConfig.Configure(config);
            LocalizationConfig.Configure(config);

            //configure authentication
            config.MessageHandlers.Insert(0, new AuthenticationHandler());

            //for gzip compression use:
            // config.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));
        }
예제 #23
0
        /// <summary>
        /// Configures the application using the provided builder, hosting environment, and logging factory.
        /// </summary>
        /// <param name="app">The current application builder.</param>
        /// <param name="env">The current hosting environment.</param>
        /// <param name="loggerFactory">The logging factory used for instrumentation.</param>
        /// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider)
        {
            loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
            loggerFactory.AddFile(this.Configuration.GetSection("Logging").GetValue <string>("PathFormat"), isJson: true);

            if (env.IsDevelopment() || Program.IsLocal(env))
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // Custom Configuration
            LocalizationConfig.Configure(app);
            SwaggerConfig.Configure(app, provider);

            app.UseHttpsRedirection();
            app.UseMvc();
        }
예제 #24
0
        public static void Initialize()
        {
            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
            var container = new Container();
            var provider  = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            container.RegisterSingle <ILocalizedStringProvider>(provider);

            //container.RegisterPerWebRequest<SchoolContext>();
            //container.RegisterPerWebRequest<IUnitOfWork, UnitOfWork>();

            var factory = new UowHandlerFactory(container);

            //factory.Register("default", () => new UnitOfWork(new SchoolContext()), new WebRequestLifestyle());
            //factory.Register("backup", () => new UnitOfWork(new BackupContext()), new WebRequestLifestyle());
            factory.Register <SchoolContext>(lifestyle: new WebRequestLifestyle());
            //factory.Register<FakeContext>("FakeContext", new WebRequestLifestyle());
            container.RegisterPerWebRequest <IUowHandlerFactory>(() => factory);
            container.Verify();
            IoC.SetContainerProvider(() => container);
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            FluentValidationModelValidatorProvider.Configure();
        }
예제 #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();
            LocalizationConfig.Configure(app);
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
 public static DefaultTextManager SetupDefaultManager(Assembly appAssembly, string overridesPath = null)
 {
     return((DefaultTextManager)ApplyDefaults(appAssembly, LocalizationConfig.SetupDefault(), overridesPath));
 }
예제 #27
0
 public static void Setup(TestContext ctx)
 {
     LocalizationConfig.RegisterLocalizationEntity <Language>(l => l.IsoCode);
     LocalizationConfig.RegisterLocalizationProvider(DefaultTestCulture);
     LocalizationConfig.RegisterCultureMapper(c => c.TwoLetterISOLanguageName);
 }
예제 #28
0
 public bool DisableLocalizationConfig(LocalizationConfig config)
 {
     config.IsActive = false;
     return(UpdateLocalizationConfig(config));
 }
예제 #29
0
 public bool DeleteLocalizationConfig(LocalizationConfig config)
 {
     _context.LocalizationConfigs.Remove(config);
     return(_context.SaveChanges() > 0);
 }
예제 #30
0
 public bool UpdateLocalizationConfig(LocalizationConfig config)
 {
     _context.LocalizationConfigs.Update(config);
     return(_context.SaveChanges() > 0);
 }