private void LoadTranslations(string selectedLanguageFile)
{
listBox_translations.Items.Clear();
Debugger.WriteLine(
LogLevel.Info,
$"Loading translation files. Selected language file: {selectedLanguageFile}");
string translationsPath = Path.Combine(MaidFiddler.DATA_PATH, Translation.TRANSLATIONS_PATH);
if (!Directory.Exists(translationsPath))
{
Debugger.WriteLine(LogLevel.Warning, "No translation folder found. Creating one...");
Directory.CreateDirectory(translationsPath);
return;
}
string[] files = Directory.GetFiles(translationsPath, "*.txt");
int selected = -1;
foreach (string filePath in files)
{
using (StreamReader sr = File.OpenText(filePath))
{
TranslationData translationData = new TranslationData();
string line = sr.ReadLine();
if (line == null || line.Trim() == string.Empty)
continue;
Match match = Translation.TagPattern.Match(line);
if (!match.Success)
continue;
translationData.FileName = Path.GetFileNameWithoutExtension(filePath);
translationData.Language = match.Groups["lang"].Value;
translationData.Version = match.Groups["ver"].Value;
translationData.Author = match.Groups["auth"].Value;
Debugger.WriteLine(
LogLevel.Info,
$"Found language: File={translationData.FileName}, Lang={translationData.Language}");
int i = listBox_translations.Items.Add(translationData);
if (translationData.FileName == selectedLanguageFile)
selected = i;
}
}
if (selected != -1)
listBox_translations.SelectedIndex = selected;
}