private async Task <object> RetrieveTranslation(IProgress <string> progress, CancellationToken cancelToken) { LocalizationAppDomain appDomain = await StringsRetriever.CreateAppDomain(App.MainWindow.Document.PathToBinaries); var document = App.MainWindow.Document; foreach (var culture in __TranslationCultures) { if (!culture.IsSelected) { continue; } document.AddLanguage(culture.Culture); StringsRetriever retriever = new StringsRetriever(App.MainWindow.Document); foreach (var assembly in document.Assemblies) { string resourceFile = System.IO.Path.Combine( culture.Culture.CultureCode, System.IO.Path.GetFileNameWithoutExtension(assembly.Assembly.AssemblyFile) + ".resources.dll" ); string resourceFileFullPath = System.IO.Path.Combine(document.PathToBinaries, resourceFile); if (!System.IO.File.Exists(resourceFileFullPath)) { continue; } string progressString = StringUtils.String("Progress_RetrievingAssemblyTranslation", resourceFile); progress.Report(progressString); LoadedAssembly loadedAssembly = await Task.Run <LoadedAssembly>(() => { return(appDomain.LoadAssembly( resourceFileFullPath)); }); var progressReporter = new ProgressPercentageReporter(progress, progressString); var lines = await retriever.ExtractTranslationLines(loadedAssembly); lines = lines.Where(retriever.LinesFilter).ToList(); await document.ImportApi.ImportTranslationStrings( progressReporter, cancelToken, assembly.Assembly.AssemblyFile, document.AssembliesLanguage.CultureCode, culture.Culture.CultureCode, lines); } } await StringsRetriever.DisposeAppDomain(appDomain); return(null); }
public async Task <object> RetrieveAllAssemblies(IProgress <string> progress, CancellationToken cancelToken) { LocalizationAppDomain appDomain = await CreateAppDomain(__Document.PathToBinaries); List <ImportResult> results = new List <ImportResult>(); foreach (var assembly in __Document.Assemblies) { progress.Report(StringUtils.String("LoadingAssembly_0", assembly.Assembly.AssemblyFile)); LoadedAssembly loadedAssembly = await Task.Run <LoadedAssembly>(() => { return(appDomain.LoadAssembly( System.IO.Path.Combine(__Document.PathToBinaries, assembly.Assembly.DefaultResourceFile))); }); var progressString = StringUtils.String("ImportingFromAssembly_0", assembly.Assembly.AssemblyFile); var progressReporter = new ProgressPercentageReporter(progress, progressString); var lines = await ExtractTranslationLines(loadedAssembly); lines = lines.Where(LinesFilter).ToList(); ImportResult importResult = await __Document.ImportApi.ImportStrings( progressReporter, cancelToken, assembly.Assembly.AssemblyFile, lines); results.Add(importResult); } progress.Report(StringUtils.String("Import_Finishing")); await DisposeAppDomain(appDomain); __Document.UpdateTranslatedCultures(); return(results); }