Browse Source

Merge pull request #2741 from studentmain/master

Fix #2740, write i18n.csv on demand
tags/4.2.1.0
Student Main GitHub 5 years ago
parent
commit
efc5a256c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 23 deletions
  1. +16
    -12
      shadowsocks-csharp/Controller/I18N.cs
  2. +1
    -0
      shadowsocks-csharp/Data/i18n.csv
  3. +15
    -11
      shadowsocks-csharp/View/MenuViewController.cs

+ 16
- 12
shadowsocks-csharp/Controller/I18N.cs View File

@@ -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>();
@@ -45,14 +45,16 @@ namespace Shadowsocks.Controller
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
@@ -75,17 +77,19 @@ namespace Shadowsocks.Controller
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)


+ 1
- 0
shadowsocks-csharp/Data/i18n.csv View File

@@ -46,6 +46,7 @@ Load Balance,负载均衡,負載平衡,負荷分散
High Availability,高可用,高可用性,高可用性
Choose by statistics,根据统计,根據統計,統計で選ぶ
Show Plugin Output,显示插件输出,,
Write translation template,写入翻译模板,,
,,,
# Config Form,,,
,,,


+ 15
- 11
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -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
@@ -56,6 +53,7 @@ namespace Shadowsocks.View
private MenuItem hotKeyItem;
private MenuItem VerboseLoggingToggleItem;
private MenuItem ShowPluginOutputToggleItem;
private MenuItem WriteI18NFileItem;
private ConfigForm configForm;
private ProxyForm proxyForm;
@@ -322,6 +320,7 @@ namespace Shadowsocks.View
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)),
CreateMenuGroup("Updates...", new MenuItem[] {
CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)),
new MenuItem("-"),
@@ -718,6 +717,11 @@ namespace Shadowsocks.View
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);


Loading…
Cancel
Save