public static string Localize(this string key) { var cultureCode = LocalizationConfig.ActualCultureCode(); culturesResources.TryGetValue(cultureCode, out ResourceManager dictionary); return(dictionary?.GetString(key) ?? string.Empty); }
/// <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(); }
/// <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); }
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); }
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()); }
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); }
private void RepaintView() { LocalizationConfig config = this._configRepository.Get(); EditorInternalConfig internalConfig = this._configRepository.GetInternalConfig(); this._localizationConfigWindow.DefaultCulture = config.DefaultCulture; this._localizationConfigWindow.SceneExcludePrefix = internalConfig.SceneExcludePrefix; }
public void Build(IContainerBuilder containerBuilder, IBuilderContext context) { //TODO: Why is this done? --Aaron var textManager = LocalizationConfig.SetupDefault(); containerBuilder.ForFactory(x => LocalizationConfig.TextManager) .ScopedAs.Singleton(); }
public void Init(string _language, Action <string> _doIt) { actionChoose += _doIt; id = _language; LocalizationConfig _config = LocalizationData.GetConfig(id); txtName.text = _config.name; tick.SetActive(false); }
private void OnEnable() { HasFolder = Directory.Exists(Directory.GetCurrentDirectory() + "\\Localization\\"); if (HasFolder) { test = new LocalizationConfig(); test.ReadConfig(); } }
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)); }
public bool UpsertLocalizationConfig(LocalizationConfig config) { if (config.Id == 0) { return(AddLocalizationConfig(config)); } else { return(UpdateLocalizationConfig(config)); } }
void OnGUI() { if (_config == null) { _config = LocalizationManager.Config; } Editor editor = Editor.CreateEditor(_config); editor.DrawDefaultInspector(); }
/// <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); }
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); }
/// <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); }
// 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); }
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(); }
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); }
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)); }
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())); }
/// <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(); }
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(); }
// 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)); }
public static void Setup(TestContext ctx) { LocalizationConfig.RegisterLocalizationEntity <Language>(l => l.IsoCode); LocalizationConfig.RegisterLocalizationProvider(DefaultTestCulture); LocalizationConfig.RegisterCultureMapper(c => c.TwoLetterISOLanguageName); }
public bool DisableLocalizationConfig(LocalizationConfig config) { config.IsActive = false; return(UpdateLocalizationConfig(config)); }
public bool DeleteLocalizationConfig(LocalizationConfig config) { _context.LocalizationConfigs.Remove(config); return(_context.SaveChanges() > 0); }
public bool UpdateLocalizationConfig(LocalizationConfig config) { _context.LocalizationConfigs.Update(config); return(_context.SaveChanges() > 0); }