public override void Initialize() { base.Initialize(); Environment = new EnvironmentBuilder().SetSettings(CreateSettings()).Build(); var assemblyConfig = new AssemblyContentConfig(GetType().GetTypeInfo().Assembly) { ResourceFolder = "Locales", ParserConfig = new ParserConfig { ThrowWhenKeyNotFound = true } }; I18N.Initialize(assemblyConfig); var textProvider = new MvxLocalizationProvider(assemblyConfig); Mvx.IoCProvider.RegisterSingleton <IMvxTextProvider>(textProvider); Mvx.IoCProvider.RegisterSingleton <IMvxLocalizationProvider>(textProvider); Mvx.IoCProvider.RegisterSingleton <IAppSettings>(new AppSettings(Environment)); Mvx.IoCProvider.LazyConstructAndRegisterSingleton(() => CrossConnectivity.Current); Mvx.IoCProvider.RegisterSingleton <IRepository>(() => new Repository()); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <ILogRepository, LogRepository>(); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <ILogWriter, LogWriter>(); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <ILogReader, LogReader>(); var logger = Mvx.IoCProvider.Resolve <IMvxLogProvider>().GetLogFor(nameof(App)); logger.Info("#################### Client Settings ####################"); logger.Error("Error"); logger.Fatal("Fatal"); logger.Warn("Warn"); }
public async Task Translate_Enum() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act var valueCatEn = friendlyLocale.TranslateEnum(Animal.Cat); var valueDogEn = friendlyLocale.TranslateEnum(Animal.Dog); var valueMonkeyEn = friendlyLocale.TranslateEnum(Animal.Monkey); await friendlyLocale.ChangeLocale("ru"); var valueCatRu = friendlyLocale.TranslateEnum(Animal.Cat); var valueDogRu = friendlyLocale.TranslateEnum(Animal.Dog); var valueMonkeyRu = friendlyLocale.TranslateEnum(Animal.Monkey); // Assert Assert.AreEqual("Cat Value", valueCatEn); Assert.AreEqual("Dog Value", valueDogEn); Assert.AreEqual("Monkey Value", valueMonkeyEn); Assert.AreEqual("Кот Значение", valueCatRu); Assert.AreEqual("Собака Значение", valueDogRu); Assert.AreEqual("Макака Значение", valueMonkeyRu); }
protected override void ReloadLocale() { var assemblyConfig = new AssemblyContentConfig(this.GetType().GetTypeInfo().Assembly) { ResourceFolder = "Locales" }; I18N.Initialize(assemblyConfig); this.ReloadItems(); }
public async Task NotExistsLocale_ThrowNotFound() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); // Act & Assert Assert.ThrowsAsync <FriendlyTranslateException>(async() => { await I18N.Instance.ChangeLocale("fr"); }); }
public async Task NotExistsEmbeddedResource_ThrowNotFound() { // Arrange I18N.Initialize(new AssemblyContentConfig(new List <Assembly> { typeof(LocaleTests).Assembly }) { ResourceFolder = "BadLocales" }); // Act & Assert Assert.ThrowsAsync <FriendlyTranslateException>(async() => { await I18N.Instance.ChangeLocale("en"); }); }
public async Task Detect_FullCultureName() { // Arrange I18N.Initialize(new AssemblyContentConfig(new List <Assembly> { typeof(LocaleTests).Assembly }) { ResourceFolder = "FullLocales" }); // Act & Assert await I18N.Instance.ChangeLocale("en-US"); await I18N.Instance.ChangeLocale("ru-RU"); }
public async Task Check_ThrowWhenKeyNotFound() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales", ThrowWhenKeyNotFound = true }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act & friendlyLocale.Translate("ViewModel.Locale.BadKey"); Assert.Throws <KeyNotFoundException>(() => { friendlyLocale.Translate("ViewModel.Locale.BadKey"); }); }
public async Task Translate_SomeWordsWithArgs_WithoutArgs() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act var value = friendlyLocale.Translate("ViewModel.Locale", 5); // Assert Assert.AreEqual("en", value); }
public async Task Translate_WithoutSomeObject() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act var value = friendlyLocale.TranslateNamingFormat("ViewModel.Test1.Test2.TestObject", new { foo = "foo value" }); // Assert Assert.AreEqual("Any foo value\nAny {bar}", value); }
public async Task Translate_SomeWordsWithArgs() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); var i18N = I18N.Instance; await i18N.ChangeLocale("en"); // Act var value = i18N.Translate("ViewModel.Test1.Test2.TestArgs", 5); // Assert Assert.AreEqual("Any 5", value); }
protected override void ReloadLocale() { var remoteConfig = new RemoteContentConfig { Locales = { { "ru", "https://raw.githubusercontent.com/kvandake/friendly-locale/master/Sample.Basic/FriendlyLocale.Sample.Core/Locales/ru.yaml" }, { "en", "https://raw.githubusercontent.com/kvandake/friendly-locale/master/Sample.Basic/FriendlyLocale.Sample.Core/Locales/en.yaml" } } }; // assembly offline locale var assembly = this.GetType().GetTypeInfo().Assembly; var offlineConfig = OfflineContentConfig.FromAssembly(assembly, "ru.yaml", "Locales"); I18N.Initialize(remoteConfig, offlineConfig); this.ReloadItems(); }
public async Task GetAvailableCultures() { // Arrange & Act & Assert I18N.Initialize(new AssemblyContentConfig(new List <Assembly> { typeof(LocaleTests).Assembly }) { ResourceFolder = "Locales" }); Assert.GreaterOrEqual(I18N.Instance.GetAvailableCultures().Count(), 0); I18N.Initialize(new AssemblyContentConfig(new List <Assembly> { typeof(LocaleTests).Assembly }) { ResourceFolder = "FullLocales" }); Assert.GreaterOrEqual(I18N.Instance.GetAvailableCultures().Count(), 0); }
public async Task Translate_SomeWordsWithFallback() { // Arrange I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales" }); var i18N = I18N.Instance; i18N.FallbackLocale = "en"; await i18N.ChangeLocale("fr"); // Act var value = i18N.Translate("ViewModel.Locale"); // Assert Assert.AreEqual("en", value); }
public async Task Check_Logger() { // Arrange var traces = new List <string>(); I18N.Initialize(new AssemblyContentConfig(this.GetType().Assembly) { ResourceFolder = "Locales", Logger = trace => { traces.Add(trace); } }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act & friendlyLocale.Translate("ViewModel.Locale.BadKey"); Assert.GreaterOrEqual(traces.Count, 0); }
public async Task Translate_MultipleAssemblies() { // Arrange var hostAssembly = this.GetType().Assembly; I18N.Initialize(new AssemblyContentConfig(new List <Assembly> { hostAssembly, typeof(LocaleTests).Assembly }) { ResourceFolder = "Locales" }); var friendlyLocale = I18N.Instance; await friendlyLocale.ChangeLocale("en"); // Act var value = friendlyLocale.Translate("ViewModel.Locale"); // Assert Assert.AreEqual("en", value); }
public async Task Chech_OfflineLocale() { // Arrange var hostAssembly = this.GetType().Assembly; var offlineConfig = OfflineContentConfig.FromAssembly(hostAssembly, "en.yaml", "Locales"); var remoteConfig = new RemoteContentConfig { CacheDir = Path.GetTempPath() }; I18N.Initialize(remoteConfig, offlineConfig); // Act var offlineLocale = I18N.Instance.GetLocale("offline"); await I18N.Instance.ChangeLocale(offlineLocale); var value = I18N.Instance.Translate("ViewModel.Locale"); // Assert Assert.NotNull(offlineLocale); Assert.AreEqual("en", value); }
public MvxLocalizationProvider(RemoteContentConfig config) { I18N.Initialize(config); }
public MvxLocalizationProvider(AssemblyContentConfig config) { I18N.Initialize(config); }
public MvxYamlTextProvider(RemoteContentConfig config) { I18N.Initialize(config); }
public MvxYamlTextProvider(AssetsContentConfig config) { I18N.Initialize(config); }