Skip to content

Commit

Permalink
Use UE4's default folder structure convention to determine the defaul…
Browse files Browse the repository at this point in the history
…t language code for a LocRes file.
  • Loading branch information
AlissaSabre committed Jul 8, 2018
1 parent e611003 commit fc33e77
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions lrxw/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -89,7 +91,7 @@ private void sourceButton_Click(object sender, EventArgs e)
{
case OperationMode.Import:
case OperationMode.Align:
handleFileDialog(sourceOpenDialog, sourceLocRes);
handleFileDialog(sourceOpenDialog, sourceLocRes, sourceLang);
break;
default:
ImpossibleCondition();
Expand All @@ -102,7 +104,7 @@ private void targetButton_Click(object sender, EventArgs e)
switch (Mode)
{
case OperationMode.Align:
handleFileDialog(targetOpenDialog, targetLocRes);
handleFileDialog(targetOpenDialog, targetLocRes, targetLang);
break;
case OperationMode.Export:
handleFileDialog(targetSaveDialog, targetLocRes);
Expand Down Expand Up @@ -130,13 +132,46 @@ private void xliffButton_Click(object sender, EventArgs e)
}
}

private void handleFileDialog(FileDialog dialog, TextBox text)
private void handleFileDialog(FileDialog dialog, TextBox text, TextBox lang = null)
{
dialog.FileName = text.Text;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
text.Text = dialog.FileName;
if (lang != null && string.IsNullOrWhiteSpace(lang.Text))
{
var f = Path.GetFileName(Path.GetDirectoryName(dialog.FileName));
if (!string.IsNullOrWhiteSpace(f))
{
bool found = false;
try
{
CultureInfo.GetCultureInfo(f);
found = true;
}
catch (ArgumentException) { }
if (found)
{
lang.Text = f;
}
}
}
}
}

private static string GetLangCodeFromPath(string path)
{
var folder_name = Path.GetFileName(Path.GetDirectoryName(path));
if (!string.IsNullOrWhiteSpace(folder_name))
{
try
{
CultureInfo.GetCultureInfo(folder_name);
return folder_name;
}
catch (ArgumentException) { }
}
return null;
}

private async void runButton_Click(object sender, EventArgs ev)
Expand Down

0 comments on commit fc33e77

Please sign in to comment.