static void Main(string[] args) { if (args == null || args.Length < 3) { Console.WriteLine("Use this tool to generate Resx files from you'r c# project\n\nUse it like this:\n LocalizationHelper csharProjectFolder ResxOutFolder Languages[]\n\nE.G.\n LocalizationHelper MyAwesomeCSharpProject\\src MyAwesomeCSharpProject\\src\\Resources en hr rus pl"); Console.WriteLine("\n\n\nAfter you start you can start filling in the missing localization strings!"); return; } var inDir = args[0]; var outDir = args[1]; var langs = args.Skip(2).ToArray(); var a = new ProjectCompiler(inDir, outDir, false, langs); a.Start(); var UnKnowns = new List <(string lang, string key)>(KnownValues.NotKnown.ToList().OrderByDescending(i => i.Value).Select(i => i.Key)); foreach (var unKnown in UnKnowns) { foreach (var vals in KnownValues.NotKnown.ToList().OrderBy(i => i.Value)) { Console.WriteLine($"#{vals.Value} {vals.Key}"); } Console.WriteLine($"Hits: {KnownValues.Hits} Misses: {KnownValues.Misses}"); Console.WriteLine("Can you tell me how to translate this? (Press enter to skip)"); Console.Write($"{unKnown}="); var value = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(value)) { KnownValues.AddValue(unKnown.lang, unKnown.key, value); a.Start(); } } }
private void Start(string curIn, string curOut, params string[] langs) { var files = Directory.GetFiles(curIn); var seri = new XmlSerializer(typeof(root)); foreach (var file in files) { var l = new LocalizeStringScanner(file); if (l.HasLocalizer()) { foreach (var lang in langs) { var outFile = FileNameToResxName(file, curOut, lang); var names = File.Exists(outFile) ? outFile.DeSeriXML <root>() : l.AllLocalization(_findFileds).Distinct().ToList().MapToroot(); root newNames = new root(); if (File.Exists(outFile)) { newNames = l.AllLocalization(_findFileds) .Distinct() .Where(i => names.data.All(j => j.name != i && j.Generated != i)) .MapToroot(); names.data.AddRange(newNames.data); } if (names.data.Any()) { var updatedCount = 0; foreach (var name in names.data.Where(i => i.value == i.Generated)) { var newValue = KnownValues.GetValue(lang, name.name); if (newValue != name.Generated) { name.value = newValue; updatedCount++; } } Console.WriteLine($"{Path.GetRelativePath(_projectRoot, file)}: {newNames.data?.Count() ?? names.data.Count()}+ {names.data.Count()}= {updatedCount}^"); if ((newNames.data?.Count() ?? names.data.Count()) > 0 || updatedCount != 0) { Directory.CreateDirectory(curOut); //Console.WriteLine($"Writing to: {Path.GetRelativePath(_outputRoot, outFile)}"); seri.Serialize(System.Xml.XmlWriter.Create(File.Create(outFile), new System.Xml.XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true }), names); } } //Console.WriteLine($"Done with: {file}"); //Console.WriteLine(new string('-', Console.WindowWidth)); } } } foreach (var dir in Directory.GetDirectories(curIn).Where(i => i.IndexOf("node_modu") == -1)) { var newpartOfPath = dir.Split('\\', StringSplitOptions.RemoveEmptyEntries).Last(); Start(dir, Path.Combine(curOut, newpartOfPath), langs); } }
/// <summary> /// Returns list of words that are not translated or at least it's possible that they aren't translated. /// </summary> public void Start() { IterateOverAllFiles(_outputRoot, i => { var fileName = i.Split('.'); var lang = fileName[fileName.Count() - 2]; var root = i.DeSeriXML <root>(); KnownValues.ExtractNewValues(root, lang); }, i => i.Split('.').Length > 2 && i.IndexOf("resx") != -1); Start(_projectRoot, _outputRoot, _languages); }