public SettingsWithStringSourceViewModel() { // localize string source TestStringSource = new StringComboBoxSource(new List <SourceComboBoxItem>() { new SourceComboBoxItem("TEST_A", _localizer.Get("StringSource.TextA")), new SourceComboBoxItem("TEST_B", _localizer.Get("StringSource.TextB")) }); }
public void Should_get_value_in_all_languages() { var localizer = new Localizer(_culture); AssertLocalizer(localizer, 3); var en = localizer.Get("en-us", "test", "Hello"); var ru = localizer.Get("test", "Hello"); Assert.Equal("Hi", en, StringComparer.InvariantCultureIgnoreCase); Assert.Equal("Привет", ru, StringComparer.InvariantCultureIgnoreCase); }
private void BindUi() { var card = GameManager.Instance.CurrentCard; var world = GameManager.Instance.World; CardDescription.text = Localizer.Get(card.DescriptionTextLocalCode); CardFooter.text = Localizer.Get(card.Name); TurnCountDown.text = GameManager.Instance.TurnToApocalypse.ToString(); CardDisplay.sprite = SpriteManager.Get(card.SpriteName); Stat1Image.sprite = SpriteManager.Get(world.Stats[0].SpriteName); Stat2Image.sprite = SpriteManager.Get(world.Stats[1].SpriteName); Stat3Image.sprite = SpriteManager.Get(world.Stats[2].SpriteName); Stat4Image.sprite = SpriteManager.Get(world.Stats[3].SpriteName); Stat1Slider.value = world.Stats[0].Value; Stat2Slider.value = world.Stats[1].Value; Stat3Slider.value = world.Stats[2].Value; Stat4Slider.value = world.Stats[3].Value; Stat1Slider.GetComponentInChildren <Image>().color = SliderColorGradient.Evaluate((float)world.Stats[0].Value / 100); Stat2Slider.GetComponentInChildren <Image>().color = SliderColorGradient.Evaluate((float)world.Stats[1].Value / 100); Stat3Slider.GetComponentInChildren <Image>().color = SliderColorGradient.Evaluate((float)world.Stats[2].Value / 100); Stat4Slider.GetComponentInChildren <Image>().color = SliderColorGradient.Evaluate((float)world.Stats[3].Value / 100); }
private void UpdateUi(string textCode, List <CardEffect> effects) { ChoiceText.text = Localizer.Get(textCode); UpdateInpactGuess(Inpact1, effects, GameManager.Instance.World.Stats[0].Name); UpdateInpactGuess(Inpact2, effects, GameManager.Instance.World.Stats[1].Name); UpdateInpactGuess(Inpact3, effects, GameManager.Instance.World.Stats[2].Name); UpdateInpactGuess(Inpact4, effects, GameManager.Instance.World.Stats[3].Name); }
public UserValidation() { RuleFor(item => item.Username) .NotEmpty() .WithMessage(Localizer.Get(Resources.Required)); RuleFor(item => item.Username) .Must(BeValidUserName) .WithMessage(Localizer.Get(Resources.UsernameMustBeValid)); }
/// <summary> /// Returns the localized representation of the string /// </summary> /// <param name="neutralValue">The text to be localized</param> public virtual string S(string neutralValue, params object[] args) { var text = neutralValue; if (Localizer != null) { text = Localizer.Get(neutralValue, args); } return(text); }
void OnLocalize() { if (_label == null) { _label = GetComponent <GuiLabel> (); } if (!string.IsNullOrEmpty(_token)) { _label.Text = Localizer.Get(_token); } }
void OnLocalize() { if (!string.IsNullOrEmpty(_token)) { if ((object)_text == null) { _text = GetComponent <Text> (); } _text.text = Localizer.Get(_token); } }
void OnLocalize() { if (_sprite == null) { _sprite = GetComponent <GuiSprite> (); } if (!string.IsNullOrEmpty(_token)) { _sprite.SpriteName = Localizer.Get(_token); } }
void OnLocalize() { if (!string.IsNullOrEmpty(_token) && (object)_atlas != null) { if ((object)_image == null) { _image = GetComponent <Image> (); } _image.sprite = _atlas.Get(Localizer.Get(_token)); } }
/// <summary> /// Gets the navigation menu items. /// </summary> /// <returns>The navigation menu items.</returns> protected override IEnumerable <NavMenuItem> CreateNavigationMenuItems() { return(new[] { new NavMenuItem() { Symbol = GlyphIcons.HomeOutline, Label = Localizer.Get("Nav.Main"), DestinationPage = typeof(MainPage) } }); }
public Result <ServiceResponse> ChangePassword(ChangePasswordRequest request, [FromServices] IUserPasswordValidator passwordValidator) { return(this.InTransaction("Default", uow => { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.OldPassword)) { throw new ArgumentNullException("oldPassword"); } if (passwordValidator is null) { throw new ArgumentNullException(nameof(passwordValidator)); } var username = User.Identity?.Name; if (passwordValidator.Validate(ref username, request.OldPassword) != PasswordValidationResult.Valid) { throw new ValidationError("CurrentPasswordMismatch", Texts.Validation.CurrentPasswordMismatch.ToString(Localizer)); } if (request.ConfirmPassword != request.NewPassword) { throw new ValidationError("PasswordConfirmMismatch", Localizer.Get("Validation.PasswordConfirm")); } request.NewPassword = UserRepository.ValidatePassword(request.NewPassword, Localizer); string salt = null; var hash = UserRepository.GenerateHash(request.NewPassword, ref salt); var userId = int.Parse(User.GetIdentifier()); UserRepository.CheckPublicDemo(userId); uow.Connection.UpdateById(new UserRow { UserId = userId, PasswordSalt = salt, PasswordHash = hash }); Cache.InvalidateOnCommit(uow, UserRow.Fields); return new ServiceResponse(); })); }
/// <summary> /// Called each time the inspector's GUI is refreshed. /// </summary> public override void OnInspectorGUI() { LocalizedText myTarget = (LocalizedText)target; EditorGUIUtility.labelWidth = 60; // If the Locked flag is on, just show a selected label that is grayed out. if (myTarget.Locked) { EditorGUILayout.BeginHorizontal(); GUI.color = Color.grey; EditorGUILayout.LabelField("Token: ", GUILayout.Width(EditorGUIUtility.labelWidth - 4)); EditorGUILayout.SelectableLabel(myTarget.Token, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } else { myTarget.Token = EditorGUILayout.TextField("Token: ", myTarget.Token); } // If the token is in devon, set the Text components text to keep it updated. if (Localizer.Has(myTarget.Token)) { myTarget.GetComponent <Text>().text = Localizer.Get(myTarget.Token); } else { EditorGUILayout.LabelField("Token is not pushed to Devon"); if (myTarget.Token == "" && !myTarget.Locked) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Suggested:", GUILayout.Width(EditorGUIUtility.labelWidth + 10)); EditorGUILayout.SelectableLabel(SceneManager.GetActiveScene().name + "." + myTarget.transform.parent.name + "." + myTarget.name, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } } myTarget.Locked = EditorGUILayout.Toggle("Locked:", myTarget.Locked); if (!myTarget.Locked && GUILayout.Button("Generate Token Name")) { myTarget.Token = (SceneManager.GetActiveScene().name + "." + myTarget.transform.parent.name + "." + myTarget.name).ToLower(); EditorUtility.SetDirty(target); } }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); // push a toast notification var toast = _toastService.Factory.CreateToastText02(_localizer.Get("Welcome.Text"), DateTime.Now.ToString()); _toastService.Show(toast); // just a short delay to simulate some work await Task.Delay(100); deferral.Complete(); }
public void EmbeddedResource() { var localizer = new Localizer(new LocalizationSource(Assembly.GetExecutingAssembly(), $"{typeof(TranslationTests).Namespace}.embedded.json")); const string key1 = "InvalidInput"; // set thread's current culture to "ar" CultureInfo.CurrentCulture = new CultureInfo("ar"); Assert.Equal("إدخال غير صالح", localizer.Get(key1), StringComparer.Ordinal); Assert.Equal("خطا در اطلاعات ورودی", localizer.Get("fa", key1), StringComparer.Ordinal); // set threads current culture to "en" CultureInfo.CurrentCulture = new CultureInfo("en"); Assert.Equal("Invalid input", localizer.Get(key1), StringComparer.Ordinal); const string key2 = "unknownerror"; // set thread's current culture to "ar" CultureInfo.CurrentCulture = new CultureInfo("ar"); Assert.Equal(string.Format("خطأ غير معروف {0}", "some word"), localizer.GetFormat(key2, new [] { "some word" }), StringComparer.Ordinal); Assert.Equal(string.Format("خطای نامشخص {0}", "test"), localizer.GetFormat("fa", key2, "test"), StringComparer.Ordinal); // set threads current culture to "en" CultureInfo.CurrentCulture = new CultureInfo("en"); Assert.Equal(string.Format("Unknown error {0}", "!!"), localizer.GetFormat(key2, new [] { "!!" }), StringComparer.Ordinal); Assert.Equal(string.Format("Unknown error {0}", "!!"), localizer.GetFormat("de", key2, new[] { "!!" }), StringComparer.Ordinal); }
//public const string REGISTRY_KEY_PARENTNAME = "ParentDisplayName"; //public const string REGISTRY_KEY_SYSCOMPONENT = "SystemComponent"; //public const string REGISTRY_KEY_WININSTALLER = "WindowsInstaller"; //public const string REGISTRY_KEY_DISPLAYICO = "DisplayIcon"; //public const string REGISTRY_KEY_DISPLAYVER = "DisplayVersion"; public FixResult RemoveItem() { var result = new FixResult(Localizer.Get().DetectorNameApp); try { result.DidExist = this.DoesExist(); result.WasRemoved = this.Remove(); } catch (Exception ex) { result.DidFail = true; } return(result); }
protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); if (requestContext.HttpContext.Session["ApplicationMessage"] != null) { ViewBag.Message = requestContext.HttpContext.Session["ApplicationMessage"]; requestContext.HttpContext.Session.Remove("ApplicationMessage"); } Type controllerType = this.GetType(); string asmName = controllerType.Assembly.GetName().Name; ViewBag.Title = Localizer.Get(string.Format("{0}_{1}_Title", requestContext.RouteData.Values["controller"], requestContext.RouteData.Values["action"]), asmName); ViewBag.Description = Localizer.Get(string.Format("{0}_{1}_Description", requestContext.RouteData.Values["controller"], requestContext.RouteData.Values["action"]), asmName); }
/// <summary> /// Gets the navigation menu items that are docked at the bottom. /// </summary> /// <returns>The navigation menu items.</returns> protected override IEnumerable <NavMenuItem> CreateBottomDockedNavigationMenuItems() { return(new[] { new NavMenuItem() { Symbol = GlyphIcons.Info, Label = Localizer.Get("Nav.About"), DestinationPage = typeof(AboutPage) }, new NavMenuItem() { Symbol = GlyphIcons.Setting, Label = Localizer.Get("Nav.Settings"), DestinationPage = typeof(SettingsPage) } }); }
public void Should_throw_MissingBlockException() { var localizer = new Localizer(new CurrentCulture("ru-ru")); Assert.Throws <MissingBlockException>(() => localizer.Get("there_is_no_block", "Hello")); }
public Result <ServiceResponse> ResetPassword(ResetPasswordRequest request, [FromServices] ISqlConnections sqlConnections) { return(this.InTransaction("Default", uow => { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.Token)) { throw new ArgumentNullException("token"); } var bytes = HttpContext.RequestServices .GetDataProtector("ResetPassword").Unprotect(Convert.FromBase64String(request.Token)); int userId; using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { throw new ValidationError(Texts.Validation.InvalidResetToken.ToString(Localizer)); } userId = br.ReadInt32(); } UserRow user; if (sqlConnections is null) { throw new ArgumentNullException(nameof(sqlConnections)); } using (var connection = sqlConnections.NewFor <UserRow>()) { user = connection.TryById <UserRow>(userId); if (user == null) { throw new ValidationError(Texts.Validation.InvalidResetToken.ToString(Localizer)); } } if (request.ConfirmPassword != request.NewPassword) { throw new ValidationError("PasswordConfirmMismatch", Localizer.Get("Validation.PasswordConfirm")); } request.NewPassword = UserRepository.ValidatePassword(request.NewPassword, Localizer); string salt = null; var hash = UserRepository.GenerateHash(request.NewPassword, ref salt); UserRepository.CheckPublicDemo(user.UserId); uow.Connection.UpdateById(new UserRow { UserId = user.UserId.Value, PasswordSalt = salt, PasswordHash = hash }); Cache.InvalidateOnCommit(uow, UserRow.Fields); return new ServiceResponse(); })); }
public void Should_throw_MissingLocalizationException_if_there_is_no_culture() { var localizer = new Localizer(new CurrentCulture("ke-ke")); Assert.Throws <MissingLocalizationException>(() => localizer.Get("messages", "Hello")); }
public void Should_throw_MissingLocalizationException_if_there_is_no_key() { var localizer = new Localizer(new CurrentCulture("ru-ru")); Assert.Throws <MissingLocalizationException>(() => localizer.Get("messages", "there_is_no_localization")); }
public void OnLocalChanged() { StartGameButtonText.text = Localizer.Get("mainMenu_StartGameButtonText"); }
void OnGUI() { GUILayout.Label( "You can create localization file for all supported languages,\n" + "name it 'Localization.csv' and place at 'Resources' folder.\n" + "Good decision - use 'google docs' or 'office excel' with csv export.\n\n" + "Default language is 'English', user choice will be saved to user prefs."); foreach (var item in new [] { "English", "Russian", "German", "French" }) { if (GUILayout.Button(item)) { // After change language OnLocalize method notification will be sent to scene. // It can be used for relocalize custom user content (labels, sprite names, etc). Localizer.Language = item; } } GUILayout.Label(string.Format("\n<b>Localization for '{0}' is '{1}'</b>", TestKey, Localizer.Get(TestKey))); }
public static string Translate(string key) { return(Localizer.Get(CurrentLocale, key)); }