Пример #1
0
        private static async Task projectToResX(string projectFile)
        {
            Console.WriteLine($"Converting all localisation files in {projectFile}...");

            MSBuildLocator.RegisterDefaults();

            var workspace = MSBuildWorkspace.Create();
            var project   = await workspace.OpenProjectAsync(projectFile);

            var localisationFiles = project.Documents.Where(d => d.Folders.SequenceEqual(SyntaxTemplates.PROJECT_RELATIVE_LOCALISATION_PATH.Split('/')))
                                    .Where(d => d.Name.EndsWith(".cs"))
                                    .Where(d => Path.GetFileNameWithoutExtension(d.Name).EndsWith(SyntaxTemplates.STRINGS_FILE_SUFFIX))
                                    .ToArray();

            if (localisationFiles.Length == 0)
            {
                Console.WriteLine("No localisation files found in project.");
                return;
            }

            foreach (var file in localisationFiles)
            {
                Console.WriteLine($"Processing {file.Name}...");

                LocalisationFile localisationFile;
                using (var stream = File.OpenRead(file.FilePath))
                    localisationFile = await LocalisationFile.ReadAsync(stream);

                string resxFile = Path.Combine(Path.GetDirectoryName(file.FilePath) !, $"{localisationFile.Prefix}.resx");

                using (var fs = File.Open(resxFile, FileMode.Create, FileAccess.ReadWrite))
                    using (var resWriter = new ResXResourceWriter(fs, getResourceTypeName))
                    {
                        foreach (var member in localisationFile.Members)
                        {
                            resWriter.AddResource(member.Key, member.EnglishText);
                        }
                        resWriter.Generate();
                    }

                Console.WriteLine($"  -> {resxFile}");
            }
        }
Пример #2
0
        public async Task FileIsNotChangedAfterReSaving()
        {
            await setupLocalisation(
                new LocalisationMember("prop", "property", "property"),
                new LocalisationMember("method", "method", "method",
                                       new LocalisationParameter("int", "i")));

            IFileInfo file    = mockFs.FileInfo.FromFileName(test_file_name);
            string    initial = await mockFs.File.ReadAllTextAsync(file.FullName, CancellationToken.None);

            // Read and re-save via LocalisationFile.
            LocalisationFile localisation;

            using (var stream = file.OpenRead())
                localisation = await LocalisationFile.ReadAsync(stream);
            using (var stream = file.OpenWrite())
                await localisation.WriteAsync(stream, workspace);

            string updated = await mockFs.File.ReadAllTextAsync(file.FullName, CancellationToken.None);

            Assert.Equal(initial, updated);
        }
Пример #3
0
 private async Task <LocalisationFile> setupFile(string contents)
 {
     mockFs.AddFile(test_file_name, contents);
     using (var stream = mockFs.FileInfo.FromFileName(test_file_name).OpenRead())
         return(await LocalisationFile.ReadAsync(stream));
 }