Exemplo n.º 1
0
		private static void LoadResources(string source)
		{
			try
			{
				string destination = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data\en-US");
				if (!Directory.Exists(destination))
				{
					Directory.CreateDirectory(destination);
				}
				dsResources = new Resources();
				LoadFiles(source, source);
				dsResources.AcceptChanges();
				string fileName = Path.Combine(destination, "Resources.xml");
				dsResources.WriteXml(fileName);
			}
			catch (Exception ex)
			{
				ShowError(ex);
			}
		}
Exemplo n.º 2
0
		private DataRow[] FindRows(string file, string key, Resources ds)
		{
			string filter = string.Format("File = '{0}' AND Key = '{1}'", file, key);
			return ds.Resource.Select(filter);
		}
Exemplo n.º 3
0
		private int ImportFile(string locale, Resources ds, string file, string baseDir)
		{
			int count = 0;
			string path = file.Substring(baseDir.Length);
			path = path.Replace(locale+".resx", "resx");
			if (path.StartsWith(Path.DirectorySeparatorChar.ToString()))
			{
				path = path.TrimStart(Path.DirectorySeparatorChar);
			}
			SetStatusBarText(string.Format("Importing {0}...", path));
			// Create a ResXResourceReader for the file.
			ResXResourceReader rsxr = new ResXResourceReader(file);

			// Create an IDictionaryEnumerator to iterate through the resources.
			IDictionaryEnumerator id = rsxr.GetEnumerator();

			// Iterate through the resources and display the contents to the console.
			foreach (DictionaryEntry d in rsxr)
			{
				string key = d.Key.ToString();
				if (d.Value != null)
				{
					string value = d.Value.ToString();
					DataRow[] rows = FindRows(path, key, ds);
					foreach (Resources.ResourceRow row in rows)
					{
						row.Value = value;
						count++;
					}
				}
			}
			//Close the reader.
			rsxr.Close();
			return count;
		}
Exemplo n.º 4
0
		private int ImportFiles(string locale, Resources ds, string sourceDir, string baseDir)
		{
			int count = 0;
			string[] dirs = Directory.GetDirectories(sourceDir);
			foreach (string dir in dirs)
			{
				count += ImportFiles(locale, ds, dir, baseDir);
				//break;
			}
			string[] files = Directory.GetFiles(sourceDir, "*.resx", SearchOption.TopDirectoryOnly);
			foreach (string file in files)
			{
				count += ImportFile(locale, ds, file, baseDir);
				//break;
			}
			return count;
		}
Exemplo n.º 5
0
		private void ImportLanguagePack()
		{
			try
			{
				string path = Path.Combine(this.DataDirectory, importedLocale);
				string sourceFile = Path.Combine(this.DataDirectory, @"en-US\Resources.xml");
				string destFile = Path.Combine(path, "Resources.xml");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				
				if (!File.Exists(destFile))
				{
					File.Copy(sourceFile, destFile);
				}
					
				ClearTmpDir();
				SetStatusBarText("Extracting language pack...");
				ZipUtils.Unzip("Tmp", importedFileName);

				Resources ds = new Resources();
				ds.ReadXml(destFile);
				int count = ImportFiles(importedLocale, ds, this.TmpDirectory, this.TmpDirectory);
				ds.AcceptChanges();
				ds.WriteXml(destFile);
				DeleteTmpDir();
				LoadLocales();
				SetCurrentLocale(importedLocale);
				FinishProgress();

				string message = string.Format("{0} record(s) imported successfully.", count);
				MessageBox.Show(this, message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			catch (Exception ex)
			{
				if (IsThreadAbortException(ex))
					return;
				throw;
			}
		}
Exemplo n.º 6
0
		private void BindResourcesGrid()
		{
			try
			{
				if (string.IsNullOrEmpty(cbSupportedLocales.Text))
				{
					grdResources.DataMember = null;
					grdResources.DataSource = null;
					return;
				}
				string localeName = null;
				DataRowView row = cbSupportedLocales.SelectedValue as DataRowView;
				if (row != null)
				{
					localeName = (string)row["Name"];
				}
				else
				{
					localeName = cbSupportedLocales.SelectedValue as string;
				}

				if (!string.IsNullOrEmpty(localeName))
				{
					dsResources = new Resources();
					string fileName = Path.Combine(this.DataDirectory, localeName + "\\resources.xml");
					dsResources.ReadXml(fileName);
					dsResources.AcceptChanges();
					grdResources.DataSource = dsResources;
					grdResources.DataMember = this.dsResources.Tables[0].TableName;
				}
			}
			catch (Exception ex)
			{
				ShowError(ex);
			}
		}