2018-04-04 01:46:32 +00:00
|
|
|
|
using System;
|
2018-04-07 05:06:15 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-04-04 01:46:32 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
public static class DevUtil
|
|
|
|
|
{
|
2018-06-01 05:40:55 +00:00
|
|
|
|
public static void AddControl(ToolStripDropDownItem t)
|
|
|
|
|
{
|
|
|
|
|
t.DropDownItems.Add(GetTranslationUpdater());
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 02:24:49 +00:00
|
|
|
|
private static readonly string[] Languages = {"ja", "fr", "it", "de", "es", "ko", "zh"};
|
2018-04-04 01:46:32 +00:00
|
|
|
|
private const string DefaultLanguage = "en";
|
2018-04-08 16:19:19 +00:00
|
|
|
|
|
2019-01-02 04:27:00 +00:00
|
|
|
|
public static bool IsUpdatingTranslations { get; private set; }
|
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Call this to update all translatable resources (Program Messages, Legality Text, Program GUI)
|
|
|
|
|
/// </summary>
|
2018-06-01 05:40:55 +00:00
|
|
|
|
private static void UpdateAll()
|
2018-04-08 16:19:19 +00:00
|
|
|
|
{
|
2018-06-01 05:40:55 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Update translation files with current values?"))
|
|
|
|
|
return;
|
2019-01-02 04:27:00 +00:00
|
|
|
|
IsUpdatingTranslations = true;
|
2018-04-08 16:19:19 +00:00
|
|
|
|
DumpStringsLegality();
|
2018-09-01 21:37:58 +00:00
|
|
|
|
DumpStringsMessage();
|
2018-04-08 16:19:19 +00:00
|
|
|
|
UpdateTranslations();
|
2019-01-02 04:27:00 +00:00
|
|
|
|
IsUpdatingTranslations = false;
|
2018-04-08 16:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 05:40:55 +00:00
|
|
|
|
private static ToolStripMenuItem GetTranslationUpdater()
|
|
|
|
|
{
|
|
|
|
|
var ti = new ToolStripMenuItem
|
|
|
|
|
{
|
|
|
|
|
ShortcutKeys = Keys.Control | Keys.Alt | Keys.D,
|
|
|
|
|
Visible = false
|
|
|
|
|
};
|
|
|
|
|
ti.Click += (s, e) => UpdateAll();
|
|
|
|
|
return ti;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
|
private static void UpdateTranslations()
|
2018-04-04 01:46:32 +00:00
|
|
|
|
{
|
2018-04-19 22:36:43 +00:00
|
|
|
|
WinFormsTranslator.SetRemovalMode(false); // add mode
|
2018-04-04 01:46:32 +00:00
|
|
|
|
WinFormsTranslator.LoadAllForms(LoadBanlist); // populate with every possible control
|
|
|
|
|
WinFormsTranslator.UpdateAll(DefaultLanguage, Languages); // propagate to others
|
|
|
|
|
WinFormsTranslator.DumpAll(Banlist); // dump current to file
|
|
|
|
|
WinFormsTranslator.SetRemovalMode(); // remove used keys, don't add any
|
|
|
|
|
WinFormsTranslator.LoadAllForms(LoadBanlist); // de-populate
|
|
|
|
|
WinFormsTranslator.RemoveAll(DefaultLanguage, PurgeBanlist); // remove all lines from above generated files that still remain
|
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
|
// Move translated files from the debug exe loc to their project location
|
|
|
|
|
var files = Directory.GetFiles(Application.StartupPath);
|
|
|
|
|
var dir = GetResourcePath();
|
|
|
|
|
foreach (var f in files)
|
|
|
|
|
{
|
|
|
|
|
var fn = Path.GetFileName(f);
|
|
|
|
|
if (!fn.EndsWith(".txt"))
|
|
|
|
|
continue;
|
|
|
|
|
if (!fn.StartsWith("lang_"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
string lang = fn.Substring(5, fn.Length - (5+4));
|
|
|
|
|
var loc = GetFileLocationInText("lang", dir, lang);
|
|
|
|
|
if (File.Exists(f))
|
|
|
|
|
File.Delete(loc);
|
|
|
|
|
File.Move(f, loc);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 01:46:32 +00:00
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly string[] LoadBanlist =
|
|
|
|
|
{
|
|
|
|
|
nameof(SplashScreen),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly string[] Banlist =
|
|
|
|
|
{
|
|
|
|
|
nameof(SplashScreen),
|
|
|
|
|
"Gender=", // editor gender labels
|
|
|
|
|
"BTN_Shinytize", // ☆
|
2018-12-14 05:10:38 +00:00
|
|
|
|
"Main.L_SizeH", // height rating
|
|
|
|
|
"Main.L_SizeW", // weight rating
|
2018-04-04 01:46:32 +00:00
|
|
|
|
"Main.B_Box", // << and >> arrows
|
|
|
|
|
"Main.L_Characteristic=", // Characterstic (dynamic)
|
|
|
|
|
"Main.L_Potential", // ★☆☆☆ IV judge evaluation
|
|
|
|
|
"SAV_HoneyTree.L_Tree0", // dynamic, don't bother
|
|
|
|
|
"SAV_Misc3.BTN_Symbol", // symbols should stay as their current character
|
2018-08-14 02:40:00 +00:00
|
|
|
|
"SettingsEditor.BAKPrompt", // internal setting
|
2019-01-16 06:26:45 +00:00
|
|
|
|
"SAV_GameSelect.L_Prompt", // prompt text (dynamic)
|
2018-04-04 01:46:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly string[] PurgeBanlist =
|
|
|
|
|
{
|
|
|
|
|
nameof(SuperTrainingEditor),
|
|
|
|
|
nameof(ErrorWindow),
|
|
|
|
|
nameof(SettingsEditor),
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-01 21:43:26 +00:00
|
|
|
|
private static void DumpStringsMessage() => DumpStrings(typeof(MessageStrings), false);
|
2018-04-08 16:19:19 +00:00
|
|
|
|
private static void DumpStringsLegality() => DumpStrings(typeof(LegalityCheckStrings));
|
2018-07-22 02:20:11 +00:00
|
|
|
|
|
2018-09-01 21:43:26 +00:00
|
|
|
|
private static void DumpStrings(Type t, bool sorted = true)
|
2018-04-04 01:46:32 +00:00
|
|
|
|
{
|
2018-04-08 16:19:19 +00:00
|
|
|
|
var dir = GetResourcePath();
|
2018-04-07 05:06:15 +00:00
|
|
|
|
var langs = new[] {DefaultLanguage}.Concat(Languages);
|
|
|
|
|
foreach (var lang in langs)
|
|
|
|
|
{
|
2018-04-07 05:51:10 +00:00
|
|
|
|
Util.SetLocalization(t, lang);
|
|
|
|
|
var entries = Util.GetLocalization(t);
|
2018-04-07 05:06:15 +00:00
|
|
|
|
var export = entries.Select(z => new {Variable = z.Split('=')[0], Line = z})
|
2018-09-01 21:37:58 +00:00
|
|
|
|
.OrderBy(z => z.Variable) // sort by length (V1 = 2, V100 = 4)
|
2018-04-07 05:06:15 +00:00
|
|
|
|
.Select(z => z.Line); // sorted lines
|
|
|
|
|
|
2018-09-01 21:43:26 +00:00
|
|
|
|
if (!sorted)
|
|
|
|
|
export = entries;
|
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
|
var location = GetFileLocationInText(t.Name, dir, lang);
|
|
|
|
|
File.WriteAllLines(location, export);
|
2018-04-07 05:51:10 +00:00
|
|
|
|
Util.SetLocalization(t, DefaultLanguage);
|
2018-04-07 05:06:15 +00:00
|
|
|
|
}
|
2018-04-04 01:46:32 +00:00
|
|
|
|
}
|
2018-04-08 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
private static string GetFileLocationInText(string fileType, string dir, string lang)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(dir, lang);
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
path = Path.Combine(dir, "other");
|
|
|
|
|
|
|
|
|
|
var fn = $"{fileType}_{lang}.txt";
|
|
|
|
|
return Path.Combine(path, fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetResourcePath()
|
|
|
|
|
{
|
|
|
|
|
var path = Application.StartupPath;
|
|
|
|
|
const string projname = "PKHeX\\";
|
|
|
|
|
var pos = path.LastIndexOf(projname, StringComparison.Ordinal);
|
|
|
|
|
var str = path.Substring(0, pos + projname.Length);
|
|
|
|
|
var coreFolder = Path.Combine(str, "PKHeX.Core", "Resources", "text");
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
|
return coreFolder;
|
|
|
|
|
}
|
2018-04-04 01:46:32 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|