예제 #1
0
        void LoadTranslations(Map map)
        {
            var selectedTranslations = new Dictionary <string, string>();
            var defaultTranslations  = new Dictionary <string, string>();

            if (!Manifest.Translations.Any())
            {
                Languages = new string[0];
                return;
            }

            var yaml = Manifest.Translations.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal);

            Languages = yaml.Select(t => t.Key).ToArray();

            yaml = MiniYaml.MergeLiberal(map.TranslationDefinitions, yaml);

            foreach (var y in yaml)
            {
                if (y.Key == Game.Settings.Graphics.Language)
                {
                    selectedTranslations = y.Value.ToDictionary(my => my.Value ?? "");
                }
                else if (y.Key == Game.Settings.Graphics.DefaultLanguage)
                {
                    defaultTranslations = y.Value.ToDictionary(my => my.Value ?? "");
                }
            }

            var translations = new Dictionary <string, string>();

            foreach (var tkv in defaultTranslations.Concat(selectedTranslations))
            {
                if (translations.ContainsKey(tkv.Key))
                {
                    continue;
                }
                if (selectedTranslations.ContainsKey(tkv.Key))
                {
                    translations.Add(tkv.Key, selectedTranslations[tkv.Key]);
                }
                else
                {
                    translations.Add(tkv.Key, tkv.Value);
                }
            }

            FieldLoader.SetTranslations(translations);
        }