Exemplo n.º 1
0
		public static void Build(ResourceDatabase db, string resourceDir, Action<string> debugOutput)
		{
			XDocument languageDefinition = XDocument.Load(Path.Combine(resourceDir, "languages/LanguageDefinition.xml"));
			var languageCodes = languageDefinition.Root.Elements().Select(e => e.Attribute("code").Value);
			
			foreach (LanguageTable language in db.Languages) {
				string databaseCode = language.LanguageName;
				string code = codeMap.ContainsKey(databaseCode) ? codeMap[databaseCode] : databaseCode;
				
				string filename;
				if (code == "en")
					filename = Path.Combine(resourceDir, "StringResources.resx");
				else
					filename = Path.Combine(resourceDir, "StringResources." + code + ".resx");
				if (File.Exists(filename)) {
					language.SaveAsResx(filename, code == "en");
				} else if (language.Entries.Count > 0.5 * db.Languages[0].Entries.Count) {
					debugOutput("Language " + code + " is more than 50% complete but not present in resourceDir");
				}
				
				if (language.Entries.Count > 0.75 * db.Languages[0].Entries.Count && !languageCodes.Contains(code)) {
					debugOutput("Language " + code + " is more than 75% complete but not defined in LanguageDefinition.xml");
				} else if (language.Entries.Count < 0.75 * db.Languages[0].Entries.Count && languageCodes.Contains(code)) {
					debugOutput("Language " + code + " is less than 75% complete but defined in LanguageDefinition.xml");
				}
			}
		}
Exemplo n.º 2
0
        public static ResourceDatabase Load(string databaseFile)
        {
            string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                databaseFile + ";";

            using (var myConnection = new OleDbConnection(connection)) {
                myConnection.Open();
                ResourceDatabase db = new ResourceDatabase();
                using (OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM Localization", myConnection)) {
                    using (OleDbDataReader reader = myOleDbCommand.ExecuteReader()) {
                        string[] fieldNames = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();
                        db.Languages.Add(new LanguageTable("en"));
                        foreach (string fieldName in fieldNames)
                        {
                            if (fieldName.StartsWith("lang-"))
                            {
                                db.Languages.Add(new LanguageTable(fieldName.Substring(5)));
                            }
                        }
                        while (reader.Read())
                        {
                            ResourceEntry primaryEntry = new ResourceEntry {
                                Key         = reader["ResourceName"].ToString(),
                                Description = reader["PrimaryPurpose"].ToString(),
                                Value       = reader["PrimaryResLangValue"].ToString()
                            };
                            db.Languages[0].Entries.Add(primaryEntry.Key, primaryEntry);
                            for (int i = 1; i < db.Languages.Count; i++)
                            {
                                string val = reader["lang-" + db.Languages[i].LanguageName].ToString();
                                if (!string.IsNullOrEmpty(val))
                                {
                                    ResourceEntry entry = new ResourceEntry {
                                        Key         = primaryEntry.Key,
                                        Description = primaryEntry.Description,
                                        Value       = val
                                    };
                                    db.Languages[i].Entries.Add(entry.Key, entry);
                                }
                            }
                        }
                    }
                }
                return(db);
            }
        }
Exemplo n.º 3
0
        void DownloadButtonClick(object sender, EventArgs e)
        {
            EventHandler onDownloadFinished = delegate {
                outputTextBox.Text += "\r\nLoading database...";
                Application.DoEvents();

                ResourceDatabase db = ResourceDatabase.Load("LocalizeDb_DL_Corsavy.mdb");
                outputTextBox.Text += "\r\nCreating resource files...";
                Application.DoEvents();
                BuildResourceFiles.Build(db, Path.Combine(srcDir, "../data/resources"),
                                         text => { outputTextBox.Text += "\r\n" + text; Application.DoEvents(); });

                outputTextBox.Text += "\r\nBuilding SharpDevelop...";
                RunBatch(Path.Combine(srcDir, ".."), "debugbuild.bat", null);
            };

            server.DownloadDatabase("LocalizeDb_DL_Corsavy.mdb", onDownloadFinished);
            //onDownloadFinished(null, null);
        }
Exemplo n.º 4
0
		public static ResourceDatabase Load(string databaseFile)
		{
			string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
				databaseFile + ";";
			using (var myConnection = new OleDbConnection(connection)) {
				myConnection.Open();
				ResourceDatabase db = new ResourceDatabase();
				using (OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM Localization", myConnection)) {
					using (OleDbDataReader reader = myOleDbCommand.ExecuteReader()) {
						string[] fieldNames = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();
						db.Languages.Add(new LanguageTable("en"));
						foreach (string fieldName in fieldNames) {
							if (fieldName.StartsWith("lang-"))
								db.Languages.Add(new LanguageTable(fieldName.Substring(5)));
						}
						while (reader.Read()) {
							ResourceEntry primaryEntry = new ResourceEntry {
								Key = reader["ResourceName"].ToString(),
								Description = reader["PrimaryPurpose"].ToString(),
								Value = reader["PrimaryResLangValue"].ToString()
							};
							db.Languages[0].Entries.Add(primaryEntry.Key, primaryEntry);
							for (int i = 1; i < db.Languages.Count; i++) {
								string val = reader["lang-" + db.Languages[i].LanguageName].ToString();
								if (!string.IsNullOrEmpty(val)) {
									ResourceEntry entry = new ResourceEntry {
										Key = primaryEntry.Key,
										Description = primaryEntry.Description,
										Value = val
									};
									db.Languages[i].Entries.Add(entry.Key, entry);
								}
							}
						}
					}
				}
				return db;
			}
		}
Exemplo n.º 5
0
        public static void Build(ResourceDatabase db, string resourceDir, Action <string> debugOutput)
        {
            XDocument languageDefinition = XDocument.Load(Path.Combine(resourceDir, "languages/LanguageDefinition.xml"));
            var       languageCodes      = languageDefinition.Root.Elements().Select(e => e.Attribute("code").Value);

            foreach (LanguageTable language in db.Languages)
            {
                string databaseCode = language.LanguageName;
                string code         = codeMap.ContainsKey(databaseCode) ? codeMap[databaseCode] : databaseCode;

                string filename;
                if (code == "en")
                {
                    filename = Path.Combine(resourceDir, "StringResources.resx");
                }
                else
                {
                    filename = Path.Combine(resourceDir, "StringResources." + code + ".resx");
                }
                if (File.Exists(filename))
                {
                    language.SaveAsResx(filename, code == "en");
                }
                else if (language.Entries.Count > 0.5 * db.Languages[0].Entries.Count)
                {
                    debugOutput("Language " + code + " is more than 50% complete but not present in resourceDir");
                }

                if (language.Entries.Count > 0.75 * db.Languages[0].Entries.Count && !languageCodes.Contains(code))
                {
                    debugOutput("Language " + code + " is more than 75% complete but not defined in LanguageDefinition.xml");
                }
                else if (language.Entries.Count < 0.75 * db.Languages[0].Entries.Count && languageCodes.Contains(code))
                {
                    debugOutput("Language " + code + " is less than 75% complete but defined in LanguageDefinition.xml");
                }
            }
        }