Exemplo n.º 1
0
        /// <summary>
        /// Loads LNG object from the array of strings.
        /// </summary>
        /// <param name="lines">Array of strings.</param>
        public static LNG FromText(string[] lines, bool trySwap = false)
        {
            LNG lng = new LNG();

            lng.Entries = lines.ToList();

            //trim every string to avoid extra spaces.
            for (int i = 0; i < lng.Entries.Count; i++)
            {
                lng.Entries[i] = lng.Entries[i].Split(';')[0].Trim();
            }

            if (trySwap)
            {
                string swapfile = Path.Combine(Meta.BasePath, "charswap.txt");

                if (File.Exists(swapfile))
                {
                    CharSwap swap = new CharSwap(swapfile);

                    for (int i = 0; i < lng.Entries.Count; i++)
                    {
                        lng.Entries[i] = swap.Parse(lng.Entries[i], SwapMode.ToEnglish);
                    }
                }
            }

            return(lng);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports CTR localization file to a list of strings
        /// </summary>
        /// <param name="filename">Target file name.</param>
        public void Export(string filename, bool trySwap = false)
        {
            if (trySwap)
            {
                string swapfile = Path.Combine(Meta.BasePath, "charswap.txt");

                if (File.Exists(swapfile))
                {
                    LNG      swaplng = new LNG();
                    CharSwap swap    = new CharSwap(swapfile);

                    foreach (string en in Entries)
                    {
                        swaplng.Entries.Add(swap.Parse(en, SwapMode.ToLocal));
                    }

                    swaplng.Export(filename, false);

                    filename = filename + "_original.txt";
                }
            }

            Helpers.WriteToFile(filename, ToString());
        }