Exemplo n.º 1
0
        static MessageContext GetMessages(string lang)
        {
            string ftlPath = Path.Combine("..", "..", "..", $"{lang}.ftl");

            using (var sr = new StreamReader(ftlPath))
            {
                var options = new MessageContextOptions {
                    UseIsolating = false
                };
                var mc     = new MessageContext(lang, options);
                var errors = mc.AddMessages(sr);
                foreach (var error in errors)
                {
                    Console.WriteLine(error);
                }
                return(mc);
            }
        }
Exemplo n.º 2
0
        private MessageContext GetMessages(string lang)
        {
            var translationResource = Application.Current.FindResource(lang).ToString();

            using (var sr = new StreamReader(Application.GetResourceStream(new Uri(translationResource)).Stream))
            {
                var options = new MessageContextOptions {
                    UseIsolating = false
                };
                var mc     = new MessageContext(lang, options);
                var errors = mc.AddMessages(sr);

                foreach (var error in errors)
                {
                    Console.WriteLine(error);
                }

                return(mc);
            }
        }
Exemplo n.º 3
0
        IEnumerable <MessageContext> GetMessageContext(string language, string[] translations, IReadOnlyFileSystem fileSystem)
        {
            var backfall = translations.Where(t => t.EndsWith("en.ftl"));
            var paths    = translations.Where(t => t.EndsWith(language + ".ftl"));

            foreach (var path in paths.Concat(backfall))
            {
                var stream = fileSystem.Open(path);
                using (var reader = new StreamReader(stream))
                {
                    var options = new MessageContextOptions {
                        UseIsolating = false
                    };
                    var messageContext = new MessageContext(language, options);
                    var errors         = messageContext.AddMessages(reader);
                    foreach (var error in errors)
                    {
                        Log.Write("debug", error.ToString());
                    }

                    yield return(messageContext);
                }
            }
        }