TranslateTool.ResXFile.Write C# (CSharp) Method

Write() public method

public Write ( ) : void
return void
        public void Write()
        {
            // Create the new file.
            ResXResourceWriter writer = new ResXResourceWriter(LocalizedFileName);

            // Iterate the list view and write current items.
            foreach (LocString locstr in AllStrings) {
                if (!string.IsNullOrEmpty(locstr.Localized))
                    writer.AddResource(locstr.Name, locstr.Localized);
            }

            // Write all the non-string nodes back to the file.
            foreach (ResXDataNode dataNode in nonStringNodes)
                writer.AddResource(dataNode);

            writer.Generate();
            writer.Close();
        }

Usage Example

Exemplo n.º 1
0
        public void WriteResources()
        {
            string filename = GetTestFile("AboutForm.resx");
            ResXFile resXFile = new ResXFile(filename, new CultureInfo("fr"));
            resXFile.Read();

            LocString str = resXFile.GetString("label1.Text");
            str.Localized = "Foo";
            resXFile.Write();

            resXFile = new ResXFile(filename, new CultureInfo("fr"));
            resXFile.Read();

            ICollection<LocString> strings = resXFile.AllStrings;

            foreach (LocString locstr in strings) {
                Console.WriteLine("Name:{0}    NonLocValue:{1}   LocValue:{2}   Comment:{3}", locstr.Name, locstr.NonLocalized, locstr.Localized, locstr.Comment);
            }
        }