public void FindLocalizedStringsInType_RequestNamespaceForSubclass_DoNotExtractStringsForSuperclassWithDifferentNamespace() { var stringExtractor = new StringExtractor(); var localizedStrings = stringExtractor.DoExtractingWork(new[] { "L10NSharp.TestsWithDifferentNamespace" }, new BackgroundWorker { WorkerReportsProgress = true }); Assert.AreEqual(0, localizedStrings.Count()); }
static void Main(string[] args) { // Parse and check the command line arguments. if (!ParseOptions(args)) { Usage(); return; } LocalizationManager.TranslationMemoryKind = TranslationMemory.XLiff; // Load the input assemblies so that they can be scanned. List <Assembly> assemblies = new List <Assembly>(); foreach (var file in _assemblyFiles) { var asm = Assembly.LoadFile(file); if (asm != null) { assemblies.Add(asm); } } // Scan the input assemblies for localizable strings. var extractor = new StringExtractor <XLiffDocument> { ExternalAssembliesToScan = assemblies.ToArray() }; var localizedStrings = extractor.DoExtractingWork(_namespaces.ToArray(), null); // The arguments to this constructor don't really matter much as they're used internally by // L10NSharp for reasons that may not percolate out to xliff. We just need a LocalizationManagerInternal // to feed into the constructor the LocalizedStringCache that does some heavy lifting for us in // creating the XliffDocument from the newly extracted localized strings. var lm = new XLiffLocalizationManager(_fileOriginal, _fileOriginal, _fileProductVersion); var stringCache = new XLiffLocalizedStringCache(lm, false); foreach (var locInfo in localizedStrings) { stringCache.UpdateLocalizedInfo(locInfo); } // Get the newly loaded static strings (in newDoc) and the baseline XLIFF (in baseDoc). var newDoc = stringCache.XliffDocuments[kDefaultLangId]; var baseDoc = LoadBaselineAndCompare(newDoc); // Save the results to the output file, merging in data from the baseline XLIFF if one was specified. var xliffOutput = XLiffLocalizationManager.MergeXliffDocuments(newDoc, baseDoc, _verbose); xliffOutput.File.SourceLang = kDefaultLangId; xliffOutput.File.ProductVersion = !string.IsNullOrEmpty(_fileProductVersion) ? _fileProductVersion : newDoc.File.ProductVersion; xliffOutput.File.HardLineBreakReplacement = kDefaultNewlineReplacement; xliffOutput.File.AmpersandReplacement = kDefaultAmpersandReplacement; xliffOutput.File.Original = _fileOriginal; xliffOutput.File.DataType = !string.IsNullOrEmpty(_fileDatatype) ? _fileDatatype : newDoc.File.DataType; xliffOutput.Save(_xliffOutputFilename); }
static void Main(string[] args) { // Parse and check the command line arguments. if (!ParseOptions(args)) { Usage(); return; } LocalizationManager.TranslationMemoryKind = TranslationMemory.XLiff; // Load the input assemblies so that they can be scanned. List <Assembly> assemblies = new List <Assembly>(); List <string> assemblyPaths = new List <string>(); if (_glob) { foreach (var glob in _assemblyFiles) { assemblyPaths.AddRange(Directory.GetFiles(Path.GetDirectoryName(glob), Path.GetFileName(glob))); } } else { assemblyPaths = _assemblyFiles; } foreach (var file in assemblyPaths) { // Using LoadFrom to make sure we pick up other assemblies in the same directory so we don't fail // to load because of 'missing' dependencies var asm = Assembly.LoadFrom(file); assemblies.Add(asm); for (var index = 0; index < _additionalLocalizationMethodNames.Count; index++) { var methodNameSpec = _additionalLocalizationMethodNames[index]; try { var type = asm.GetType(methodNameSpec.Item1 + "." + methodNameSpec.Item2); if (type == null) { continue; } _additionalLocalizationMethods.AddRange(type .GetMethods(BindingFlags.Static | BindingFlags.Public) .Where(m => m.Name == methodNameSpec.Item3)); if (_verbose) { Console.WriteLine($"Method {methodNameSpec.Item2}.{methodNameSpec.Item3} in {asm.GetName().FullName} will be treated as a localization method."); } _additionalLocalizationMethodNames.RemoveAt(index--); } catch (Exception e) { if (_verbose) { Console.WriteLine("Error using reflection on {asm.GetName().FullName} to get type {methodNameSpec.Item2} or method {methodNameSpec.Item3}:" + e.Message); } } } } if (_verbose && _additionalLocalizationMethodNames.Any()) { Console.WriteLine("Failed to find the following additional localization methods:"); foreach (var methodNameSpec in _additionalLocalizationMethodNames) { Console.WriteLine($"{methodNameSpec.Item1}.{methodNameSpec.Item2}.{methodNameSpec.Item3}"); } } // Scan the input assemblies for localizable strings. var extractor = new StringExtractor <XLiffDocument> { ExternalAssembliesToScan = assemblies.ToArray() }; extractor.OutputErrorsToConsole = _verbose; var localizedStrings = extractor.DoExtractingWork(_additionalLocalizationMethods, _namespaces.ToArray(), null); // The arguments to this constructor don't really matter much as they're used internally by // L10NSharp for reasons that may not percolate out to xliff. We just need a LocalizationManagerInternal // to feed into the constructor the LocalizedStringCache that does some heavy lifting for us in // creating the XliffDocument from the newly extracted localized strings. var lm = new XLiffLocalizationManager(_fileOriginal, _fileOriginal, _fileProductVersion); var stringCache = new XLiffLocalizedStringCache(lm, false); foreach (var locInfo in localizedStrings) { stringCache.UpdateLocalizedInfo(locInfo); } // Get the newly loaded static strings (in newDoc) and the baseline XLIFF (in baseDoc). var newDoc = stringCache.GetDocument(kDefaultLangId); var baseDoc = LoadBaselineAndCompare(newDoc); // Save the results to the output file, merging in data from the baseline XLIFF if one was specified. var xliffOutput = XLiffLocalizationManager.MergeXliffDocuments(newDoc, baseDoc, _verbose); xliffOutput.File.SourceLang = kDefaultLangId; xliffOutput.File.ProductVersion = !string.IsNullOrEmpty(_fileProductVersion) ? _fileProductVersion : newDoc.File.ProductVersion; xliffOutput.File.HardLineBreakReplacement = kDefaultNewlineReplacement; xliffOutput.File.AmpersandReplacement = kDefaultAmpersandReplacement; xliffOutput.File.Original = _fileOriginal; xliffOutput.File.DataType = !string.IsNullOrEmpty(_fileDatatype) ? _fileDatatype : newDoc.File.DataType; xliffOutput.Save(_xliffOutputFilename); }
protected override void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var extractor = new StringExtractor <T>(); e.Result = extractor.DoExtractingWork(_namespaceBeginnings, sender as BackgroundWorker); }