private void AddTranslationRegex(RegexTranslation regex) { if (!_registeredRegexes.Contains(regex.Original)) { _registeredRegexes.Add(regex.Original); _defaultRegexes.Add(regex); } }
private void LoadTranslationsInStream(Stream stream, bool allowOverride, bool closeStream) { try { var reader = new StreamReader(stream, Encoding.UTF8); { string[] translations = reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string translatioOrDirective in translations) { try { var kvp = TextHelper.ReadTranslationLineAndDecode(translatioOrDirective); if (kvp != null) { string key = kvp[0]; string value = kvp[1]; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value) && key != value) { if (key.StartsWith("r:")) { try { var regex = new RegexTranslation(key, value); AddTranslationRegex(regex); } catch (Exception e) { XuaLogger.AutoTranslator.Warn(e, $"An error occurred while constructing regex translation: '{translatioOrDirective}'."); } } else { AddTranslationInternal(key, value.MakeRedirected(), allowOverride); } } } } catch (Exception e) { XuaLogger.AutoTranslator.Warn(e, $"An error occurred while reading translation: '{translatioOrDirective}'."); } } } } finally { if (closeStream) { stream.Dispose(); } } }
private void AddTranslationRegex(RegexTranslation regex) { if (!_registeredRegexes.Contains(regex.Original)) { _registeredRegexes.Add(regex.Original); _defaultRegexes.Add(regex); } //else //{ // XuaLogger.Current.Warn( $"Could not register translation regex '{regex.Original}' because it has already been registered." ); //} }
private void LoadTranslationsInFile(string fullFileName) { if (File.Exists(fullFileName)) { XuaLogger.Current.Debug($"Loading texts: {fullFileName}."); string[] translations = File.ReadAllLines(fullFileName, Encoding.UTF8); foreach (string translation in translations) { for (int i = 0; i < TranslationSplitters.Length; i++) { var splitter = TranslationSplitters[i]; string[] kvp = translation.Split(splitter, 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) && IsTranslatable(key)) { if (key.StartsWith("r:")) { try { var regex = new RegexTranslation(key, value); AddTranslationRegex(regex); } catch (Exception e) { XuaLogger.Current.Warn(e, $"An error occurred while constructing regex translation: '{translation}'."); } } else { AddTranslation(key, value); // also add a modified version of the translation var ukey = new UntranslatedText(key, false, false); var uvalue = new UntranslatedText(value, false, false); if (ukey.TrimmedTranslatableText != key) { AddTranslation(ukey.TrimmedTranslatableText, uvalue.TrimmedTranslatableText); } } break; } } } } } }
private void LoadTranslationsInFile(string fullFileName, bool allowOverride) { var fileExists = File.Exists(fullFileName); if (fileExists) { if (fileExists) { string[] translations = File.ReadAllLines(fullFileName, Encoding.UTF8); foreach (string translatioOrDirective in translations) { string[] kvp = translatioOrDirective.Split(TranslationSplitters, 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)) { if (key.StartsWith("r:")) { try { var regex = new RegexTranslation(key, value); AddTranslationRegex(regex); } catch (Exception e) { XuaLogger.AutoTranslator.Warn(e, $"An error occurred while constructing regex translation: '{translatioOrDirective}'."); } } else { AddTranslation(key, value, allowOverride); } } } } } } }