public TranslatableResXFile(Assembly assembly, string resourceName) { baseName = Path.ChangeExtension(resourceName.Substring(App.TranslatableResourcePrefix.Length), null); using (var stream = assembly.GetManifestResourceStream(resourceName)) { using (ResourceReader resReader = new ResourceReader(stream)) { foreach (System.Collections.DictionaryEntry entry in resReader) { if (entry.Value is string) { // Sort out keys used by WinForms for something that should not be translated // - it's a mess as the WinForm designer mix everything leaving it to translation programs to sort it out :( string key = (string)entry.Key; string val = (string)entry.Value; if (key.StartsWith(">>", StringComparison.InvariantCulture)) { if (key.EndsWith(".Name", StringComparison.InvariantCulture) || key.EndsWith(".Type", StringComparison.InvariantCulture) || key.EndsWith(".Parent", StringComparison.InvariantCulture) || key.EndsWith(".ZOrder", StringComparison.InvariantCulture)) // More are probably needed, add them as they are found :( { continue; } } // Skip the Text field for controls if they look like a default control name if (key.EndsWith(".Text", StringComparison.InvariantCulture) && defaultControlTextRegex.IsMatch(val)) { continue; } // Check it at least have one English letter (a-z). If not, assume non translatable number etc. if (!translatableTextRegex.IsMatch(val)) { continue; } if (key == "$this.Localizable") { continue; } var translatableString = new TranslatableString(key, val, this); translatableStrings.Add(translatableString); translatableString.PropertyChanged += TranslatableStringPropertyChangedHandler; } } } } }
public TranslatableResXFile(Assembly assembly, string resourceName) { baseName = Path.ChangeExtension(resourceName.Substring(App.TranslatableResourcePrefix.Length), null); using (var stream = assembly.GetManifestResourceStream(resourceName)) { using (ResourceReader resReader = new ResourceReader(stream)) { foreach (System.Collections.DictionaryEntry entry in resReader) { if (entry.Value is string) { // Sort out keys used by WinForms for something that should not be translated // - it's a mess as the WinForm designer mix everything leaving it to translation programs to sort it out :( string key = (string) entry.Key; string val = (string) entry.Value; if (key.StartsWith(">>", StringComparison.InvariantCulture)) { if (key.EndsWith(".Name", StringComparison.InvariantCulture) || key.EndsWith(".Type", StringComparison.InvariantCulture) || key.EndsWith(".Parent", StringComparison.InvariantCulture) || key.EndsWith(".ZOrder", StringComparison.InvariantCulture)) // More are probably needed, add them as they are found :( { continue; } } // Skip the Text field for controls if they look like a default control name if (key.EndsWith(".Text", StringComparison.InvariantCulture) && defaultControlTextRegex.IsMatch(val)) { continue; } // Check it at least have one English letter (a-z). If not, assume non translatable number etc. if (!translatableTextRegex.IsMatch(val)) { continue; } if (key == "$this.Localizable") continue; var translatableString = new TranslatableString(key, val, this); translatableStrings.Add(translatableString); translatableString.PropertyChanged += TranslatableStringPropertyChangedHandler; } } } } }