Exemplo n.º 1
0
        /// <summary>
        /// Lets you save a translation to a file.
        /// </summary>
        /// <param name="translation">The translation</param>
        /// <param name="path">The file path</param>
        public static void Save(ResourceBundle translation, string path)
        {
            var lines = translation.Entries.Select(pair => $"{pair.Key} = {pair.Value}").ToList();

            lines.Sort((s, s1) => string.Compare(s, s1, StringComparison.OrdinalIgnoreCase));
            File.WriteAllLines(path, lines);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a translation from a file.
        /// </summary>
        /// <param name="filePath">The file</param>
        /// <returns>The translation</returns>
        public static ResourceBundle Parse(string filePath)
        {
            var translation = new ResourceBundle();

            var lines = File.ReadAllLines(filePath);
            foreach (var line in lines)
            {
                var pair = line.Split('=');
                translation.Entries.Add(pair[0].Trim(), pair[1].Trim());
            }

            return translation;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a translation from a file.
        /// </summary>
        /// <param name="filePath">The file</param>
        /// <returns>The translation</returns>
        public static ResourceBundle Parse(string filePath)
        {
            var translation = new ResourceBundle();

            var lines = File.ReadAllLines(filePath);

            foreach (var line in lines)
            {
                var pair = line.Split('=');
                translation.Entries.Add(pair[0].Trim(), pair[1].Trim());
            }

            return(translation);
        }
Exemplo n.º 4
0
 public static void TranslateAll()
 {
     if (string.IsNullOrWhiteSpace(BasePath) || string.IsNullOrWhiteSpace(BundleName))
     {
         throw new Exception("Can't translate anything if you haven't set the Base Path or Bundle Names");
     }
     var referenceBundle = ResourceBundle.Parse("english_reference.properties");
     _englishBundle = ResourceBundle.Parse(BasePath + "\\" + BundleName + "_en_EN.properties");
     Console.WriteLine("Finished Loading Reference Files");
     _differentKeys = _englishBundle.DifferentKeys(referenceBundle);
     _missingKeys = referenceBundle.MissingKeys(_englishBundle);
     Console.WriteLine("Translating Normal Languages\n----------------------------------");
     TranslateLanguages();
     Console.WriteLine("\nTranslating Silly Languages\n----------------------------------");
     TranslateSillyLanguages();
     ResourceBundle.Save(_englishBundle, "english_reference.properties");
 }
Exemplo n.º 5
0
        public static void TranslateAll()
        {
            if (string.IsNullOrWhiteSpace(BasePath) || string.IsNullOrWhiteSpace(BundleName))
            {
                throw new Exception("Can't translate anything if you haven't set the Base Path or Bundle Names");
            }
            var referenceBundle = ResourceBundle.Parse("english_reference.properties");

            _englishBundle = ResourceBundle.Parse(BasePath + "\\" + BundleName + "_en_EN.properties");
            Console.WriteLine("Finished Loading Reference Files");
            _differentKeys = _englishBundle.DifferentKeys(referenceBundle);
            _missingKeys   = referenceBundle.MissingKeys(_englishBundle);
            Console.WriteLine("Translating Normal Languages\n----------------------------------");
            TranslateLanguages();
            Console.WriteLine("\nTranslating Silly Languages\n----------------------------------");
            TranslateSillyLanguages();
            ResourceBundle.Save(_englishBundle, "english_reference.properties");
        }
Exemplo n.º 6
0
        private static void TranslateSillyLanguages()
        {
            var completed = 0;

            foreach (var language in SillyLanguages.Language)
            {
                Console.WriteLine("Starting " + language.Key);
                var            keysToTranslate = _differentKeys.Concat(_missingKeys);
                ResourceBundle oldBundle;
                try
                {
                    oldBundle = ResourceBundle.Parse(PathGenerator(language.Value));
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("No properties file found for language " + language.Key);
                    keysToTranslate = _englishBundle.Entries.Keys;
                    oldBundle       = new ResourceBundle();
                }
                var i           = 0.0;
                var toTranslate = keysToTranslate as string[] ?? keysToTranslate.ToArray();
                var length      = toTranslate.Count();

                foreach (var key in toTranslate)
                {
                    Console.Write($"\r{Math.Round(i / length * 100, 2)}% Complete,   \t" +
                                  $"{Math.Round(((i / length + completed) / SillyLanguages.Language.Count) * 100, 2)}% Overall            ");
                    var englishWords = _englishBundle[key];
                    var translated   = language.Value.Translate(englishWords);
                    translated     = Regex.Replace(translated, @"[^\x00-\x7F]", c => $@"\u{(int)c.Value[0]:x4}");
                    oldBundle[key] = translated;
                    i++;
                }
                Console.Write("\r100% Complete                ");
                ResourceBundle.Save(oldBundle, PathGenerator(language.Value));
                Console.WriteLine("\nFinished " + language.Key);
                completed++;
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Lets you save a translation to a file.
 /// </summary>
 /// <param name="translation">The translation</param>
 /// <param name="path">The file path</param>
 public static void Save(ResourceBundle translation, string path)
 {
     var lines = translation.Entries.Select(pair => $"{pair.Key} = {pair.Value}").ToList();
     lines.Sort((s, s1) => string.Compare(s, s1, StringComparison.OrdinalIgnoreCase));
     File.WriteAllLines(path, lines);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Gets all the keys that are missing from this translation,
 /// given a master translation.
 /// </summary>
 /// <param name="master">The master translation</param>
 public IEnumerable<string> MissingKeys(ResourceBundle master)
 {
     return (from key in master.Entries.Keys where !Entries.ContainsKey(key) select key);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Gets all the keys that have changed. This method should be called on your new
 /// set of keys. new.DifferentKeys(old) and will give you a list of the keys that have changed.
 /// </summary>
 /// <param name="old">The old set of keys</param>
 /// <returns>The changed keys (all if on a different language)</returns>
 public IEnumerable<string> DifferentKeys(ResourceBundle old)
 {
     return from key in Entries.Keys where !old.Entries.ContainsKey(key) || this[key] != old[key] select key;
 }
Exemplo n.º 10
0
        private static void TranslateLanguages()
        {
            var completed = 0;
            foreach (var language in Languages.Language)
            {
                Console.WriteLine("Starting " + language.Key);
                var defaultCode = language.Value.DefaultCode()[0];
                var defaultLanguage = language.Value.DefaultCode()[1];
                var keysToTranslate = _differentKeys.Concat(_missingKeys);
                ResourceBundle oldBundle;
                try
                {
                    oldBundle = ResourceBundle.Parse(PathGenerator(language.Value));
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("No properties file found for language " + language.Key);
                    keysToTranslate = _englishBundle.Entries.Keys;
                    oldBundle = new ResourceBundle();
                }
                var i = 0.0;
                var toTranslate = keysToTranslate as string[] ?? keysToTranslate.ToArray();
                var length = toTranslate.Count();

                foreach (var key in toTranslate)
                {
                    var percent = i/length;
                    Console.Write($"\r{Math.Round(percent * 100, 2)}% Complete,   \t" +
                                  $"{Math.Round(((percent + completed) / Languages.Language.Count) * 100, 2)}% Overall      ");
                    var englishWords = _englishBundle[key].Split('\n');
                    var translated = new string[englishWords.Length];
                    var j = 0;
                    foreach (var englishWord in englishWords)
                    {
                        if (defaultLanguage.Equals("Google"))
                        {
                            var tempTranslated = GoogleTranslator.Translate(englishWord, defaultCode);
                            if (tempTranslated.Equals(englishWord))
                            {
                                tempTranslated = BingTranslator.Translate(englishWord, language.Value.Bing);
                            }
                            translated[j] = tempTranslated;
                        }
                        else
                        {
                            translated[j] = BingTranslator.Translate(englishWord, defaultCode);
                        }
                        i++;
                        translated[j] = Regex.Replace(translated[j], @"[^\x00-\x7F]", c => $@"\u{(int)c.Value[0]:x4}");
                        translated[j] = Regex.Replace(translated[j], @"\\$", c => @"");
                    }

                    var result = string.Join("\n", translated);
                    oldBundle[key] = result;
                    i++;
                }
                Console.Write("\r100% Complete    \t                ");
                ResourceBundle.Save(oldBundle, PathGenerator(language.Value));
                Console.WriteLine("\nFinished " + language.Key);
                completed++;
            }
        }
Exemplo n.º 11
0
        private static void TranslateSillyLanguages()
        {
            var completed = 0;
            foreach (var language in SillyLanguages.Language)
            {
                Console.WriteLine("Starting " + language.Key);
                var keysToTranslate = _differentKeys.Concat(_missingKeys);
                ResourceBundle oldBundle;
                try
                {
                    oldBundle = ResourceBundle.Parse(PathGenerator(language.Value));
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("No properties file found for language " + language.Key);
                    keysToTranslate = _englishBundle.Entries.Keys;
                    oldBundle = new ResourceBundle();
                }
                var i = 0.0;
                var toTranslate = keysToTranslate as string[] ?? keysToTranslate.ToArray();
                var length = toTranslate.Count();

                foreach (var key in toTranslate)
                {
                    Console.Write($"\r{Math.Round(i / length * 100, 2)}% Complete,   \t" +
                                  $"{Math.Round(((i / length + completed) / SillyLanguages.Language.Count) * 100, 2)}% Overall            ");
                    var englishWords = _englishBundle[key];
                    var translated = language.Value.Translate(englishWords);
                    translated = Regex.Replace(translated, @"[^\x00-\x7F]", c => $@"\u{(int)c.Value[0]:x4}");
                    oldBundle[key] = translated;
                    i++;
                }
                Console.Write("\r100% Complete                ");
                ResourceBundle.Save(oldBundle, PathGenerator(language.Value));
                Console.WriteLine("\nFinished " + language.Key);
                completed++;
            }
        }
Exemplo n.º 12
0
        private static void TranslateLanguages()
        {
            var completed = 0;

            foreach (var language in Languages.Language)
            {
                Console.WriteLine("Starting " + language.Key);
                var            defaultCode     = language.Value.DefaultCode()[0];
                var            defaultLanguage = language.Value.DefaultCode()[1];
                var            keysToTranslate = _differentKeys.Concat(_missingKeys);
                ResourceBundle oldBundle;
                try
                {
                    oldBundle = ResourceBundle.Parse(PathGenerator(language.Value));
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("No properties file found for language " + language.Key);
                    keysToTranslate = _englishBundle.Entries.Keys;
                    oldBundle       = new ResourceBundle();
                }
                var i           = 0.0;
                var toTranslate = keysToTranslate as string[] ?? keysToTranslate.ToArray();
                var length      = toTranslate.Count();

                foreach (var key in toTranslate)
                {
                    var percent = i / length;
                    Console.Write($"\r{Math.Round(percent * 100, 2)}% Complete,   \t" +
                                  $"{Math.Round(((percent + completed) / Languages.Language.Count) * 100, 2)}% Overall      ");
                    var englishWords = _englishBundle[key].Split('\n');
                    var translated   = new string[englishWords.Length];
                    var j            = 0;
                    foreach (var englishWord in englishWords)
                    {
                        if (defaultLanguage.Equals("Google"))
                        {
                            var tempTranslated = GoogleTranslator.Translate(englishWord, defaultCode);
                            if (tempTranslated.Equals(englishWord))
                            {
                                tempTranslated = BingTranslator.Translate(englishWord, language.Value.Bing);
                            }
                            translated[j] = tempTranslated;
                        }
                        else
                        {
                            translated[j] = BingTranslator.Translate(englishWord, defaultCode);
                        }
                        i++;
                        translated[j] = Regex.Replace(translated[j], @"[^\x00-\x7F]", c => $@"\u{(int)c.Value[0]:x4}");
                        translated[j] = Regex.Replace(translated[j], @"\\$", c => @"");
                    }

                    var result = string.Join("\n", translated);
                    oldBundle[key] = result;
                    i++;
                }
                Console.Write("\r100% Complete    \t                ");
                ResourceBundle.Save(oldBundle, PathGenerator(language.Value));
                Console.WriteLine("\nFinished " + language.Key);
                completed++;
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Gets all the keys that have changed. This method should be called on your new
 /// set of keys. new.DifferentKeys(old) and will give you a list of the keys that have changed.
 /// </summary>
 /// <param name="old">The old set of keys</param>
 /// <returns>The changed keys (all if on a different language)</returns>
 public IEnumerable <string> DifferentKeys(ResourceBundle old)
 {
     return(from key in Entries.Keys where !old.Entries.ContainsKey(key) || this[key] != old[key] select key);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Gets all the keys that are missing from this translation,
 /// given a master translation.
 /// </summary>
 /// <param name="master">The master translation</param>
 public IEnumerable <string> MissingKeys(ResourceBundle master)
 {
     return(from key in master.Entries.Keys where !Entries.ContainsKey(key) select key);
 }