Пример #1
0
        public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form)
        {
            form.TextOutput = "Writing " + path + "...";

            Hashtable resourceEntries = new Hashtable();
            bool check = false;

            //Get existing resources
            ResXResourceReader reader = new ResXResourceReader(path);
            if (reader != null)
            {
                IDictionaryEnumerator id = reader.GetEnumerator();
                foreach (DictionaryEntry d in reader)
                {
                    if (d.Value == null)
                        resourceEntries.Add(d.Key.ToString(), "");
                    else
                        resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
                }
                reader.Close();
            }

            //Modify resources here...
            foreach (String key in data.Keys)
            {
                if (!resourceEntries.ContainsKey(key))
                {

                    String value = data[key].ToString();
                    if (value == null) value = "";

                    resourceEntries.Add(key, value);
                }
            }

            //Write the combined resource file
            ResXResourceWriter resourceWriter = new ResXResourceWriter(path);

            foreach (String key in resourceEntries.Keys)
            {
                resourceWriter.AddResource(key, resourceEntries[key]);
            }
            resourceWriter.Generate();
            resourceWriter.Close();

            //Check if entered correctly
            reader = new ResXResourceReader(path);
            if (reader != null)
            {
                foreach (DictionaryEntry d in reader)
                    foreach (String key in resourceEntries.Keys)
                    {
                        if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true;
                    }
                reader.Close();
            }

            if (check) form.TextOutput = path + " written successfully";
            else form.TextOutput = path + " not written !!";
        }
Пример #2
0
        public void WriteToFile(FileInfoCollection fileInfoCollection, Dictionary<string, string> translations, string entryKey, TranslatorForm form)
        {
            resourceEntries = new Hashtable(translations);

                foreach (var fileInfo in fileInfoCollection.FilesInfo)
                    foreach (KeyValuePair<string, string> translation in translations)
                        if (fileInfo.Name.ToLower().Contains(translation.Key.ToLower()))
                        {
                            resourceEntries = new Hashtable() {{entryKey, translation.Value}};
                            Helper.UpdateResourceFile(resourceEntries, fileInfo.FullName, form);
                        }
        }
Пример #3
0
        public void CanTranslateText()
        {
            StreamWriter file = new StreamWriter(new FileStream("settings.ini", FileMode.Create, FileAccess.Write));

            file.WriteLine("[API-Key]");
            file.WriteLine("Key=Key");
            file.Close();

            IApiTranslator API = new TranslateAPIUnderTest("host");

            TranslatorForm form = new TranslatorForm(API);

            string result = form.Translate("Test", "en", "ru");

            Assert.AreEqual(result, "Тест");

            File.Delete("settings.ini");
        }
Пример #4
0
        public void CanGetLanguages()
        {
            StreamWriter file = new StreamWriter(new FileStream("settings.ini", FileMode.Create, FileAccess.Write));

            file.WriteLine("[API-Key]");
            file.WriteLine("Key=Key");
            file.Close();

            IApiTranslator API  = new TranslateAPIUnderTest("host");
            TranslatorForm form = new TranslatorForm(API);

            Assert.AreEqual(API.Languages.Count, 3);
            Assert.AreEqual(API.Languages[0], new KeyValuePair <string, string>("en", "Английский"));
            Assert.AreEqual(API.Languages[1], new KeyValuePair <string, string>("ru", "Русский"));
            Assert.AreEqual(API.Languages[2], new KeyValuePair <string, string>("de", "Немецкий"));

            File.Delete("settings.ini");
        }
Пример #5
0
        public void CanDetectLang()
        {
            StreamWriter file = new StreamWriter(new FileStream("settings.ini", FileMode.Create, FileAccess.Write));

            file.WriteLine("[API-Key]");
            file.WriteLine("Key=Key");
            file.Close();

            IApiTranslator API = new TranslateAPIUnderTest("host");

            TranslatorForm form = new TranslatorForm(API);

            string lang = form.TryDetectLang("Привет");

            Assert.IsNotNull(lang);
            Assert.AreEqual(lang, "Русский");

            File.Delete("settings.ini");
        }
Пример #6
0
 public AnalizadorSRT(TranslatorForm A)
 {
     Formulario = A;
 }
 public void WriteToFile(FileWriter writer, Dictionary<string, string> translations, TranslatorForm form)
 {
     writer.WriteToFile(_fileInfoCollection, translations, _key, form);
 }