Exemplo n.º 1
0
        private void GenerateBamlStream(Stream input, Stream output, Dictionaries curDictionaries)
        {
            string     commentFile   = Path.ChangeExtension(options.Input, "loc");
            TextReader commentStream = null;

            try
            {
                if (File.Exists(commentFile))
                {
                    commentStream = new StreamReader(commentFile);
                }

                // create a localizabilty resolver based on reflection
                var localizabilityReflector =
                    new BamlLocalizabilityByReflection(options.Assemblies);

                // create baml localizer
                var mgr = new BamlLocalizer(
                    input,
                    localizabilityReflector,
                    commentStream
                    );

                // get the resources
                var source       = mgr.ExtractResources();
                var translations = new BamlLocalizationDictionary();

                foreach (DictionaryEntry entry in source)
                {
                    var key = (BamlLocalizableResourceKey)entry.Key;
                    var translatedResource = curDictionaries.FindCorrespondence(key);
                    if (translatedResource != null)
                    {
                        string translatedContent = translatedResource.Content;

                        if (!String.IsNullOrEmpty(translatedContent))
                        {
                            var curResource = (BamlLocalizableResource)entry.Value;
                            if (curResource.Content != translatedContent)
                            {
                                translations.Add(key, translatedResource);
                            }
                        }
                    }
                }

                // update baml
                mgr.UpdateBaml(output, translations);
            }
            finally
            {
                if (commentStream != null)
                {
                    commentStream.Close();
                }
            }
        }