Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2740, write i18n.csv on demand #2741

Merged
3 commits merged into from Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions shadowsocks-csharp/Controller/I18N.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Shadowsocks.Controller

public static class I18N
{
private static readonly string I18N_FILE = "i18n.csv";
public const string I18N_FILE = "i18n.csv";

private static Dictionary<string, string> _strings = new Dictionary<string, string>();

Expand Down Expand Up @@ -45,14 +45,16 @@ private static void Init(string res, string locale)
if (localeNames[i].Split('-')[0] == localeNoRegion)
targetIndex = i;
}
Logging.Info($"Using {localeNames[targetIndex]} translation for {locale}");
}

// Still not found, exit
if (targetIndex == -1 || enIndex == targetIndex)
{
Logging.Info($"Translation for {locale} not found");
return;
if (targetIndex != -1 && enIndex != targetIndex)
{
Logging.Info($"Using {localeNames[targetIndex]} translation for {locale}");
}
else
{
// Still not found, exit
Logging.Info($"Translation for {locale} not found");
return;
}
}

// read translation lines
Expand All @@ -75,17 +77,19 @@ private static void Init(string res, string locale)
static I18N()
{
string i18n;
string locale = CultureInfo.CurrentCulture.Name;
if (!File.Exists(I18N_FILE))
{
i18n = Resources.i18n_csv;
File.WriteAllText(I18N_FILE, i18n, Encoding.UTF8);
//File.WriteAllText(I18N_FILE, i18n, Encoding.UTF8);
}
else
{
Logging.Info("Using external translation");
i18n = File.ReadAllText(I18N_FILE, Encoding.UTF8);
}
Logging.Info("Current language is: " + CultureInfo.CurrentCulture.Name);
Init(i18n, CultureInfo.CurrentCulture.Name);
Logging.Info("Current language is: " + locale);
Init(i18n, locale);
}

public static string GetString(string key, params object[] args)
Expand Down
1 change: 1 addition & 0 deletions shadowsocks-csharp/Data/i18n.csv
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Load Balance,负载均衡,負載平衡,負荷分散
High Availability,高可用,高可用性,高可用性
Choose by statistics,根据统计,根據統計,統計で選ぶ
Show Plugin Output,显示插件输出,,
Write translation template,写入翻译模板,,
,,,
# Config Form,,,
,,,
Expand Down
26 changes: 15 additions & 11 deletions shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
using System;
using Shadowsocks.Controller;
using Shadowsocks.Model;
using Shadowsocks.Properties;
using Shadowsocks.Util;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZXing;
using ZXing.Common;
using ZXing.QrCode;

using Shadowsocks.Controller;
using Shadowsocks.Model;
using Shadowsocks.Properties;
using Shadowsocks.Util;
using System.Linq;
using Microsoft.Win32;
using System.Windows.Interop;

namespace Shadowsocks.View
{
public class MenuViewController
Expand Down Expand Up @@ -56,6 +53,7 @@ public class MenuViewController
private MenuItem hotKeyItem;
private MenuItem VerboseLoggingToggleItem;
private MenuItem ShowPluginOutputToggleItem;
private MenuItem WriteI18NFileItem;

private ConfigForm configForm;
private ProxyForm proxyForm;
Expand Down Expand Up @@ -322,6 +320,7 @@ private void LoadMenu()
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
this.VerboseLoggingToggleItem = CreateMenuItem( "Verbose Logging", new EventHandler(this.VerboseLoggingToggleItem_Click) ),
this.ShowPluginOutputToggleItem = CreateMenuItem("Show Plugin Output", new EventHandler(this.ShowPluginOutputToggleItem_Click)),
this.WriteI18NFileItem = CreateMenuItem("Write translation template",new EventHandler(WriteI18NFileItem_Click)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this menu? What will happen if user generated an old csv file then user upgrade SS to a new version with new UI elements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this menu?

user can translate the program by edit generated csv

What will happen

New translation won't apply

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New translation won't apply

IMO, if users need a new language or amend the translation, let them send pull request. Otherwise, by use of an external translation file may cause some "out-of-date" problem after upgrade.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel it doesn't matter, please merge the PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenshaoju How do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My programming is bad...
Looks good, build succeeded, I think is good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"out-of-date" problem

will implement translate file merge to resolve this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will implement translate file merge to resolve this

What will happen if there is a conflict or obsoleted item in new version? This is what I am worrying about. Too much user interactions.
Or your design purpose is to switch between "integrated translation resource" and "external translation file" in the future?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflict

use external one, as user may changed it

obsoleted

just keep it, user can downgrade version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I will draft a new release soon

CreateMenuGroup("Updates...", new MenuItem[] {
CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)),
new MenuItem("-"),
Expand Down Expand Up @@ -718,6 +717,11 @@ private void ShowPluginOutputToggleItem_Click(object sender, EventArgs e)
controller.ToggleShowPluginOutput(ShowPluginOutputToggleItem.Checked);
}

private void WriteI18NFileItem_Click(object sender, EventArgs e)
{
File.WriteAllText(I18N.I18N_FILE, Resources.i18n_csv, Encoding.UTF8);
}

private void StatisticsConfigItem_Click(object sender, EventArgs e)
{
StatisticsStrategyConfigurationForm form = new StatisticsStrategyConfigurationForm(controller);
Expand Down