diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs
index 82e2b64c5..a3c3bce91 100644
--- a/GreenshotPlugin/Controls/GreenshotForm.cs
+++ b/GreenshotPlugin/Controls/GreenshotForm.cs
@@ -204,19 +204,20 @@ namespace GreenshotPlugin.Controls {
}
protected void ApplyLanguage(ToolStripItem applyTo, string languageKey) {
+ string langString = null;
if (!string.IsNullOrEmpty(languageKey)) {
- if (!Language.hasKey(languageKey)) {
+ if (!Language.TryGetString(languageKey, out langString)) {
LOG.WarnFormat("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name);
if (DesignMode) {
MessageBox.Show(string.Format("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name));
}
return;
}
- applyTo.Text = Language.GetString(languageKey);
+ applyTo.Text = langString;
} else {
// Fallback to control name!
- if (Language.hasKey(applyTo.Name)) {
- applyTo.Text = Language.GetString(applyTo.Name);
+ if (Language.TryGetString(applyTo.Name, out langString)) {
+ applyTo.Text = langString;
return;
}
if (this.DesignMode) {
@@ -267,13 +268,15 @@ namespace GreenshotPlugin.Controls {
}
}
}
+
///
/// Apply all the language settings to the "Greenshot" Controls on this form
///
protected void ApplyLanguage() {
+ string langString = null;
// Set title of the form
- if (!string.IsNullOrEmpty(LanguageKey) && Language.hasKey(LanguageKey)) {
- this.Text = Language.GetString(LanguageKey);
+ if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) {
+ this.Text = langString;
}
// Reset the text values for all GreenshotControls
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
@@ -313,17 +316,18 @@ namespace GreenshotPlugin.Controls {
/// Apply the language text to supplied control
///
protected void ApplyLanguage(Control applyTo, string languageKey) {
+ string langString = null;
if (!string.IsNullOrEmpty(languageKey)) {
- if (!Language.hasKey(languageKey)) {
+ if (!Language.TryGetString(languageKey, out langString)) {
LOG.WarnFormat("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name);
MessageBox.Show(string.Format("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name));
return;
}
- applyTo.Text = Language.GetString(languageKey);
+ applyTo.Text = langString;
} else {
// Fallback to control name!
- if (Language.hasKey(applyTo.Name)) {
- applyTo.Text = Language.GetString(applyTo.Name);
+ if (Language.TryGetString(applyTo.Name, out langString)) {
+ applyTo.Text = langString;
return;
}
if (this.DesignMode) {
diff --git a/GreenshotPlugin/Core/Language.cs b/GreenshotPlugin/Core/Language.cs
index 98f9b8bbe..53f16dc77 100644
--- a/GreenshotPlugin/Core/Language.cs
+++ b/GreenshotPlugin/Core/Language.cs
@@ -489,6 +489,27 @@ namespace GreenshotPlugin.Core {
}
return resources.ContainsKey(key);
}
+
+ ///
+ /// TryGet method which combines hasKey & GetString
+ ///
+ ///
+ /// out string
+ ///
+ public static bool TryGetString(string key, out string languageString) {
+ return resources.TryGetValue(key, out languageString);
+ }
+
+ ///
+ /// TryGet method which combines hasKey & GetString
+ ///
+ /// string with prefix
+ /// string with key
+ /// out string
+ ///
+ public static bool TryGetString(string prefix, string key, out string languageString) {
+ return resources.TryGetValue(prefix + "." + key, out languageString);
+ }
public static string Translate(object key) {
string typename = key.GetType().Name;