Example #1
0
        public void WriteToFile(LanguageGenerator lg)
        {
            var targetFilePath = $"{name}.olang";

            if (File.Exists(targetFilePath))
            {
                File.Move(targetFilePath, targetFilePath + ".old");
            }
            //File.Create(targetFilePath);

            var header =
                $"{targetFilePath}\n" +
                $"Generated using Cabel\n" +
                $"seed:{lg.Seed}\n" +
                $"conf:wlen=[{lg.MinWordLength},{lg.MaxWordLength}]\n" +
                $"refs:{string.Join(", ",lg.GetReferenceNames())}\n" +
                $"vers:{lg.Version}\n";

            var content = words.Select(kvp => $"{kvp.Key}: {kvp.Value}");

            var buffer = new List <string>();

            buffer.Add(header);
            buffer.Add("\n");
            foreach (var s in content)
            {
                buffer.Add(s);
            }

            File.WriteAllLines(targetFilePath, buffer);
        }
Example #2
0
        static void Main(string[] args)
        {
            var version = Assembly.GetEntryAssembly().GetName().Version;
            var lg      = new LanguageGenerator(version, seed: new Random().Next());

            lg.AddLanguage(ReferenceLanguage.BuildFrom("lang/hebrew.txt"));
            lg.AddLanguage(ReferenceLanguage.BuildFrom("lang/chinese.txt"));
            lg.SetDictionary(WordDictionary.BuildFrom("words/wordsEn.txt"));

            Console.WriteLine("Generating...");
            var ol = lg.Generate();

            ol.WriteToFile(lg);
            Console.WriteLine("Done!");
        }