Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            lblStatus.Text = "Building...";
            this.Invalidate();
            Application.DoEvents();

            List<string> languageName = new List<string>();
            List<string> outputs = new List<string>();
            DataSet theData = new OdsReaderWriter().ReadOdsFile("..\\..\\..\\translations\\translations.ods");
            int rowCounter = 0;
            foreach (DataRow thisRow in theData.Tables[0].Rows)
            {
                if (rowCounter == 0)
                {
                    for (int i = 2; i < thisRow.ItemArray.Length; i++)
                    {
                        if (!String.IsNullOrEmpty(thisRow.ItemArray[i].ToString()))
                        {
                            languageName.Add(thisRow.ItemArray[i].ToString());
                            outputs.Add("");
                        }
                    }
                }
                else
                {
                    string textId;
                    if (!String.IsNullOrEmpty(thisRow.ItemArray[0].ToString()))
                    {
                        textId = thisRow.ItemArray[0].ToString();
                    }
                    else
                    {
                        continue;
                    }

                    for (int i = 2; i < thisRow.ItemArray.Length; i++)
                    {
                        if (!String.IsNullOrEmpty(thisRow.ItemArray[i].ToString()))
                        {
                            outputs[i - 2] += textId + "=" + thisRow.ItemArray[i] + Environment.NewLine;
                        }
                    }
                }
                rowCounter++;
            }
            for (int i = 0; i < outputs.Count; i++)
            {
                StreamWriter outfile = new StreamWriter("..\\..\\..\\translations\\" + languageName[i] + ".ini");
                outfile.WriteLine("# Embroidery Reader language strings file. To translate Embroidery Reader to a new");
                outfile.WriteLine("# language, copy this file to a new name and translate each string.");
                outfile.WriteLine("# If you make a new translation, please contact me! I'd love to");
                outfile.WriteLine("# include your translation with Embroidery Reader.");
                outfile.WriteLine("# The best way to contact me is through http://www.njcrawford.com/contact/.");
                outfile.Write(outputs[i]);
                outfile.Close();
                //MessageBox.Show(languageName[i] + Environment.NewLine + outputs[i]);
            }
            lblStatus.Text = "Done";
        }
	public static void ODSToDictionary(string aFileName){
		OdsReadWrite.OdsReaderWriter reader = new OdsReadWrite.OdsReaderWriter();
		System.Data.DataSet dataset = reader.ReadOdsFile(aFileName);
		System.Data.DataRow columnRow = null;		
		
		foreach(System.Data.DataTable table in dataset.Tables){
			string result = "";
			bool test = false;
			bool isDictionary = false;
			foreach(System.Data.DataRow row in table.Rows){
				string rowResult = "";
				if(!test) {
					test = true;
					if((row[0] as string).ToUpper() != "ID") break;
					columnRow = row;
					isDictionary = true;
				}
				int colId = 0;
				bool appendRow = true;
				foreach(System.Data.DataColumn column in table.Columns){
					
					if(colId == 0 && string.IsNullOrEmpty((row[column.ColumnName] as string))) {
						appendRow = false;
						break;
					}
					if(string.IsNullOrEmpty((columnRow[column.ColumnName] as string))) continue;
					
					string append = (row[column.ColumnName] as string);
					if(!string.IsNullOrEmpty(append)){
						append = append.Replace(";", "_semicolon");
						append = append.Replace("\n", @"\n");
					}
					if(rowResult == "")	rowResult = append;	
					else rowResult = rowResult + ";" + append;
					colId++;
				}
				if(appendRow){
					if(result == "") result = rowResult;
					else result = result + "\n" + rowResult;
				}
			}
			if(isDictionary){
				string fileName = dataPath + "/Resources/Dictionaries/" + table.TableName + ".txt";
				SaveToTxt(result, fileName, System.Text.Encoding.UTF8);
				Debug.Log("Saved dictionary : " + fileName);
			}
		}		
	}
	void OnGUI(){
		EditorGUILayout.BeginHorizontal();
						
		if(GUILayout.Button("Save")){
			Save();
			ShowNotification(new GUIContent("Dictionaries saved"));
		}
		
		if(GUILayout.Button("Load")){
			Load();
			ShowNotification(new GUIContent("Dictionaries loaded"));
		}
		
		if(GUILayout.Button("Add")){
			langItems.Add(new LanguageItem());
		}
										
		if(GUILayout.Button("Update Camera")){
			LangDictionaries ld = Camera.main.gameObject.GetComponent<LangDictionaries>() as LangDictionaries;
			if(ld == null) ld = Camera.main.gameObject.AddComponent<LangDictionaries>() as LangDictionaries;
			List<LanguageItem> selection = new List<LanguageItem>(from i in langItems where i.selected == true select i);
			ld.dictionaries.Clear();
			ld.langCode = langCode;
			for(int i = 0; i<selection.Count(); i++){
				string fileName = Application.dataPath + "/Resources Localization/" + selection[i].odsFileName + ".ods";
				if(System.IO.File.Exists(fileName)){
					OdsReadWrite.OdsReaderWriter reader = new OdsReadWrite.OdsReaderWriter();
					System.Data.DataSet dataset = reader.ReadOdsFile(fileName);
				
					foreach(System.Data.DataTable table in dataset.Tables){
						bool isDictionary = false;
						foreach(System.Data.DataRow row in table.Rows){
							if((row[0] as string).ToUpper() == "ID") isDictionary = true;
							else isDictionary = false;
							break;
						}
						if(isDictionary){
							ld.dictionaries.Add(new LangDictionaries.LangDictionary());
							ld.dictionaries.Last().aliasName = table.TableName;
							ld.dictionaries.Last().assetPath = "Dictionaries/" + table.TableName;
						}
					}		
				} else {
					Debug.LogError("FILE NOT EXISTS : " + fileName);	
				}
			}
			ShowNotification(new GUIContent("Camera.main dictionaries updated"));
		}
		
		langCode = (Lang.LanguageCode)EditorGUILayout.EnumPopup(langCode, GUILayout.Width(80));
		
		GUILayout.Label("Async", GUILayout.Width(40));
		async = EditorGUILayout.Toggle(async, GUILayout.Width(20));
		
		if(GUILayout.Button("Download from GoogleDocs")){
			for(int i = 0; i< langItems.Count; i++){
				if(langItems[i].selected){
					langItems[i].Download(async, ()=>{Repaint();});
				}
			}
		}
		
		
	
		EditorGUILayout.EndHorizontal();
		
		OSXOpenOffice = EditorGUILayout.TextField("OpenOffice(OSX)", OSXOpenOffice);
		WINOpenOffice = EditorGUILayout.TextField("OpenOffice(WIN)", WINOpenOffice);
		
		EditorGUILayout.BeginHorizontal();
		GUILayout.Box("Filename",GUILayout.Width(263));
		//GUILayout.Box("ODS Url",GUILayout.Width(300));
		//GUILayout.Box("Document Url",GUILayout.Width(260));
		GUILayout.Box("Public Document Key", GUILayout.Width(363));
		GUILayout.Box("",GUILayout.Width(20));
		GUILayout.Box("Last Download",GUILayout.Width(140));
		GUILayout.Box("ODS->TXT",GUILayout.Width(80));
		GUILayout.Box("Delete",GUILayout.ExpandWidth(true));
		EditorGUILayout.EndHorizontal();
		backgroundColor = GUI.backgroundColor;
		contentColor = GUI.contentColor;
		for(int i = 0; i< langItems.Count(); i++){
			langItem = langItems[i];
			EditorGUILayout.BeginHorizontal();
			GUI.backgroundColor = langItems[i].GetColor();	
			langItem.odsFileName = GUILayout.TextField(langItem.odsFileName, GUILayout.Width(200));
			if(GUILayout.Button("Open",GUILayout.Width(60))){
				string filePath = Application.dataPath + "/Resources Localization/" + langItems[i].odsFileName + ".ods";
				if(!File.Exists(filePath)){
					File.Copy(Application.dataPath + "/Foriero/Localization/Templates/Localization.ods", filePath);
					AssetDatabase.Refresh();
				} 
				if(Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX){
					System.Diagnostics.Process.Start(OSXOpenOffice, "\"" + filePath + "\"");
				} else {
					System.Diagnostics.Process.Start(WINOpenOffice, "\"" + filePath.Replace("/",@"\") + "\"");
				}
			}
			langItem.publicKey = GUILayout.TextField(langItem.publicKey, GUILayout.Width(196));
			//langItem.odsURL = GUILayout.TextField(langItem.odsURL, GUILayout.Width(196));
			if(GUILayout.Button("Download",GUILayout.Width(100))){
				langItems[i].Download(async, ()=>{Repaint();});
			}
			//langItem.documentURL = GUILayout.TextField(langItem.documentURL, GUILayout.Width(196));
			if(GUILayout.Button("Open",GUILayout.Width(60))){
				Application.OpenURL(langItem.documentURL);	
			}
			langItem.selected = EditorGUILayout.Toggle(langItem.selected,GUILayout.Width(20));
						
			GUILayout.Box(langItems[i].lastDownload, GUILayout.Width(140));
			
			if(GUILayout.Button("ODS->TXT", GUILayout.Width(80))){
				string fileNameOds = Application.dataPath + "/Resources Localization/" + langItems[i].odsFileName + ".ods"; 
				if(!File.Exists(fileNameOds)){
					File.Copy(Application.dataPath + "/Foriero/Localization/Templates/Localization.ods", fileNameOds);
					AssetDatabase.Refresh();	
				}
				ODSToDictionary(fileNameOds);
			}
			if(GUILayout.Button("Delete")){
				langItems.Remove(langItems[i]);
				break;
			}
			
			if(langItem.errorMessage != "OK") GUI.contentColor = Color.red;
			GUI.backgroundColor = backgroundColor;
			GUI.contentColor = contentColor;
			EditorGUILayout.EndHorizontal();
		}
	}
Beispiel #4
0
    public static void ODSToDictionary(string aFileName)
    {
        OdsReadWrite.OdsReaderWriter reader    = new OdsReadWrite.OdsReaderWriter();
        System.Data.DataSet          dataset   = reader.ReadOdsFile(aFileName);
        System.Data.DataRow          columnRow = null;

        foreach (System.Data.DataTable table in dataset.Tables)
        {
            string result       = "";
            bool   test         = false;
            bool   isDictionary = false;
            foreach (System.Data.DataRow row in table.Rows)
            {
                string rowResult = "";
                if (!test)
                {
                    test = true;
                    if ((row[0] as string).ToUpper() != "ID")
                    {
                        break;
                    }
                    columnRow    = row;
                    isDictionary = true;
                }
                int  colId     = 0;
                bool appendRow = true;
                foreach (System.Data.DataColumn column in table.Columns)
                {
                    if (colId == 0 && string.IsNullOrEmpty((row[column.ColumnName] as string)))
                    {
                        appendRow = false;
                        break;
                    }
                    if (string.IsNullOrEmpty((columnRow[column.ColumnName] as string)))
                    {
                        continue;
                    }

                    string append = (row[column.ColumnName] as string);
                    if (!string.IsNullOrEmpty(append))
                    {
                        append = append.Replace(";", "_semicolon");
                        append = append.Replace("\n", @"\n");
                    }
                    if (rowResult == "")
                    {
                        rowResult = append;
                    }
                    else
                    {
                        rowResult = rowResult + ";" + append;
                    }
                    colId++;
                }
                if (appendRow)
                {
                    if (result == "")
                    {
                        result = rowResult;
                    }
                    else
                    {
                        result = result + "\n" + rowResult;
                    }
                }
            }
            if (isDictionary)
            {
                string fileName = dataPath + "/Resources/Dictionaries/" + table.TableName + ".txt";
                SaveToTxt(result, fileName, System.Text.Encoding.UTF8);
                Debug.Log("Saved dictionary : " + fileName);
            }
        }
    }
Beispiel #5
0
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Save"))
        {
            Save();
            ShowNotification(new GUIContent("Dictionaries saved"));
        }

        if (GUILayout.Button("Load"))
        {
            Load();
            ShowNotification(new GUIContent("Dictionaries loaded"));
        }

        if (GUILayout.Button("Add"))
        {
            langItems.Add(new LanguageItem());
        }

        if (GUILayout.Button("Update Camera"))
        {
            LangDictionaries ld = Camera.main.gameObject.GetComponent <LangDictionaries>() as LangDictionaries;
            if (ld == null)
            {
                ld = Camera.main.gameObject.AddComponent <LangDictionaries>() as LangDictionaries;
            }
            List <LanguageItem> selection = new List <LanguageItem>(from i in langItems where i.selected == true select i);
            ld.dictionaries.Clear();
            ld.langCode = langCode;
            for (int i = 0; i < selection.Count(); i++)
            {
                string fileName = Application.dataPath + "/Resources Localization/" + selection[i].odsFileName + ".ods";
                if (System.IO.File.Exists(fileName))
                {
                    OdsReadWrite.OdsReaderWriter reader  = new OdsReadWrite.OdsReaderWriter();
                    System.Data.DataSet          dataset = reader.ReadOdsFile(fileName);

                    foreach (System.Data.DataTable table in dataset.Tables)
                    {
                        bool isDictionary = false;
                        foreach (System.Data.DataRow row in table.Rows)
                        {
                            if ((row[0] as string).ToUpper() == "ID")
                            {
                                isDictionary = true;
                            }
                            else
                            {
                                isDictionary = false;
                            }
                            break;
                        }
                        if (isDictionary)
                        {
                            ld.dictionaries.Add(new LangDictionaries.LangDictionary());
                            ld.dictionaries.Last().aliasName = table.TableName;
                            ld.dictionaries.Last().assetPath = "Dictionaries/" + table.TableName;
                        }
                    }
                }
                else
                {
                    Debug.LogError("FILE NOT EXISTS : " + fileName);
                }
            }
            ShowNotification(new GUIContent("Camera.main dictionaries updated"));
        }

        langCode = (Lang.LanguageCode)EditorGUILayout.EnumPopup(langCode, GUILayout.Width(80));

        GUILayout.Label("Async", GUILayout.Width(40));
        async = EditorGUILayout.Toggle(async, GUILayout.Width(20));

        if (GUILayout.Button("Download from GoogleDocs"))
        {
            for (int i = 0; i < langItems.Count; i++)
            {
                if (langItems[i].selected)
                {
                    langItems[i].Download(async, () => { Repaint(); });
                }
            }
        }



        EditorGUILayout.EndHorizontal();

        OSXOpenOffice = EditorGUILayout.TextField("OpenOffice(OSX)", OSXOpenOffice);
        WINOpenOffice = EditorGUILayout.TextField("OpenOffice(WIN)", WINOpenOffice);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Box("Filename", GUILayout.Width(263));
        //GUILayout.Box("ODS Url",GUILayout.Width(300));
        //GUILayout.Box("Document Url",GUILayout.Width(260));
        GUILayout.Box("Public Document Key", GUILayout.Width(363));
        GUILayout.Box("", GUILayout.Width(20));
        GUILayout.Box("Last Download", GUILayout.Width(140));
        GUILayout.Box("ODS->TXT", GUILayout.Width(80));
        GUILayout.Box("Delete", GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();
        backgroundColor = GUI.backgroundColor;
        contentColor    = GUI.contentColor;
        for (int i = 0; i < langItems.Count(); i++)
        {
            langItem = langItems[i];
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor  = langItems[i].GetColor();
            langItem.odsFileName = GUILayout.TextField(langItem.odsFileName, GUILayout.Width(200));
            if (GUILayout.Button("Open", GUILayout.Width(60)))
            {
                string filePath = Application.dataPath + "/Resources Localization/" + langItems[i].odsFileName + ".ods";
                if (!File.Exists(filePath))
                {
                    File.Copy(Application.dataPath + "/Foriero/Localization/Templates/Localization.ods", filePath);
                    AssetDatabase.Refresh();
                }
                if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
                {
                    System.Diagnostics.Process.Start(OSXOpenOffice, "\"" + filePath + "\"");
                }
                else
                {
                    System.Diagnostics.Process.Start(WINOpenOffice, "\"" + filePath.Replace("/", @"\") + "\"");
                }
            }
            langItem.publicKey = GUILayout.TextField(langItem.publicKey, GUILayout.Width(196));
            //langItem.odsURL = GUILayout.TextField(langItem.odsURL, GUILayout.Width(196));
            if (GUILayout.Button("Download", GUILayout.Width(100)))
            {
                langItems[i].Download(async, () => { Repaint(); });
            }
            //langItem.documentURL = GUILayout.TextField(langItem.documentURL, GUILayout.Width(196));
            if (GUILayout.Button("Open", GUILayout.Width(60)))
            {
                Application.OpenURL(langItem.documentURL);
            }
            langItem.selected = EditorGUILayout.Toggle(langItem.selected, GUILayout.Width(20));

            GUILayout.Box(langItems[i].lastDownload, GUILayout.Width(140));

            if (GUILayout.Button("ODS->TXT", GUILayout.Width(80)))
            {
                string fileNameOds = Application.dataPath + "/Resources Localization/" + langItems[i].odsFileName + ".ods";
                if (!File.Exists(fileNameOds))
                {
                    File.Copy(Application.dataPath + "/Foriero/Localization/Templates/Localization.ods", fileNameOds);
                    AssetDatabase.Refresh();
                }
                ODSToDictionary(fileNameOds);
            }
            if (GUILayout.Button("Delete"))
            {
                langItems.Remove(langItems[i]);
                break;
            }

            if (langItem.errorMessage != "OK")
            {
                GUI.contentColor = Color.red;
            }
            GUI.backgroundColor = backgroundColor;
            GUI.contentColor    = contentColor;
            EditorGUILayout.EndHorizontal();
        }
    }