Example #1
0
        /// <summary>
        /// 将新的翻译合并到此翻译中
        /// <list type="bullet">
        ///     <item><description>目标与此翻译ID和哈希相同的条目会被忽略</description></item>
        ///     <item><description>目标ID不同但哈希于此翻译中存在的条目会使用此翻译中同哈希的第一个条目的内容</description></item>
        ///     <item><description>目标与此翻译哈希不同的条目会在此翻译中新建</description></item>
        ///     <item><description>此翻译中存在但是目标中不存在的条目不会处理</description></item>
        /// </list>
        /// </summary>
        /// <param name="source">目标翻译</param>
        public bool MergeWith(ScriptTranslation source)
        {
            var changed = false;

            foreach (var(key, content) in source._translatableStrings)
            {
                // 情况1
                if (_translatableStrings.ContainsKey(key))
                {
                    continue;
                }
                // 情况2
                var similarIds = _translatableStrings.Keys.Where(e => e << 16 == key << 16).ToArray();
                if (similarIds.Any())
                {
                    _translatableStrings.Add(key, _translatableStrings[similarIds.First()]);
                    changed = true;
                    continue;
                }
                // 情况3
                _translatableStrings.Add(key, content);
                changed = true;
            }
            return(changed);
        }
Example #2
0
        /// <summary>
        /// 删除此翻译中存在但是目标中不存在的条目
        /// </summary>
        /// <param name="baseTranslation">目标翻译</param>
        /// <returns></returns>
        public bool RemoveUnavailableTranslations(ScriptTranslation baseTranslation)
        {
            var needRemove = new List <uint>(_translatableStrings.Keys.Where(e => !baseTranslation._translatableStrings.ContainsKey(e)));

            foreach (var id in needRemove)
            {
                _translatableStrings.Remove(id);
            }
            return(needRemove.Count > 0);
        }