Skip to content

Commit

Permalink
Localizations: let FW change to ConfigLang
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiTiSu authored and meee1 committed May 30, 2015
1 parent bfc2886 commit 22d8cdc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 33 deletions.
5 changes: 4 additions & 1 deletion GCSViews/Terminal.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@
<data name="TXT_terminal.Text" xml:space="preserve">
<value>*注意* 请点击上方的连接
命令行只在第一次连接电源时工作,日志只能通过USB下载
新版本仅支持通过mavlink下载日志,请访问 飞行数据 &gt; 数据闪存日志</value>

天书注:自AC3.2起,APM1/2不再支持通过本界面下载日志,请访问 飞行数据 &gt; 数据闪存日志
如果需要恢复默认设置,请访问 配置/调试 &gt; 全部参数表 &gt; 重置为默认值
</value>
</data>
<data name="BUT_logbrowse.Text" xml:space="preserve">
<value>浏览日志</value>
Expand Down
56 changes: 56 additions & 0 deletions Localizations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using MissionPlanner.Utilities;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace MissionPlanner
{
public static class Localizations
{
public static CultureInfo ConfigLang = CultureInfo.GetCultureInfo("en-US");

public static CultureInfo GetConfigLang()
{
CultureInfo ci = CultureInfoEx.GetCultureInfo((string)MainV2.config["language"]);
if (ci != null)
{
return ci;
}
else
{
return CultureInfo.GetCultureInfo("en-US");
}
}

public static string ReplaceMirrorUrl(ref string url)
{
switch (ConfigLang.Name)
{
case "zh-CN":
case "zh-Hans":
if (url.Contains("raw.github.com"))
{
url = url.Replace("raw.github.com", "githubraw.diywrj.com");
}
else if (url.Contains("firmware.diydrones.com"))
{
url = url.Replace("firmware.diydrones.com", "firmware.diywrj.com");
}
else if (url.Contains("github.com"))
{
url = url.Replace("github.com", "github.diywrj.com");
}
else
{
}
break;
default:
break;
}

return url;
}
}
}
2 changes: 2 additions & 0 deletions MainV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,8 @@ public void changelanguage(CultureInfo ci)
config["language"] = ci.Name;
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;

Localizations.ConfigLang = ci;

HashSet<Control> views = new HashSet<Control> { this, FlightData, FlightPlanner, Simulation };

foreach (Control view in MyView.Controls)
Expand Down
1 change: 1 addition & 0 deletions MissionPlanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
<Compile Include="Joystick\Joy_Mount_Mode.Designer.cs">
<DependentUpon>Joy_Mount_Mode.cs</DependentUpon>
</Compile>
<Compile Include="Localizations.cs" />
<Compile Include="Log\CollectionBuffer.cs" />
<Compile Include="Log\LogDownloadMavLink.cs">
<SubType>Form</SubType>
Expand Down
39 changes: 7 additions & 32 deletions Utilities/Firmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public Firmware()
a++;
}
}

System.Threading.Thread.CurrentThread.CurrentUICulture = Localizations.ConfigLang;
}

/// <summary>
Expand All @@ -152,7 +154,7 @@ public List<software> getFWList(string firmwareurl = "")
firmwareurl = this.firmwareurl;

// mirror support
ReplaceMirrorUrl(ref firmwareurl);
Localizations.ReplaceMirrorUrl(ref firmwareurl);

log.Info("getFWList");

Expand Down Expand Up @@ -381,6 +383,8 @@ void updateProgress(int percent, string status)
/// <returns></returns>
void getAPMVersion(object tempin)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = Localizations.ConfigLang;

try
{

Expand All @@ -390,7 +394,7 @@ void getAPMVersion(object tempin)

if (baseurl == "") return;

ReplaceMirrorUrl(ref baseurl);
Localizations.ReplaceMirrorUrl(ref baseurl);

Uri url = new Uri(new Uri(baseurl), "git-version.txt");

Expand Down Expand Up @@ -562,7 +566,7 @@ public bool update(string comport, software temp, string historyhash)
baseurl = getUrl(historyhash, baseurl);

// update to use mirror url
ReplaceMirrorUrl(ref baseurl);
Localizations.ReplaceMirrorUrl(ref baseurl);

log.Info("Using " + baseurl);

Expand Down Expand Up @@ -1230,34 +1234,5 @@ byte[] readIntelHEXv2(StreamReader sr)

return FLASH;
}

string ReplaceMirrorUrl(ref string url)
{
switch (System.Globalization.CultureInfo.CurrentUICulture.Name)
{
case "zh-CN":
case "zh-Hans":
if (url.Contains("raw.github.com"))
{
url = url.Replace("raw.github.com", "githubraw.diywrj.com");
}
else if (url.Contains("firmware.diydrones.com"))
{
url = url.Replace("firmware.diydrones.com", "firmware.diywrj.com");
}
else if (url.Contains("github.com"))
{
url = url.Replace("github.com", "github.diywrj.com");
}
else
{
}
break;
default:
break;
}

return url;
}
}
}

0 comments on commit 22d8cdc

Please sign in to comment.