Beispiel #1
0
        /// <summary>Updates the game's localization database from the strings on the disk.</summary>
        /// <param name="configFilename">The file name with the localization data.</param>
        /// <param name="targetNode">
        /// The language node from database to update. It must not be a copy!
        /// </param>
        public static void UpdateLocalizationContent(string configFilename, ConfigNode targetNode)
        {
            var newNode = ConfigAccessor.GetNodeByPath(
                ConfigNode.Load(configFilename), "Localization/" + Localizer.CurrentLanguage);
            var oldTags = new HashSet <string>(targetNode.values.DistinctNames());
            var newTags = new HashSet <string>(newNode.values.DistinctNames());

            Debug.LogWarningFormat(
                "Update localization config: added={0}, deleted={1}, updated={2}, file={3}",
                newTags.Except(oldTags).Count(),
                oldTags.Except(newTags).Count(),
                newTags.Intersect(oldTags).Count(),
                configFilename);
            // Update the existing and new tags.
            newNode.values.Cast <ConfigNode.Value>().ToList()
            .ForEach(value => Localizer.Tags[value.name] = Regex.Unescape(value.value));
            // Drop the deleted tags.
            oldTags.Except(newTags).ToList()
            .ForEach(tag => Localizer.Tags.Remove(tag));
            // Update the database config.
            targetNode.values.Clear();
            newNode.values.Cast <ConfigNode.Value>().ToList()
            .ForEach(targetNode.values.Add);
        }