Beispiel #1
0
    void DumpAllTexts(Text[] texts)
    {
        var length = texts.Length;

        LocalizationXmlEntry[] entries = new LocalizationXmlEntry[length];

        for (int i = 0; i < length; i++)
        {
            var content = texts[i].text;
            entries[i] = new LocalizationXmlEntry()
            {
                Key = content, Value = content
            };
        }

        LocalizationXmlRepack container = new LocalizationXmlRepack()
        {
            Entries = entries
        };

        var serializer = new XmlSerializer(typeof(LocalizationXmlRepack));
        var sceneName  = SceneManager.GetActiveScene().name;
        var fileName   = $"{Application.dataPath}\\{sceneName}Localization.xml";

        using (var stream = File.Create(fileName))
        {
            serializer.Serialize(stream, container);
        }
    }
        private void RunTestingParametrized(string cultureToRunIn, string defaultCultureToSet)
        {
            var localizationManager = new LocalizationManager(defaultCultureToSet);
            var xmlLoaderSaver      = new XmlLoaderSaver(catchAndLogExceptions: false);

            localizationManager.Request_Load += xmlLoaderSaver.Handle_LoadRequest;
            //localizationManager.Request_Save += xmlLoaderSaver.Handle_SaveRequest; //Testing that this event is indeed unavailable at localizationManager

            //Pack and save
            var originalDictionary = new Dictionary <string, string>()
            {
                { "Interactive Music Scales", "00" },
                { "Clear UI [Esc]", "01" },
                { "Save current scale [Ctrl+S]", "02" },
                { "Delete selected scale [Delete]", "03" },

                { "Cannot save the new scale while other scale is in display", "04" },
                { "Cannot save empty scale", "05" },
                { "Scale successfully saved", "06" },
                { "To delete the scale one must first select it", "07" },
                { "Cannot delete basic scale", "08" },
                { "Delete this scale? Are you sure?", "09" },
                { "Scale deleted", "10" },
            };

            var packedEntries = new List <LocalizationXmlEntry>();

            foreach (var pair in originalDictionary)
            {
                packedEntries.Add(new LocalizationXmlEntry()
                {
                    Key = pair.Key, Value = pair.Value
                });
            }

            var container = new LocalizationXmlRepack()
            {
                Entries = packedEntries.ToArray()
            };

            xmlLoaderSaver.Handle_SaveRequest($"Localization\\{cultureToRunIn}.xml", container);

            //Load and unpack
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureToRunIn);
            var loadedDictionary = localizationManager.Handle_LoadLocalizationRequest();

            //Compare
            foreach (var pair in originalDictionary)
            {
                Assert.AreEqual(originalDictionary[pair.Key], loadedDictionary[pair.Key]);
            }
        }
        public void Write_Load_Compare_Equal_NoException()
        {
            //Pack and save
            var originalDictionary = new Dictionary <string, string>()
            {
                { "apple", "яблоко" },
                { "orange", "апельсинка" },
                { "pizza", "пицца" }
            };

            var packedEntries = new List <LocalizationXmlEntry>();

            foreach (var pair in originalDictionary)
            {
                packedEntries.Add(new LocalizationXmlEntry()
                {
                    Key = pair.Key, Value = pair.Value
                });
            }

            var container = new LocalizationXmlRepack()
            {
                Entries = packedEntries.ToArray()
            };

            var xmlLoaderSaver = new XmlLoaderSaver(catchAndLogExceptions: false);

            xmlLoaderSaver.Handle_SaveRequest("Localization\\Test\\TestLocalization.xml", container);

            //Load and unpack
            container = (LocalizationXmlRepack)xmlLoaderSaver.Handle_LoadRequest("Localization\\Test\\TestLocalization.xml", typeof(LocalizationXmlRepack));

            var unpackedEntries = container.Entries;

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

            foreach (var entry in unpackedEntries)
            {
                loadedDictionary[entry.Key] = entry.Value;
            }

            //Compare
            foreach (var pair in originalDictionary)
            {
                Assert.AreEqual(originalDictionary[pair.Key], loadedDictionary[pair.Key]);
            }
        }