Write() public method

public Write ( System.Xml.Linq.XDocument &doc, string outputPath, string language, string &FILENAME_PREFIX, string &ATTRIBUTE_ID, System.Xml.Linq.XName &xname, System.Xml.Linq.XName &xtarget ) : bool
doc System.Xml.Linq.XDocument
outputPath string
language string
FILENAME_PREFIX string
ATTRIBUTE_ID string
xname System.Xml.Linq.XName
xtarget System.Xml.Linq.XName
return bool
Beispiel #1
0
        public void CanWriteLocalizableFile()
        {
            string prefix = "ApplicationResources_";
            string id = "id";

            XDocument doc = XDocument.Load("../../../I18N.Test/Assets/FrenchXliff.xml");
            string nameSpace = doc.Root.GetDefaultNamespace().NamespaceName;
            XName xfile = XName.Get("file", nameSpace);
            string language = doc.Descendants(xfile).FirstOrDefault().Attribute("target-language").Value.ToString();

            XName xname = XName.Get("trans-unit", nameSpace);
            XName xtarget = XName.Get("target", nameSpace);

            string outputPath = Directory.GetCurrentDirectory();

            I18N.Format.Localizable l = new Localizable();
            Assert.IsNotNull(l);

            Boolean hasWritten = l.Write(ref doc, outputPath, language, ref prefix, ref id, ref xname, ref xtarget);

            Assert.IsTrue(hasWritten);
        }
Beispiel #2
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);
            }
        }