Ejemplo n.º 1
0
 public void LocalizeAll(ResourceDirectory resources, bool expandText)
 {
     foreach (ResXFile resXFile in resources.AllFiles) {
         foreach (LocString str in resXFile.AllStrings) {
             str.Localized = Localize(str.NonLocalized, expandText);
         }
     }
 }
Ejemplo n.º 2
0
        public void LoadFiles(string directory, CultureInfo culture)
        {
            resourceDirectory = new ResourceDirectory();
            resourceDirectory.ReadFiles(directory, culture);
            resourceDirectory.ReadResources();

            PopulateListView();
        }
Ejemplo n.º 3
0
        // Generate a DLL with resources in it.
        public bool Generate(ResourceDirectory directory)
        {
            string directoryPath = Path.Combine(OutputDirectory, directory.Culture.Name);
            if (!Directory.Exists(directoryPath))
                Directory.CreateDirectory(directoryPath);

            List<string> resourcesFiles = new List<string>();

            // Find tools.
            alExeName = RunProgram.FindSDKTool("al.exe");
            if (alExeName == null)
                ErrorText += @"Cannot find al.exe in the Windows SDK. Make sure the Windows SDK is installed in c:\Program Files\Microsoft SDKs\Windows";
            resgenExeName = RunProgram.FindSDKTool("resgen.exe");
            if (resgenExeName == null)
                ErrorText += @"Cannot find resgen.exe in the Windows SDK. Make sure the Windows SDK is installed in c:\Program Files\Microsoft SDKs\Windows";
            if (alExeName == null || resgenExeName == null)
                return false;

            // Convert all .resx to .resources.
            foreach (ResXFile resxFile in directory.AllFiles) {
                bool success = ConvertResX(resxFile, directoryPath);
                if (!success) {
                    ErrorText += programRunner.Output;
                    return false;
                }
            }

            // Create response file for AL.
            string responseFileName = Path.Combine(directoryPath, "alresp.txt");
            using (TextWriter responseWriter = new StreamWriter(responseFileName)) {
                responseWriter.WriteLine("/t:lib");

                foreach (ResXFile resxFile in directory.AllFiles) {
                    string resourceFile = GetResourcesName(resxFile, directoryPath);
                    responseWriter.WriteLine("/embed:\"{0}\",\"{1}.{2}\"", resourceFile, Namespace, Path.GetFileName(resourceFile));
                }

                responseWriter.WriteLine("/culture:{0}", directory.Culture.Name);
                responseWriter.WriteLine("/out:\"{0}\"", Path.Combine(directoryPath, DllName+".resources.dll"));
            }

            // Run AL.EXE
            int exitCode = programRunner.Run(alExeName, "\"@" + responseFileName + "\"", directoryPath);
            ErrorText += programRunner.Output;

            if (exitCode == 0) {
                foreach (ResXFile resxFile in directory.AllFiles) {
                    string resourceFile = GetResourcesName(resxFile, directoryPath);
                    File.Delete(resourceFile);
                }

                return true;
            }
            else
                return false;
        }
Ejemplo n.º 4
0
        private LocString FindLocString(PoLocation location, ResourceDirectory resdir)
        {
            foreach (ResXFile file in resdir.AllFiles)
                if (Path.GetFileName(file.NonLocalizedFileName) == location.FileName) {
                    if (file.HasString(location.Name))
                        return file.GetString(location.Name);
                }

            return null;
        }
Ejemplo n.º 5
0
        public void WritePot(ResourceDirectory directory)
        {
            WriteHeader();

            foreach (ResXFile resXFile in directory.AllFiles) {
                foreach (LocString str in resXFile.AllStrings) {
                    ProcessString(str);
                }
            }

            WriteStrings();

            writer.Close();
            writer = null;
        }
Ejemplo n.º 6
0
        public void Apply(List<PoEntry> entries, ResourceDirectory resdir, TextWriter statusOutput)
        {
            foreach (PoEntry entry in entries) {
                foreach (PoLocation location in entry.Locations) {
                    LocString str = FindLocString(location, resdir);
                    if (str != null) {
                        ApplyEntry(entry, str, statusOutput);
                    }
                    else {
                        statusOutput.WriteLine("No string found for non-loc '{0}' in '{1}'/'{2}' ", entry.NonLocalized, location.FileName, location.Name);
                    }
                }

                foreach (ResXFile resxfile in resdir.AllFiles)
                    foreach (LocString str in resxfile.AllStrings) {
                        if (str.NonLocalized == entry.NonLocalized) {
                            if (str.Localized != entry.Localized) {
                                statusOutput.WriteLine("Updating localized RESX for '{0}' to '{1}'", str.Name, entry.Localized);
                                str.Localized = entry.Localized;
                            }
                        }
                    }
            }
        }
Ejemplo n.º 7
0
        private void SynchronizePot(string resxDirectory, string potFileName, string programName, string email, string version)
        {
            ResourceDirectory resourceDirectory = new ResourceDirectory();

            resourceDirectory.ReadFiles(resxDirectory, CultureInfo.GetCultureInfo("en"));
            resourceDirectory.ReadResources();

            PoWriterAttributes attributes = new PoWriterAttributes() {
                Name = programName,
                Email = email,
                Version = version,
                writePOT = true
            };

            PoWriter potWriter = new PoWriter(potFileName, attributes);
            potWriter.WritePot(resourceDirectory);
        }
Ejemplo n.º 8
0
        private void SynchronizePoFile(string resxDirectory, string poDirectory, string baseName, CultureInfo culture, string programName, string email, string version, TextWriter statusOutput)
        {
            ResourceDirectory resourceDirectory = new ResourceDirectory();

            statusOutput.WriteLine("Reading RESX directory '{0}' for culture '{1}'", resxDirectory, culture.Name);
            resourceDirectory.ReadFiles(resxDirectory, culture);
            resourceDirectory.ReadResources();

            foreach (var resX in resourceDirectory.AllFiles) {
                statusOutput.WriteLine("   {0}", resX);
            }
            statusOutput.WriteLine();

            string cultureName = culture.Name;
            if (cultureName.EndsWith("-NO"))
                cultureName = cultureName.Substring(0, 2);
            cultureName = cultureName.Replace("-", "_");

            string poFileName = Path.Combine(poDirectory, baseName + "-" + cultureName + ".po");

            statusOutput.WriteLine("Reading PO file '{0}' for culture '{1}'", poFileName, culture.Name);
            PoReader reader = new PoReader(poFileName);
            List<PoEntry> entries = reader.ReadPo();
            ApplyPo applyPo = new ApplyPo();
            applyPo.Apply(entries, resourceDirectory, statusOutput);

            resourceDirectory.WriteResources();

            PoWriterAttributes attributes = new PoWriterAttributes() {
                Name = programName,
                Email = email,
                Version = version,
                writePOT = false
            };

            PoWriter potWriter = new PoWriter(poFileName, attributes);
            potWriter.WritePot(resourceDirectory);
        }
Ejemplo n.º 9
0
        public void ReadDirectory()
        {
            string directory = GetTestFileDirectory();

            ResourceDirectory resdir = new ResourceDirectory();
            resdir.ReadFiles(directory, new CultureInfo("de"));
            resdir.ReadResources();

            foreach (ResXFile resxfile in resdir.AllFiles) {
                Console.WriteLine("Nonlocalized ResXFile: {0}   LocalizedResXFile: {1}", resxfile.NonLocalizedFileName, resxfile.LocalizedFileName);
                Console.WriteLine("----------------------------------------------------------------");

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

                Console.WriteLine();
            }
        }
Ejemplo n.º 10
0
 public GenerationDialog(ResourceDirectory resDir)
     : this()
 {
     namespaceTextBox.Text = assemblyTextBox.Text = Path.GetFileName(resDir.BaseDirectoryPath);
 }