Пример #1
0
        public void LoadDatFile_Test()
        {
            IEnumerable <Translation> translations =
                UnsortedDatFileService.LoadDatFile(TEST_DATA_PATH_IN, new CultureInfo("en-GB"));

            Assert.IsNotNull(translations);
            Assert.IsTrue(translations.Any());
        }
Пример #2
0
        /// <summary>
        /// Imports a DAT file from a specified location.
        /// </summary>
        /// <param name="filePath">The path to the file to import.</param>
        /// <param name="locale">The locale of the file.</param>
        /// <param name="fileType">Type of dat file to import.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static IEnumerable <Translation> Import(string filePath, CultureInfo locale,
                                                       FileType fileType = FileType.SortedGameStringFile)
        {
            switch (fileType)
            {
            case FileType.SortedGameStringFile:
                return(SortedDatFileService.LoadDatFile(filePath, locale));

            case FileType.UnsortedCreditsStringFile:
                return(UnsortedDatFileService.LoadDatFile(filePath, locale));

            default:
                throw new ArgumentOutOfRangeException(nameof(fileType), fileType,
                                                      "The file type specified is not supported.");
            }
        }
Пример #3
0
        /// <summary>
        /// Exports a list of translations to a given dat file.
        /// </summary>
        /// <param name="filePath">The file to export to. Must not already exist.</param>
        /// <param name="translations">A list of translations to write to the dat file.</param>
        /// <param name="fileType">Type of dat file to export.</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static void Export(string filePath, IEnumerable <Translation> translations,
                                  FileType fileType = FileType.SortedGameStringFile)
        {
            switch (fileType)
            {
            case FileType.SortedGameStringFile:
                SortedDatFileService.StoreDatFile(filePath, translations);
                break;

            case FileType.UnsortedCreditsStringFile:
                UnsortedDatFileService.StoreDatFile(filePath, translations);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(fileType), fileType,
                                                      "The file type specified is not supported.");
            }
        }
Пример #4
0
        public void StoreDatFile_Test()
        {
            List <Translation> translations = new List <Translation>
            {
                new Translation("TEST_KEY_01", "Test value 1.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_02", "Test value 2.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_03", "Test value 3.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_04", "Test value 4.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_05", "Test value 5.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_06", "Test value 6.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_07", "Test value 7.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_08", "Test value 8.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_09", "Test value 9.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_10", "Test value 10.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_11", "Test value 11.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_12", "Test value 12.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_13", "Test value 13.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_14", "Test value 14.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_15", "Test value 15.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_16", "Test value 16.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_17", "Test value 17.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_18", "Test value 18.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_19", "Test value 19.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_20", "Test value 20.", new CultureInfo("en-GB"))
            };

            UnsortedDatFileService.StoreDatFile(TEST_DATA_PATH_OUT, translations);
            Assert.IsTrue(File.Exists(TEST_DATA_PATH_OUT));
            byte[] b = File.ReadAllBytes(TEST_DATA_PATH_OUT);
            UnsortedDatFileBinaryFileBuilder builder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = builder.Build(b);

            Assert.IsNotNull(datFile);
            Assert.IsTrue(datFile.GetTextItemCount() == translations.Count);
            for (int i = 0; i < translations.Count; i++)
            {
                Assert.IsTrue(datFile.GetKeys()[i].CompareTo(new KeyTableRecord(translations[i].Key)) == 0);
                Assert.IsTrue(datFile.GetValues()[i].CompareTo(new ValueTableRecord(translations[i].Value)) == 0);
            }
        }