Example #1
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            try {
                CosmosLocalization.Initialize()
                .ToGlobal(c => c.SetPathBase(Directory.GetCurrentDirectory()).SetPathSegment("Resources/I18N"))
                .AddJsonResourceFrom("Main.*")
                .AddJsonAnonymousResourceFrom()
                .AddHandlebars()
                .AllDone();

                Console.WriteLine("Handlebars =====================");
                var template = @"{{T 'Hello world {0}', 'Main', 'zh-CN'}}";

                var compiledTemplate = HandlebarsDotNet.Handlebars.Compile(template);
                var context          = new { Now = DateTime.Now, Number = 2, A = "Alex LEWIS" };
                var result           = compiledTemplate(context);
                Console.WriteLine(result);
            } catch (Exception exception) {
                Console.WriteLine(exception.Message);
                Console.WriteLine(exception.Source);
                Console.WriteLine(exception.StackTrace);
            }


            Console.ReadLine();
        }
Example #2
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            try
            {
                CosmosLocalization.Initialize()
                .ToGlobal(c => c.SetPathBase(Directory.GetCurrentDirectory()).SetPathSegment("Resources/I18N"))
                .AddJsonResourceFrom("Main.*")
                .AddJsonAnonymousResourceFrom()
                .AllDone();

                Console.WriteLine("Basic =========================");

                Console.WriteLine(new Text("Hello world {0}", "Main", "zh-CN", DateTime.Now));
                Console.WriteLine(new Text("Hello world {0}", "Main", "en-US", DateTime.Now));
                Console.WriteLine(new Text("Hello world {0}", "Main", "en-GB", DateTime.Now));

                Console.WriteLine("Current LanguageTag ===========");

                Console.WriteLine(new Text("Hello world {0}", "Main", DateTime.Now)); //en-US
                LanguageTagCoreManager.UpdateTag("zh-CN");
                Console.WriteLine(new Text("Hello world {0}", "Main", DateTime.Now)); //zh-CN

                Console.WriteLine("Fallback LanguageTag ==========");
                Console.WriteLine(new Text("Hello world {0}", "Main", "en-CA", DateTime.Now));

                Console.WriteLine("Update Current LanguageTag handler");
                LanguageTagCoreManager.UpdateTagChangedHandler(DisplayNewLanguageTag);
                LanguageTagCoreManager.UpdateTag("zh-CN");
                LanguageTagCoreManager.UpdateTag("zh-TW");

                Console.WriteLine("Without Parameters ===========");
                Console.WriteLine(new Text("Hello world {0}", "Main")); //zh-CN

                Console.WriteLine("Custom Translate Format Provider ===========");
                Console.WriteLine(new Text("Hello world {0}", "Main", DateTime.Now)
                {
                    CustomFormatProvider = CustomFormatProvider
                });                                                                                                                 //zh-CN

                Console.WriteLine("Anonymous ==============================");
                LanguageTagCoreManager.UpdateTag("zh-CN");
                Console.WriteLine(new Text("Hello anonymous world {0}", TranslationManager.ANONYMOUS_PACKAGE_KEY, DateTime.Now)); //zn-CN
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                Console.WriteLine(exception.Source);
                Console.WriteLine(exception.StackTrace);
            }


            Console.ReadLine();
        }
Example #3
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            try {
                CosmosLocalization.Initialize()
                .ToGlobal(c => c.SetPathBase(Directory.GetCurrentDirectory()).SetPathSegment("Resources/I18N"))
                .AddJsonResourceFrom("Main.*.json")
                .AllDone();

                Console.WriteLine(new Text("Hello world {0}", "Main", Locale.zh_CN, DateTime.Now));
                Console.WriteLine(new Text("Hello world {0}", "Main", Locale.en_US, DateTime.Now));
                Console.WriteLine(new Text("Hello world {0}", "Main", Locale.en_GB, DateTime.Now));

                Console.WriteLine("Hello world");
            }
            catch (Exception exception) {
                Console.WriteLine(exception.Message);
                Console.WriteLine(exception.Source);
                Console.WriteLine(exception.StackTrace);
            }


            Console.ReadLine();
        }