Browse Source

add import for resource files in StringResourceTool

pull/30/head
Siegfried Pammer 13 years ago
parent
commit
a260b93579
  1. 370
      src/Tools/StringResourceTool/MainForm.cs
  2. 6
      src/Tools/StringResourceTool/StringResourceTool.csproj
  3. 31
      src/Tools/StringResourceTool/TranslationServer.cs

370
src/Tools/StringResourceTool/MainForm.cs

@ -11,9 +11,11 @@ using System.Diagnostics; @@ -11,9 +11,11 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Resources;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -34,6 +36,58 @@ namespace StringResourceTool @@ -34,6 +36,58 @@ namespace StringResourceTool
}
savePasswordCheckBox.Checked = true;
} catch {}
Dictionary<string, string> languages = new Dictionary<string, string>() {
{ "cz", "Czech" },
{ "nl", "Dutch" },
{ "fr", "French" },
{ "de", "German" },
{ "it", "Italian" },
{ "pt", "Portuguese" },
{ "es", "Spanish" },
{ "se", "Swedish" },
{ "goisern", "Goiserisch" },
{ "ru", "Russian" },
{ "br", "Brazilian Portuguese" },
{ "pl", "Polish" },
{ "jp", "Japanese" },
{ "th", "Thai" },
{ "kr", "Korean" },
{ "dk", "Danish" },
{ "hu", "Hungarian" },
{ "ro", "Romanian" },
{ "cn-gb", "Chinese Simplified" },
{ "cn-big", "Chinese Traditional" },
{ "ca", "Catalan" },
{ "bg", "Bulgarian" },
{ "urdu", "Urdu" },
{ "be", "Belarusian" },
{ "el", "Greek" },
{ "tr", "Turkish" },
{ "sk", "Slovak" },
{ "lt", "Lithuanian" },
{ "he", "Hebrew" },
{ "sl", "Slovenian" },
{ "es-mx", "Spanish (Mexico)" },
{ "af", "Afrikaans" },
{ "vi", "Vietnamese" },
{ "ar", "Arabic" },
{ "no", "Norwegian" },
{ "fa", "Persian" },
{ "sr", "Serbian" },
{ "fi", "Finnish" },
{ "hr", "Croatian" },
{ "id", "Indonesian" }
};
// Clear the combobox
comboBox1.DataSource = null;
comboBox1.Items.Clear();
// Bind the combobox
comboBox1.DataSource = new BindingSource(languages, null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
}
[STAThread]
@ -70,155 +124,233 @@ namespace StringResourceTool @@ -70,155 +124,233 @@ namespace StringResourceTool
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.deleteStringsButton = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.savePasswordCheckBox = new System.Windows.Forms.CheckBox();
this.button3 = new System.Windows.Forms.Button();
this.passwordTextBox = new System.Windows.Forms.TextBox();
this.userNameTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.outputTextBox = new System.Windows.Forms.TextBox();
this.button5 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// MainForm
// groupBox1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(621, 399);
groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.deleteStringsButton);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.savePasswordCheckBox);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.passwordTextBox);
this.groupBox1.Controls.Add(this.userNameTextBox);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(597, 100);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Translation server";
//
// groupBox1
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"cz\">Czech</option>",
"<option value=\"nl\">Dutch</option>",
"<option value=\"fr\">French</option>",
"<option selected=\"\" value=\"de\">German</option>",
"<option value=\"it\">Italian</option>",
"<option value=\"pt\">Portuguese</option>",
"<option value=\"es\">Spanish</option>",
"<option value=\"se\">Swedish</option>",
"<option value=\"goisern\">Goiserisch</option>",
"<option value=\"ru\">Russian</option>",
"<option value=\"br\">Brazilian Portuguese</option>",
"<option value=\"pl\">Polish</option>",
"<option value=\"jp\">Japanese</option>",
"<option value=\"th\">Thai</option>",
"<option value=\"kr\">Korean</option>",
"<option value=\"dk\">Danish</option>",
"<option value=\"hu\">Hungarian</option>",
"<option value=\"ro\">Romanian</option>",
"<option value=\"cn-gb\">Chinese Simplified</option>",
"<option value=\"cn-big\">Chinese Traditional</option>",
"<option value=\"ca\">Catalan</option>",
"<option value=\"bg\">Bulgarian</option>",
"<option value=\"urdu\">Urdu</option>",
"<option value=\"be\">Belarusian</option>",
"<option value=\"el\">Greek</option>",
"<option value=\"tr\">Turkish</option>",
"<option value=\"sk\">Slovak</option>",
"<option value=\"lt\">Lithuanian</option>",
"<option value=\"he\">Hebrew</option>",
"<option value=\"sl\">Slovenian</option>",
"<option value=\"es-mx\">Spanish (Mexico)</option>",
"<option value=\"af\">Afrikaans</option>",
"<option value=\"vi\">Vietnamese</option>",
"<option value=\"ar\">Arabic</option>",
"<option value=\"no\">Norwegian</option>",
"<option value=\"fa\">Persian</option>",
"<option value=\"sr\">Serbian</option>",
"<option value=\"fi\">Finnish</option>",
"<option value=\"hr\">Croatian</option>",
"<option value=\"id\">Indonesian </option>"});
this.comboBox1.Location = new System.Drawing.Point(76, 65);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 9;
//
deleteStringsButton = new System.Windows.Forms.Button();
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 68);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(58, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Language:";
//
// deleteStringsButton
//
deleteStringsButton.Enabled = false;
deleteStringsButton.Location = new System.Drawing.Point(411, 20);
deleteStringsButton.Name = "deleteStringsButton";
deleteStringsButton.Size = new System.Drawing.Size(144, 23);
deleteStringsButton.TabIndex = 7;
deleteStringsButton.Text = "Delete resource strings";
deleteStringsButton.Click += new System.EventHandler(this.DeleteStringsButtonClick);
button4 = new System.Windows.Forms.Button();
this.deleteStringsButton.Enabled = false;
this.deleteStringsButton.Location = new System.Drawing.Point(411, 20);
this.deleteStringsButton.Name = "deleteStringsButton";
this.deleteStringsButton.Size = new System.Drawing.Size(144, 23);
this.deleteStringsButton.TabIndex = 7;
this.deleteStringsButton.Text = "Delete resource strings";
this.deleteStringsButton.Click += new System.EventHandler(this.DeleteStringsButtonClick);
//
// button4
//
button4.Enabled = false;
button4.Location = new System.Drawing.Point(292, 20);
button4.Name = "button4";
button4.Size = new System.Drawing.Size(113, 23);
button4.TabIndex = 6;
button4.Text = "Download database";
button4.Click += new System.EventHandler(this.DownloadButtonClick);
savePasswordCheckBox = new System.Windows.Forms.CheckBox();
this.button4.Enabled = false;
this.button4.Location = new System.Drawing.Point(292, 20);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(113, 23);
this.button4.TabIndex = 6;
this.button4.Text = "Download database";
this.button4.Click += new System.EventHandler(this.DownloadButtonClick);
//
// savePasswordCheckBox
//
savePasswordCheckBox.Location = new System.Drawing.Point(182, 44);
savePasswordCheckBox.Name = "savePasswordCheckBox";
savePasswordCheckBox.Size = new System.Drawing.Size(104, 24);
savePasswordCheckBox.TabIndex = 5;
savePasswordCheckBox.Text = "Save password";
button3 = new System.Windows.Forms.Button();
this.savePasswordCheckBox.Location = new System.Drawing.Point(182, 44);
this.savePasswordCheckBox.Name = "savePasswordCheckBox";
this.savePasswordCheckBox.Size = new System.Drawing.Size(104, 24);
this.savePasswordCheckBox.TabIndex = 5;
this.savePasswordCheckBox.Text = "Save password";
//
// button3
//
button3.Location = new System.Drawing.Point(182, 20);
button3.Name = "button3";
button3.Size = new System.Drawing.Size(75, 23);
button3.TabIndex = 4;
button3.Text = "Login";
button3.Click += new System.EventHandler(this.Button3Click);
passwordTextBox = new System.Windows.Forms.TextBox();
this.button3.Location = new System.Drawing.Point(182, 20);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 4;
this.button3.Text = "Login";
this.button3.Click += new System.EventHandler(this.Button3Click);
//
// passwordTextBox
//
passwordTextBox.Location = new System.Drawing.Point(76, 42);
passwordTextBox.Name = "passwordTextBox";
passwordTextBox.PasswordChar = '●';
passwordTextBox.Size = new System.Drawing.Size(100, 21);
passwordTextBox.TabIndex = 3;
passwordTextBox.UseSystemPasswordChar = true;
userNameTextBox = new System.Windows.Forms.TextBox();
this.passwordTextBox.Location = new System.Drawing.Point(76, 42);
this.passwordTextBox.Name = "passwordTextBox";
this.passwordTextBox.PasswordChar = '●';
this.passwordTextBox.Size = new System.Drawing.Size(100, 20);
this.passwordTextBox.TabIndex = 3;
this.passwordTextBox.UseSystemPasswordChar = true;
//
// userNameTextBox
//
userNameTextBox.Location = new System.Drawing.Point(76, 19);
userNameTextBox.Name = "userNameTextBox";
userNameTextBox.Size = new System.Drawing.Size(100, 21);
userNameTextBox.TabIndex = 1;
label2 = new System.Windows.Forms.Label();
this.userNameTextBox.Location = new System.Drawing.Point(76, 19);
this.userNameTextBox.Name = "userNameTextBox";
this.userNameTextBox.Size = new System.Drawing.Size(100, 20);
this.userNameTextBox.TabIndex = 1;
//
// label2
//
label2.Location = new System.Drawing.Point(6, 40);
label2.Name = "label2";
label2.Size = new System.Drawing.Size(64, 23);
label2.TabIndex = 2;
label2.Text = "Password:";
label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
label1 = new System.Windows.Forms.Label();
this.label2.Location = new System.Drawing.Point(6, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Password:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label1
//
label1.Location = new System.Drawing.Point(6, 17);
label1.Name = "label1";
label1.Size = new System.Drawing.Size(64, 23);
label1.TabIndex = 0;
label1.Text = "Username:";
label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
groupBox1.Controls.Add(deleteStringsButton);
groupBox1.Controls.Add(button4);
groupBox1.Controls.Add(savePasswordCheckBox);
groupBox1.Controls.Add(button3);
groupBox1.Controls.Add(passwordTextBox);
groupBox1.Controls.Add(userNameTextBox);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new System.Drawing.Point(12, 12);
groupBox1.Name = "groupBox1";
groupBox1.Size = new System.Drawing.Size(597, 74);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Translation server";
groupBox1.SuspendLayout();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
button2 = new System.Windows.Forms.Button();
this.label1.Location = new System.Drawing.Point(6, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Username:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// button2
//
button2.Location = new System.Drawing.Point(142, 92);
button2.Name = "button2";
button2.Size = new System.Drawing.Size(124, 23);
button2.TabIndex = 2;
button2.Text = "Find missing strings";
button2.Click += new System.EventHandler(this.Button2Click);
button1 = new System.Windows.Forms.Button();
this.button2.Location = new System.Drawing.Point(141, 118);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(124, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Find missing strings";
this.button2.Click += new System.EventHandler(this.Button2Click);
//
// button1
//
button1.Location = new System.Drawing.Point(12, 91);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(124, 23);
button1.TabIndex = 1;
button1.Text = "Find unused strings";
button1.Click += new System.EventHandler(this.Button1Click);
outputTextBox = new System.Windows.Forms.TextBox();
this.button1.Location = new System.Drawing.Point(11, 118);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(124, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Find unused strings";
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// outputTextBox
//
outputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
outputTextBox.Location = new System.Drawing.Point(12, 120);
outputTextBox.Multiline = true;
outputTextBox.Name = "outputTextBox";
outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
outputTextBox.Size = new System.Drawing.Size(597, 267);
outputTextBox.TabIndex = 3;
this.Controls.Add(groupBox1);
this.Controls.Add(button2);
this.Controls.Add(button1);
this.Controls.Add(outputTextBox);
this.outputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.outputTextBox.Location = new System.Drawing.Point(12, 147);
this.outputTextBox.Multiline = true;
this.outputTextBox.Name = "outputTextBox";
this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.outputTextBox.Size = new System.Drawing.Size(597, 309);
this.outputTextBox.TabIndex = 3;
//
// button5
//
this.button5.Location = new System.Drawing.Point(271, 118);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(280, 23);
this.button5.TabIndex = 4;
this.button5.Text = "Upload resources (check language! dangerous!)";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.Button5Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(621, 468);
this.Controls.Add(this.button5);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.outputTextBox);
this.Name = "MainForm";
this.Text = "StringResourceTool";
this.SuspendLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button deleteStringsButton;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.CheckBox savePasswordCheckBox;
@ -406,5 +538,29 @@ namespace StringResourceTool @@ -406,5 +538,29 @@ namespace StringResourceTool
server.DeleteResourceStrings(list.ToArray());
}
}
void Button5Click(object sender, EventArgs e)
{
server.SetLanguage(comboBox1.SelectedValue.ToString());
using (OpenFileDialog dialog = new OpenFileDialog()) {
dialog.Filter = "String resources (.resources)|*.resources";
if (dialog.ShowDialog() != DialogResult.OK) return;
ImportResourcesFile(dialog.FileName);
}
}
void ImportResourcesFile(string fileName)
{
using (ResourceReader r = new ResourceReader(fileName)) {
IDictionaryEnumerator enumerator = r.GetEnumerator();
while (enumerator.MoveNext()) {
try {
server.UpdateTranslation(enumerator.Key.ToString(), enumerator.Value.ToString());
} catch (WebException ex) {
outputTextBox.AppendText(Environment.NewLine + "could not update: " + enumerator.Key + ": " + ex.Message);
}
}
}
}
}
}

6
src/Tools/StringResourceTool/StringResourceTool.csproj

@ -53,9 +53,15 @@ @@ -53,9 +53,15 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BuildResourceFiles.cs" />
<Compile Include="CookieAwareWebClient.cs" />
<Compile Include="MainForm.cs" />
<Compile Include="ResourceDatabase.cs" />
<Compile Include="TranslationServer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

31
src/Tools/StringResourceTool/TranslationServer.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Windows.Forms;
@ -17,11 +18,17 @@ namespace StringResourceTool @@ -17,11 +18,17 @@ namespace StringResourceTool
{
TextBox output;
string baseURL = "http://developer.sharpdevelop.net/corsavy/translation/";
public TranslationServer(TextBox output)
{
this.output = output;
this.cookieContainer = new CookieContainer();
this.wc = new CookieAwareWebClient(cookieContainer);
}
CookieContainer cookieContainer = new CookieContainer();
CookieContainer cookieContainer;
CookieAwareWebClient wc;
public bool Login(string user, string pwd)
{
output.Text = "Contacting server...";
@ -52,8 +59,6 @@ namespace StringResourceTool @@ -52,8 +59,6 @@ namespace StringResourceTool
}
public void DownloadDatabase(string targetFile, EventHandler successCallback)
{
WebClient wc = new WebClient();
wc.Headers.Set("Cookie", cookieContainer.GetCookieHeader(new Uri(baseURL)));
wc.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) {
output.BeginInvoke((MethodInvoker)delegate {
output.Text = "Download: " + e.ProgressPercentage + "%";
@ -79,8 +84,6 @@ namespace StringResourceTool @@ -79,8 +84,6 @@ namespace StringResourceTool
public void AddResourceString(string idx, string value, string purpose)
{
WebClient wc = new WebClient();
wc.Headers.Set("Cookie", cookieContainer.GetCookieHeader(new Uri(baseURL)));
wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
wc.UploadString(new Uri(baseURL + "owners_AddNew.asp"),
"Idx=" + Uri.EscapeDataString(idx)
@ -88,6 +91,15 @@ namespace StringResourceTool @@ -88,6 +91,15 @@ namespace StringResourceTool
+ "&PrimaryPurpose=" + Uri.EscapeDataString(purpose));
}
public void UpdateTranslation(string idx, string newValue)
{
newValue = HttpUtility.UrlEncode(newValue, Encoding.Default);
wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
wc.UploadString(new Uri(baseURL + "translation_edit.asp"),
"Idx=" + Uri.EscapeDataString(idx)
+ "&Localization=" + newValue);
}
public void DeleteResourceStrings(string[] idx)
{
const int threadCount = 3; // 3 parallel calls
@ -117,8 +129,6 @@ namespace StringResourceTool @@ -117,8 +129,6 @@ namespace StringResourceTool
public void DeleteResourceString(string idx, EventHandler callback)
{
WebClient wc = new WebClient();
wc.Headers.Set("Cookie", cookieContainer.GetCookieHeader(new Uri(baseURL)));
wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
wc.UploadStringCompleted += delegate {
output.BeginInvoke((MethodInvoker)delegate {
@ -131,5 +141,12 @@ namespace StringResourceTool @@ -131,5 +141,12 @@ namespace StringResourceTool
wc.UploadStringAsync(new Uri(baseURL + "owners_delete.asp"),
"Idx=" + Uri.EscapeDataString(idx) + "&ReallyDelete=on");
}
public void SetLanguage(string language)
{
wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
wc.UploadString(new Uri(baseURL + "SelectLanguage.asp"),
"Language=" + Uri.EscapeDataString(language));
}
}
}

Loading…
Cancel
Save