Ejemplo n.º 1
0
        /// <summary>
        /// Reads an XLIFF file as input and generates a properties file for 
        /// the language contained in the input file. If the input target 
        /// language is zh-CN, the output file will be named 
        /// ApplicationResources_zh-CN.properties. The output file is generated
        /// in the same directory as the input file
        /// </summary>
        /// <param name="args">Arguments are '--help', and '--xliff=' as the fully qualified input filename like C:\Test\XliffParser\TestXliff.xml</param>
        static void Main(string[] args)
        {
            try
            {
                // Command line parsing routine.
                Argument commandLine = new Argument(args);

                if (!String.IsNullOrEmpty(commandLine["help"]) || args.Length == 0)
                {
                    Help();
                }
                else {

                    if(!String.IsNullOrEmpty(commandLine["xliff"]))
                    {
                        XDocument doc = XDocument.Load(commandLine["xliff"]);
                        //NEED TO GET THE LANGUAGE FOR THE OUTPUT FILE NAME
                        string nameSpace = doc.Root.GetDefaultNamespace().NamespaceName;
                        XName xfile = XName.Get(NODE_FILE, nameSpace);
                        string language = doc.Descendants(xfile).FirstOrDefault().Attribute("target-language").Value.ToString();

                        XName xname = XName.Get(NODE_TRANS_UNIT, nameSpace);
                        XName xtarget = XName.Get(NODE_TARGET, nameSpace);

                        string outputPath = args[0].Substring(0, args[0].LastIndexOf("\\") + 1);

                        Resource res = new Resource();
                        Property pro = new Property();
                        Localizable loc = new Localizable();

                        // Write the resource file.
                        if (res.Write(ref doc, outputPath, language, ref FILENAME_PREFIX, ref ATTRIBUTE_ID, ref xname, ref xtarget))
                        {
                            Console.WriteLine("[INFO]	Generated {0} resource file", language);
                        }

                        // Write the properties file.
                        if (pro.Write(ref doc, outputPath, language, ref FILENAME_PREFIX, ref ATTRIBUTE_ID, ref xname, ref xtarget))
                        {
                            Console.WriteLine("[INFO]	Generated {0} properties file", language);
                        }

                        // Write the Localizable.strings file.
                        if (loc.Write(ref doc, outputPath, language, ref FILENAME_PREFIX, ref ATTRIBUTE_ID, ref xname, ref xtarget))
                        {
                            Console.WriteLine("[INFO]	Generated {0} strings file", language);
                        }
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void CanParseCommandLineArgs()
        {
            // /name=Jack
            // --name=Jack
            // --name="Multiple words"
            // -name 'Jack'

            // String array with 4 elements.
            string[] args = new string[]
            {
                " /name=Jack", "--name=Jack",
                "--name=\"Multiple words\"",
                "-name 'Jack'"
            };

            // Command line parsing tests.
            Argument commandLine = new Argument(args);
            Assert.IsNotNull(commandLine["name"]);
            string val = commandLine["name"];
            Assert.AreEqual("Jack", commandLine["name"]);
        }