/// <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); } }
public void CanWriteAndReadFrenchLanguageResourceFile() { 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.Resource r = new Resource(); Assert.IsNotNull(r); r.Write(ref doc, outputPath, language, ref prefix, ref id, ref xname, ref xtarget); ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager("Debug" + prefix + language, "../", null); var s = resourceManager.GetString("form.label.username", System.Globalization.CultureInfo.CreateSpecificCulture("fr")); }
public void CanCreateInstanceOfResourceObject() { I18N.Format.Resource r = new Resource(); Assert.IsNotNull(r); }