Exemple #1
0
        /// <summary>
        /// Searches all of the /data/*.dat files in content.ggpk for user strings that can be translated. Also fills
        /// out 'fileRecordMap' with valid datName -> FileRecord mappings.
        /// </summary>
        private void CollectTranslatableStrings()
        {
            AllDatTranslations = new Dictionary <string, DatTranslation>();
            fileRecordMap      = new Dictionary <string, FileRecord>();

            foreach (var recordOffset in content.RecordOffsets)
            {
                var record = recordOffset.Value as FileRecord;

                if (record == null || record.ContainingDirectory == null || record.DataLength == 12 || Path.GetExtension(record.Name) != ".dat")
                {
                    continue;
                }

                // Make sure parser for .dat type actually exists
                if (!RecordFactory.HasRecordInfo(record.Name))
                {
                    continue;
                }

                if (record.ContainingDirectory.Name != "Data")
                {
                    continue;
                }

                // We'll need this .dat FileRecord later on so we're storing it in a map of fileName -> FileRecord
                fileRecordMap.Add(record.Name, record);

                List <string> translatableStrings;

                try
                {
                    translatableStrings = GetTranslatableStringsFromDatFile(record);
                }
                catch (Exception ex)
                {
                    OutputLine(string.Format(Settings.Strings["CollectTranslatableStrings_FailedReading"], record.Name, ex.Message));
                    continue;
                }

                var newDatTranslation = new DatTranslation();
                newDatTranslation.DatName      = record.Name;
                newDatTranslation.Translations = new List <Translation>();

                foreach (var str in translatableStrings)
                {
                    newDatTranslation.Translations.Add(new Translation(str));
                }

                if (translatableStrings.Count > 0)
                {
                    AllDatTranslations.Add(record.Name, newDatTranslation);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves all translations to file
        /// </summary>
        public void SaveTranslationData()
        {
            int debugTranslationCount = 0;

            List <DatTranslation> datTranslations = new List <DatTranslation>();
            XmlSerializer         serializer      = new XmlSerializer(datTranslations.GetType());

            using (FileStream fs = new FileStream(settingsPath, FileMode.Create))
            {
                foreach (var datTranslationTable in AllDatTranslations)
                {
                    if (datTranslationTable.Value.Translations == null || datTranslationTable.Value.Translations.Count == 0)
                    {
                        continue;
                    }

                    DatTranslation newDatTranslation = new DatTranslation()
                    {
                        DatName      = datTranslationTable.Key,
                        Translations = (from n in datTranslationTable.Value.Translations
                                        where n.Status != Translation.TranslationStatus.Ignore
                                        select
                                        new Translation()
                        {
                            TranslatedText = n.TranslatedText.Replace(Environment.NewLine, "__BREAK__"),
                            OriginalText = n.OriginalText.Replace(Environment.NewLine, "__BREAK__"),
                        }).ToList()
                    };

                    if (newDatTranslation.Translations.Count > 0)
                    {
                        datTranslations.Add(newDatTranslation);
                        debugTranslationCount += newDatTranslation.Translations.Count;
                    }
                }

                serializer.Serialize(fs, datTranslations);
                OutputLine(String.Format(Settings.Strings["SaveTranslationData_Successful"], debugTranslationCount, settingsPath));
            }
        }
Exemple #3
0
        /// <summary>
        /// Merges user translations with master list of transleatable strings and determiens if the user
        /// translation is already applied or is invalid (possibly due to a patch).
        /// </summary>
        private void MergeUserTranslations()
        {
            Dictionary <string, DatTranslation> userDatTranslations;

            try
            {
                userDatTranslations = ReadTranslationData();
            }
            catch (Exception ex)
            {
                OutputLine(string.Format(Settings.Strings["ReloadAllData_Failed"], ex.Message));
                return;
            }

            if (userDatTranslations == null)
            {
                return;
            }

            foreach (var userTranslation in userDatTranslations)
            {
                if (!AllDatTranslations.ContainsKey(userTranslation.Key))
                {
                    AllDatTranslations.Add(userTranslation.Key, new DatTranslation());
                }

                DatTranslation currentDatTranslation = AllDatTranslations[userTranslation.Key];

                if (AllDatTranslations[userTranslation.Key].Translations == null)
                {
                    continue;
                }

                // Mapping of originalText -> Translation pairs to determine if the user translation is already applied, not yet applied, or no longer valid
                Dictionary <string, Translation> translationsByOriginalHash = AllDatTranslations[userTranslation.Key].Translations.ToDictionary(k => k.OriginalText);

                foreach (var translation in userTranslation.Value.Translations)
                {
                    if (translationsByOriginalHash.ContainsKey(translation.OriginalText))
                    {
                        translation.Status = Translation.TranslationStatus.NeedToApply;

                        translationsByOriginalHash[translation.OriginalText].Status         = translation.Status;
                        translationsByOriginalHash[translation.OriginalText].TranslatedText = translation.TranslatedText;
                        translationsByOriginalHash[translation.OriginalText].CurrentText    = translation.OriginalText;
                    }
                    else if (translationsByOriginalHash.ContainsKey(translation.TranslatedText))
                    {
                        translation.Status = Translation.TranslationStatus.AlreadyApplied;

                        translationsByOriginalHash[translation.TranslatedText].Status         = translation.Status;
                        translationsByOriginalHash[translation.TranslatedText].TranslatedText = translation.TranslatedText;
                        translationsByOriginalHash[translation.TranslatedText].CurrentText    = translation.TranslatedText;
                        translationsByOriginalHash[translation.TranslatedText].OriginalText   = translation.OriginalText;
                    }
                    else
                    {
                        translation.Status = Translation.TranslationStatus.Invalid;
                        currentDatTranslation.Translations.Add(translation);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Searches all of the /data/*.dat files in content.ggpk for user strings that can be translated. Also fills
        /// out 'fileRecordMap' with valid datName -> FileRecord mappings.
        /// </summary>
        private void CollectTranslatableStrings()
        {
            AllDatTranslations = new Dictionary<string, DatTranslation>();
            fileRecordMap = new Dictionary<string, FileRecord>();

            foreach (var recordOffset in content.RecordOffsets)
            {
                FileRecord record = recordOffset.Value as FileRecord;

                if (record == null || record.ContainingDirectory == null || Path.GetExtension(record.Name) != ".dat")
                {
                    continue;
                }

                // Make sure parser for .dat type actually exists
                if (DatFactory.GetTypeName(Path.GetFileNameWithoutExtension(record.Name)) == null)
                {
                    continue;
                }

                // We'll need this .dat FileRecord later on so we're storing it in a map of fileName -> FileRecord
                fileRecordMap.Add(record.Name, record);

                List<string> translatableStrings;

                try
                {
                    translatableStrings = GetTranslatableStringsFromDatFile(record);
                }
                catch (Exception ex)
                {
                    OutputLine(string.Format(Settings.Strings["CollectTranslatableStrings_FailedReading"], record.Name, ex.Message));
                    continue;
                }

                DatTranslation newDatTranslation = new DatTranslation();
                newDatTranslation.DatName = record.Name;
                newDatTranslation.Translations = new List<Translation>();

                foreach (string str in translatableStrings)
                {
                    newDatTranslation.Translations.Add(new Translation(str));
                }

                if (translatableStrings.Count > 0)
                {
                    AllDatTranslations.Add(record.Name, newDatTranslation);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Saves all translations to file
        /// </summary>
        public void SaveTranslationData()
        {
            int debugTranslationCount = 0;

            List<DatTranslation> datTranslations = new List<DatTranslation>();
            XmlSerializer serializer = new XmlSerializer(datTranslations.GetType());
            using (FileStream fs = new FileStream(settingsPath, FileMode.Create))
            {
                foreach (var datTranslationTable in AllDatTranslations)
                {
                    if (datTranslationTable.Value.Translations == null || datTranslationTable.Value.Translations.Count == 0)
                        continue;

                    DatTranslation newDatTranslation = new DatTranslation()
                    {
                        DatName = datTranslationTable.Key,
                        Translations = (from n in datTranslationTable.Value.Translations
                                        where n.Status != Translation.TranslationStatus.Ignore
                                        select
                                            new Translation()
                                            {
                                                TranslatedText = n.TranslatedText.Replace(Environment.NewLine, "__BREAK__"),
                                                OriginalText = n.OriginalText.Replace(Environment.NewLine, "__BREAK__"),
                                            }).ToList()
                    };

                    if (newDatTranslation.Translations.Count > 0)
                    {
                        datTranslations.Add(newDatTranslation);
                        debugTranslationCount += newDatTranslation.Translations.Count;
                    }
                }

                serializer.Serialize(fs, datTranslations);
                OutputLine(String.Format(Settings.Strings["SaveTranslationData_Successful"], debugTranslationCount, settingsPath));
            }
        }