public WizardWindowViewModel(WizardWindow window, ApplicationStatusManager manager, SourceList <PhotoViewModel> photos, int selectedIndex) { _window = window; LocalizationContext = window.LocalizationContext; _router = new RoutingState(); _firstWizardViewModel = new FirstWizardViewModel(this, LocalizationContext); _secondWizardViewModel = new SecondWizardViewModel(this, LocalizationContext); _thirdWizardViewModel = new ThirdWizardViewModel(this, window, manager, LocalizationContext); _fourthWizardViewModel = new FourthWizardViewModel(this, manager, photos, selectedIndex, window.AppConfig, LocalizationContext); canGoNext = this .WhenAnyValue(x => x.CanGoNext); canGoBack = this. WhenAnyValue(x => x.CanGoBack); CanGoNext = true; CanGoBack = false; GoNext = ReactiveCommand.Create(Next, canGoNext); GoBack = ReactiveCommand.Create(Back, canGoBack); BackButtonText = LocalizationContext.WizardBackButtonText; NextButtonText = LocalizationContext.WizardNextButtonText; Log.Information("Wizard started."); }
public IEnumerable <CultureInfo> GetCultures() { using (var context = new LocalizationContext()) { return(context.Objects.Select(x => x.LocaleId).ToList().Distinct().Select(x => new CultureInfo(x)).ToList()); } }
public SettingsWindowViewModel(SettingsWindow window, LocalizationContext context, ref AppConfig config, ApplicationStatusManager manager, ThemeManager mainThemeManager, ThemeManager settingsThemeManager) { _window = window; this.LocalizationContext = context; _settingsThemeManager = settingsThemeManager; _mainThemeManager = mainThemeManager; _config = config; _newConfig = AppConfig.DeepCopy(_config); _applicationStatusManager = manager; InitView(); this.WhenAnyValue(x => x.ThemeIndex) .Skip(1) .Subscribe(x => SwitchSettingsTheme()); SetupCommands(); MLUrl = _newConfig.MlModelConfig.Url; UpdateModelStatusCommand.Execute().Subscribe(); }
public AboutViewModel(Window window, LocalizationContext localizationContext) { LocalizationContext = localizationContext; OpenLicenseCommand = ReactiveCommand.Create(OpenLicense); OpenGithubCommand = ReactiveCommand.Create(OpenGithub); OpenSiteCommand = ReactiveCommand.Create(OpenSite); }
/// <summary> /// Gets the current culture from the http request. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public static CultureInfo GetCurrentCulture(this HttpRequestBase request) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; return(LocalizationContext.TryGetCultureFromTwoLetterIsoCode( twoLetterISOLanguageName: currentCulture.TwoLetterISOLanguageName)); }
private async Task <Dictionary <string, TLocalized> > Load <TLocalized, TEntity>([NotNull] string culture) where TLocalized : class, ILocalizedIdentity <TEntity> where TEntity : IIdentity { using (var context = new LocalizationContext()) return(await context.Set <TLocalized>().Where(localized => localized.CultureKey == culture) .ToDictionaryAsync(localized => localized.StringKey).ConfigureAwait(false)); }
public virtual string LocalizeMessage(LocalizationContext context) { var localizer = context.LocalizerFactory.Create <IdentityResource>(); SetData(localizer); return(IdentityResult.LocalizeErrors(localizer)); }
public SettingsWindow(LocalizationContext context, ref AppConfig appConfig, ApplicationStatusManager manager, ThemeManager themeManager) { AppConfig = appConfig; AvaloniaXamlLoader.Load(this); var settingsThemeManager = new ThemeManager(this); settingsThemeManager.UseTheme(themeManager.CurrentTheme); this.DataContext = new SettingsWindowViewModel(this, context, ref appConfig, manager, themeManager, settingsThemeManager); }
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)); }
private async Task <TLocalized> Load <TLocalized, TEntity>([NotNull] string key, [NotNull] string culture) where TLocalized : class, ILocalizedIdentity <TEntity> where TEntity : IIdentity { using (var context = new LocalizationContext()) return(await context.Set <TLocalized>() .SingleOrDefaultAsync(localized => localized.StringKey == key && localized.CultureKey == culture) .ConfigureAwait(false)); }
public void Save(params ILocalizedObject[] list) { using (var context = new LocalizationContext()) { context.Objects.AddOrUpdate(list.Cast <LocalizedObject>().ToArray()); context.SaveChanges(); } LocalizationCache.Clear(); }
public ThirdWizardViewModel(IScreen screen, WizardWindow window, ApplicationStatusManager manager, LocalizationContext localizationContext) { _applicationStatusManager = manager; _window = window; LocalizationContext = localizationContext; HostScreen = screen; _appConfig = window.AppConfig; LoadModelCommand = ReactiveCommand.Create(LoadModel); UpdateModelStatusCommand = ReactiveCommand.Create(UpdateModelStatus); }
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)); }
public SecondWizardViewModel(IScreen screen, LocalizationContext localizationContext) { HostScreen = screen; LocalizationContext = localizationContext; this.ValidationRule( viewModel => viewModel.OutputPath, Directory.Exists, path => $"Incorrect path {path}"); SavePhotos = ReactiveCommand.Create(Save); }
public WizardWindow(AppConfig appConfig, LocalizationContext localizationContext, ThemeManager themeManager) { AppConfig = appConfig; LocalizationContext = localizationContext; ThemeManager = themeManager; var localThemeManager = new ThemeManager(this); localThemeManager.UseTheme(themeManager.CurrentTheme); this.WhenActivated(disposables => { }); AvaloniaXamlLoader.Load(this); }
public IEnumerable <Models.Language> GetSelectedLanguages() { //TODO: check if there is any? because maybe the cookie lived long and some languages got deleted? // otherwise something was changed/cached return(LocalizationContext.CurrentBackEndUserLanguages() .Select(o => o.CultureInfo) .Select(o => new Models.Language { ISOCode = o.Name, Name = o.EnglishName })); }
protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); var localization = DependencyResolver.Current.GetService <ILocalizationContext>(); localization.ChangeUrl = lang => { var url = Request.RawUrl; var result = LocalizationContext.ReplaceLangInUrl(url, lang); return(result); }; }
public async Task LoadGameText1Async() { using (var dc = new LocalizationContext( this.GetConnectionStringFromFile(this.options.CacheDebugLocalization))) { this.gameTexts = (await dc.BaseGameText .ToListAsync()) .ToDictionary(q => q.Tag, q => q.Text); } File.WriteAllText(@"D:\Temp\texts1.json", JsonConvert.SerializeObject(this.gameTexts)); }
public FirstWizardViewModel(IScreen screen, LocalizationContext localizationContext) { HostScreen = screen; LocalizationContext = localizationContext; this.ValidationRule( viewModel => viewModel.InputPath, Directory.Exists, path => $"Incorrect path {path}"); OpenPhotos = ReactiveCommand.Create(Open); }
/// <summary> /// Gets the current UI culture from the http request. /// </summary> /// <param name="request">The request.</param> /// <param name="getFromBrowserIfNotFound">if set to <c>true</c> [get from browser if not found].</param> /// <returns></returns> public static CultureInfo GetCurrentUICulture(this HttpRequestBase request, bool getFromBrowserIfNotFound = true) { CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; // If not found try to get it from the browser if (getFromBrowserIfNotFound && currentUICulture == null) { currentUICulture = request.TryGetCultureFromBrowser(); } return(LocalizationContext.TryGetCultureFromTwoLetterIsoCode( twoLetterISOLanguageName: currentUICulture.TwoLetterISOLanguageName)); }
public SaveAsWindowViewModel(Window window, SourceList <PhotoViewModel> photos, ApplicationStatusManager applicationStatusManager, LocalizationContext localizationContext) { LocalizationContext = localizationContext; _photos = photos; _applicationStatusManager = applicationStatusManager; this.ValidationRule( viewModel => viewModel.OutputPath, Directory.Exists, path => $"Incorrect path {path}"); SelectPathCommand = ReactiveCommand.Create(SelectOutputFolder); SaveCommand = ReactiveCommand.Create(SavePhotos, this.IsValid()); }
public ModelManagerWindowViewModel(ModelManagerWindow window, LocalizationContext context, ref AppConfig config, ApplicationStatusManager manager) { this.LocalizationContext = context; _config = config; _newConfig = AppConfig.DeepCopy(_config); _applicationStatusManager = manager; _avalableModels .Connect() .Bind(out _avalableModelsCollection) .Subscribe(); _installedModels .Connect() .Bind(out _installedModelsCollection) .Subscribe(); _repositories .Connect() .Bind(out _repositoriesCollection) .Subscribe(); var repoRule = this.ValidationRule( viewModel => viewModel.RepositoryToAdd, x => string.IsNullOrWhiteSpace(x) == false, x => $"Incorrect repository {x}"); UpdateModelStatusCommand = ReactiveCommand.Create(async() => { await UpdateModelStatus(); }, CanExecute()); UpdateInstalledModelsCommand = ReactiveCommand.Create(async() => { await UpdateInstalledModels(); }, CanExecute()); UpdateAvailableModelsCommand = ReactiveCommand.Create(async() => { await UpdateAvailableModels(); }, CanExecute()); DownloadModelCommand = ReactiveCommand.Create(async() => { await DownloadModel(); }, CanExecute()); RemoveModelCommand = ReactiveCommand.Create(async() => { await RemoveModel(); }, CanExecute()); ActivateModelCommand = ReactiveCommand.Create(async() => { await ActivateModel(); }, CanExecute()); AddRepositoryCommand = ReactiveCommand.Create(AddRepository, this.IsValid()); RemoveRepositoryCommand = ReactiveCommand.Create(RemoveRepository, CanExecute()); ApplyCommand = ReactiveCommand.Create(async() => { _config = AppConfig.DeepCopy(_newConfig); await _config.Save(); window.AppConfig = _config; window.Close(); }, CanExecute()); CancelCommand = ReactiveCommand.Create(window.Close, CanExecute()); Task.Run(Init); }
/// <summary> /// Gets a list of `SubNav` items under the `Node` passed in. /// </summary> /// <param name="node"></param> /// <returns></returns> public IEnumerable <SubNav> GetSubNavFromAliasPath(string nodeAliasPath, CultureInfo cultureInfo = null, ISiteInfo siteInfo = null) { if (siteInfo == null) { // If site is not provided, get the current site siteInfo = _siteService.CurrentSite; _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using current site"); } else { _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using passed in site"); } if (cultureInfo == null) { cultureInfo = LocalizationContext.GetCurrentCulture(); _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using current culture"); } else { _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using passed in culture"); } var subnavList = new List <SubNav>(); try { foreach (ITreeNode Node in DocumentQueryHelper.RepeaterQuery( Path: nodeAliasPath + "/%", CultureCode: cultureInfo.CultureCode, SiteName: siteInfo.SiteName, ClassNames: "CMS.MenuItem", OrderBy: "NodeLevel, NodeOrder", Columns: "MenuItemName,NodeAliasPath" )) { subnavList.Add(new SubNav() { LinkText = Node.GetValue("MenuItemName").ToString(), // You have to decide what your URL will be, for us our URLs = NodeAliasPath LinkUrl = Node.NodeAliasPath }); } } catch (Exception ex) { _eventLogService.LogException("ExampleService", "GET", ex); } return(subnavList); }
public FourthWizardViewModel(IScreen screen, ApplicationStatusManager manager, SourceList <PhotoViewModel> photos, int selectedIndex, AppConfig config, LocalizationContext localizationContext) { _applicationStatusManager = manager; _photos = photos; _selectedIndex = selectedIndex; _appConfig = config; LocalizationContext = localizationContext; StopCommand = ReactiveCommand.Create(Stop); HostScreen = screen; }
/// <summary> /// Get the language. /// </summary> /// <param name="paymentRequest"></param> protected virtual string GetLanguageCode(PaymentRequest paymentRequest) { var culture = paymentRequest.Payment != null && paymentRequest.Payment.PurchaseOrder != null && paymentRequest.PurchaseOrder.CultureCode != null ? new CultureInfo(paymentRequest.Payment.PurchaseOrder.CultureCode) : new CultureInfo("en-us"); // Culture based on order. // It's used in the AddLanguage call. LocalizationContext.SetCulture(culture); var languageCode = "2"; switch (LocalizationContext.CurrentCultureCode) { case "da": case "da-DK": languageCode = "1"; break; case "sv": case "sv-SE": languageCode = "3"; break; case "no": case "nb-NO": case "nn-NO": languageCode = "4"; break; case "is": case "is-IS": languageCode = "6"; break; case "de": case "de-DE": languageCode = "7"; break; case "fi": case "fi-FI": languageCode = "8"; break; } return(languageCode); }
public ILocalizedObject Get(int key) { var obj = LocalizationCache.Get <ILocalizedObject>(key.ToString()); if (obj == null) { using (var context = new LocalizationContext()) { obj = context.Objects.SingleOrDefault(o => o.Key == key); } LocalizationCache.Set(key.ToString(), obj); } return(obj); }
public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture) { var result = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name); if (result == null || !result.Any()) { using (var context = new LocalizationContext()) { result = context.Objects.Where(obj => obj.LocaleId == culture.LCID && obj.Scope.StartsWith("~/")).ToList(); } LocalizationCache.Set(culture.Name, result); } return(result); }
public static void InitializeDatabase(LocalizationContext context) { var cultureNL = new SupportedCulture() { IsSupported = true, Name = "nl" }; var cultureEN = new SupportedCulture() { IsSupported = true, Name = "en" }; context.SupportedCultures.Add(cultureNL); context.SupportedCultures.Add(cultureEN); context.SaveChanges(); var collection = new Dictionary <LocalizationKey, (SupportedCulture Culture, string Value)[]>()
public override void Init( InspectorPropertyAttribute inspectorProperty, EditorContext editorContext, LocalizationContext localizationContext, object currentValue, bool valueInherited) { base.Init(inspectorProperty, editorContext, localizationContext, currentValue, valueInherited); // Disable for localized strings. // TODO(np): Enable editing while not showing RAW values. var stringProperty = inspectorProperty as InspectorStringAttribute; if (stringProperty != null && stringProperty.Localized) { this.IsEnabled = false; } }
private string _getLocalizationString(LocalizationContext context, CultureInfo culture, string baseKey, string mainKey, bool updateLastUsed) { var cultureName = culture.Name; var dbCulture = context.SupportedCultures.SingleOrDefault(c => c.Name == cultureName && c.IsSupported); if (dbCulture == null) { return(null); } var dbKey = context.LocalizationKeys.SingleOrDefault(k => k.Base == baseKey && k.Key == mainKey); if (dbKey == null) { // Key doesn't exist, create! dbKey = new LocalizationKey() { Base = baseKey, Key = mainKey, Comment = LocalizationKey.DEFAULT_COMMENT }; try { context.LocalizationKeys.Add(dbKey); context.SaveChanges(); } catch (DbUpdateException ex) when((ex.InnerException as System.Data.SqlClient.SqlException)?.Number == 2601) { // Key already exists, (concurrent request probably added it): reload entity. context.Entry(dbKey).State = EntityState.Detached; dbKey = context.LocalizationKeys.SingleOrDefault(k => k.Base == baseKey && k.Key == mainKey); } } var localization = context.LocalizationRecords .Where(r => r.LocalizationKey.Id == dbKey.Id && r.Culture.Id == dbCulture.Id) .SingleOrDefault(); if (updateLastUsed && localization != null) { localization.LastUsed = DateTime.Now; context.SaveChanges(); } return(localization?.Text); }
/// <summary> /// Exports a set of resource types into the portable object file. /// </summary> /// <param name="provider">The provider.</param> /// <param name="objects">The objects.</param> /// <returns>The PO file.</returns> public virtual File Export(ResourceProvider provider, ResourceObjectProviderBase objects = null) { var culture = Culture ?? CultureInfo.InstalledUICulture; var originalContext = new LocalizationContext(EmptyResourceProvider.Instance, CultureInfo.InvariantCulture, new ResourceObjectProvider()); var translatedContext = new LocalizationContext(new GettextResourceProvider(provider), culture, objects); var list = new List<Entry>(); var stringType = typeof (string); CachedResourceObjectProvider.RemoveAllCachedObjects(); foreach (var type in _types) { var original = originalContext.GetResourceObject(type); var translated = translatedContext.GetResourceObject(type); var set = type.FullName; var comments = GetComments(type.GetCustomAttributes<POCommentAttribute>()); list.AddRange(ResourceObjectProviderBase.EnumerateFields(type).Where(x => x.FieldType == stringType).Select(field => new Entry { Context = string.Format("{0}.{1}", set, field.Name), OriginalText = (string) field.GetValue(original), TranslatedText = (string) field.GetValue(translated), Comments = GetComments(field.GetCustomAttributes<POCommentAttribute>(), comments) })); list.AddRange(ResourceObjectProviderBase.EnumerateProperties(type).Where(x => x.PropertyType == stringType).Select(property => new Entry { Context = string.Format("{0}.{1}", set, property.Name), OriginalText = (string)property.GetValue(original, null), TranslatedText = (string)property.GetValue(original, null), Comments = GetComments(property.GetCustomAttributes<POCommentAttribute>(), comments) })); } CachedResourceObjectProvider.RemoveAllCachedObjects(); return new File(Name, culture.Name, list); }