private void LoadResizeCommandsInStream(Stream stream, string fullFileName) { if (!Settings.EnableSilentMode) { XuaLogger.AutoTranslator.Debug($"Loading resize commands: {fullFileName}."); } var reader = new StreamReader(stream, Encoding.UTF8); { var context = new TranslationFileLoadingContext(); string[] translations = reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string translatioOrDirective in translations) { if (Settings.EnableTranslationScoping) { var directive = TranslationFileDirective.Create(translatioOrDirective); if (directive != null) { context.Apply(directive); if (!Settings.EnableSilentMode) { XuaLogger.AutoTranslator.Debug("Directive in file: " + fullFileName + ": " + directive.ToString()); } continue; } } if (context.IsExecutable(Settings.ApplicationName)) { string[] kvp = translatioOrDirective.Split(Splitters, StringSplitOptions.None); if (kvp.Length == 2) { string key = TextHelper.Decode(kvp[0]); string value = TextHelper.Decode(kvp[1]); if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { var levels = context.GetLevels(); if (levels.Count == 0) { AddTranslation(key, value, TranslationScopes.None); } else { foreach (var level in levels) { AddTranslation(key, value, level); } } } } } } } }
private void LoadResizeCommandsInFile(string fullFileName) { var fileExists = File.Exists(fullFileName); if (fileExists) { XuaLogger.AutoTranslator.Debug($"Loading resize commands: {fullFileName}."); var context = new TranslationFileLoadingContext(); string[] translations = File.ReadAllLines(fullFileName, Encoding.UTF8); foreach (string translatioOrDirective in translations) { if (Settings.EnableTranslationScoping) { var directive = TranslationFileDirective.Create(translatioOrDirective); if (directive != null) { context.Apply(directive); XuaLogger.AutoTranslator.Debug("Directive in file: " + fullFileName + ": " + directive.ToString()); continue; } } if (context.IsExecutable(Settings.ApplicationName)) { string[] kvp = translatioOrDirective.Split(Splitters, StringSplitOptions.None); if (kvp.Length == 2) { string key = TextHelper.Decode(kvp[0]); string value = TextHelper.Decode(kvp[1]); if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { var levels = context.GetLevels(); if (levels.Count == 0) { AddTranslation(key, value, TranslationScopes.None); } else { foreach (var level in levels) { AddTranslation(key, value, level); } } } } } } } }
private void LoadResizeCommandsInStream(Stream stream, string fullFileName) { if (!Settings.EnableSilentMode) { XuaLogger.AutoTranslator.Debug($"Loading resize commands: {fullFileName}."); } var reader = new StreamReader(stream, Encoding.UTF8); { var context = new TranslationFileLoadingContext(); string[] translations = reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string translatioOrDirective in translations) { var directive = TranslationFileDirective.Create(translatioOrDirective); if (directive != null) { context.Apply(directive); if (!Settings.EnableSilentMode) { XuaLogger.AutoTranslator.Debug("Directive in file: " + fullFileName + ": " + directive.ToString()); } continue; } if (context.IsApplicable()) { try { var kvp = TextHelper.ReadTranslationLineAndDecode(translatioOrDirective); if (kvp != null) { string key = kvp[0]; string value = kvp[1]; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { var levels = context.GetLevels(); if (levels.Count == 0) { AddTranslation(key, value, TranslationScopes.None); } else { foreach (var level in levels) { AddTranslation(key, value, level); } } } } } catch (Exception e) { XuaLogger.AutoTranslator.Warn(e, $"An error occurred while reading UI resize directive: '{translatioOrDirective}'."); } } } } }