mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Fixed error with IETF and refactored the confluence plugin to use the right language code.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1790 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
a0c09b7d6a
commit
4e8f6b0b26
5 changed files with 87 additions and 69 deletions
|
@ -66,9 +66,9 @@ namespace GreenshotConfluencePlugin {
|
||||||
public override string Description {
|
public override string Description {
|
||||||
get {
|
get {
|
||||||
if (page == null) {
|
if (page == null) {
|
||||||
return Language.GetString(LangKey.upload_menu_item);
|
return Language.GetString("confluence", LangKey.upload_menu_item);
|
||||||
} else {
|
} else {
|
||||||
return Language.GetString(LangKey.upload_menu_item) + ": \"" + page.Title + "\"";
|
return Language.GetString("confluence", LangKey.upload_menu_item) + ": \"" + page.Title + "\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,11 +173,11 @@ namespace GreenshotConfluencePlugin {
|
||||||
Process.Start(page.Url);
|
Process.Start(page.Url);
|
||||||
} catch {}
|
} catch {}
|
||||||
} else {
|
} else {
|
||||||
System.Windows.MessageBox.Show(Language.GetString(LangKey.upload_success));
|
System.Windows.MessageBox.Show(Language.GetString("confluence", LangKey.upload_success));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
System.Windows.MessageBox.Show(Language.GetString(LangKey.upload_failure) + " " + e.Message);
|
System.Windows.MessageBox.Show(Language.GetString("confluence", LangKey.upload_failure) + " " + e.Message);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace GreenshotConfluencePlugin {
|
||||||
confluenceConnector.login();
|
confluenceConnector.login();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessageBox.Show(Language.GetFormattedString(LangKey.login_error, e.Message));
|
MessageBox.Show(Language.GetFormattedString("confluence", LangKey.login_error, e.Message));
|
||||||
}
|
}
|
||||||
return confluenceConnector;
|
return confluenceConnector;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ namespace TranslationByMarkupExtension {
|
||||||
/// See <see cref="ITranslationProvider.Translate" />
|
/// See <see cref="ITranslationProvider.Translate" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Translate(string key) {
|
public object Translate(string key) {
|
||||||
if (Language.hasKey(key)) {
|
if (Language.hasKey("confluence", key)) {
|
||||||
return Language.GetString(key);
|
return Language.GetString("confluence", key);
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,66 +4,52 @@ using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace TranslationByMarkupExtension
|
namespace TranslationByMarkupExtension {
|
||||||
{
|
public class TranslationManager {
|
||||||
public class TranslationManager
|
|
||||||
{
|
|
||||||
private static TranslationManager _translationManager;
|
private static TranslationManager _translationManager;
|
||||||
|
|
||||||
public event EventHandler LanguageChanged;
|
public event EventHandler LanguageChanged;
|
||||||
|
|
||||||
public CultureInfo CurrentLanguage
|
public CultureInfo CurrentLanguage {
|
||||||
{
|
|
||||||
get { return Thread.CurrentThread.CurrentUICulture; }
|
get { return Thread.CurrentThread.CurrentUICulture; }
|
||||||
set
|
set {
|
||||||
{
|
if( value != Thread.CurrentThread.CurrentUICulture) {
|
||||||
if( value != Thread.CurrentThread.CurrentUICulture)
|
|
||||||
{
|
|
||||||
Thread.CurrentThread.CurrentUICulture = value;
|
Thread.CurrentThread.CurrentUICulture = value;
|
||||||
OnLanguageChanged();
|
OnLanguageChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CultureInfo> Languages
|
public IEnumerable<CultureInfo> Languages {
|
||||||
{
|
get {
|
||||||
get
|
if( TranslationProvider != null) {
|
||||||
{
|
|
||||||
if( TranslationProvider != null)
|
|
||||||
{
|
|
||||||
return TranslationProvider.Languages;
|
return TranslationProvider.Languages;
|
||||||
}
|
}
|
||||||
return Enumerable.Empty<CultureInfo>();
|
return Enumerable.Empty<CultureInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TranslationManager Instance
|
public static TranslationManager Instance {
|
||||||
{
|
get {
|
||||||
get
|
if (_translationManager == null) {
|
||||||
{
|
_translationManager = new TranslationManager();
|
||||||
if (_translationManager == null)
|
}
|
||||||
_translationManager = new TranslationManager();
|
|
||||||
return _translationManager;
|
return _translationManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITranslationProvider TranslationProvider { get; set; }
|
public ITranslationProvider TranslationProvider { get; set; }
|
||||||
|
|
||||||
private void OnLanguageChanged()
|
private void OnLanguageChanged() {
|
||||||
{
|
if (LanguageChanged != null) {
|
||||||
if (LanguageChanged != null)
|
|
||||||
{
|
|
||||||
LanguageChanged(this, EventArgs.Empty);
|
LanguageChanged(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Translate(string key)
|
public object Translate(string key) {
|
||||||
{
|
if( TranslationProvider != null) {
|
||||||
if( TranslationProvider!= null)
|
object translatedValue = TranslationProvider.Translate(key);
|
||||||
{
|
if( translatedValue != null) {
|
||||||
object translatedValue =TranslationProvider.Translate(key);
|
|
||||||
if( translatedValue != null)
|
|
||||||
{
|
|
||||||
return translatedValue;
|
return translatedValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace GreenshotPlugin.Core {
|
||||||
private const string HELP_FILENAME_PATTERN = @"help-*.html";
|
private const string HELP_FILENAME_PATTERN = @"help-*.html";
|
||||||
private const string LANGUAGE_FILENAME_PATTERN = @"language*.xml";
|
private const string LANGUAGE_FILENAME_PATTERN = @"language*.xml";
|
||||||
private static Regex PREFIX_REGEXP = new Regex(@"language_([a-zA-Z0-9]+).*");
|
private static Regex PREFIX_REGEXP = new Regex(@"language_([a-zA-Z0-9]+).*");
|
||||||
private static Regex IETF_REGEXP = new Regex(@"[^a-zA-Z]+");
|
private static Regex IETF_CLEAN_REGEXP = new Regex(@"[^a-zA-Z]+");
|
||||||
|
private static Regex IETF_REGEXP = new Regex(@"^.*([a-zA-Z]{2}-[a-zA-Z]{2})\.xml$");
|
||||||
private const string LANGUAGE_GROUPS_KEY = @"SYSTEM\CurrentControlSet\Control\Nls\Language Groups";
|
private const string LANGUAGE_GROUPS_KEY = @"SYSTEM\CurrentControlSet\Control\Nls\Language Groups";
|
||||||
private static List<string> unsupportedLanguageGroups = new List<string>();
|
private static List<string> unsupportedLanguageGroups = new List<string>();
|
||||||
private static IDictionary<string, string> resources = new Dictionary<string, string>();
|
private static IDictionary<string, string> resources = new Dictionary<string, string>();
|
||||||
|
@ -143,7 +144,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ietf"></param>
|
/// <param name="ietf"></param>
|
||||||
private static void LoadFiles(string ietf) {
|
private static void LoadFiles(string ietf) {
|
||||||
ietf = ClearIETF(ietf);
|
ietf = ReformatIETF(ietf);
|
||||||
if (!languageFiles.ContainsKey(ietf)) {
|
if (!languageFiles.ContainsKey(ietf)) {
|
||||||
LOG.ErrorFormat("No language {0} available.", ietf);
|
LOG.ErrorFormat("No language {0} available.", ietf);
|
||||||
return;
|
return;
|
||||||
|
@ -173,27 +174,14 @@ namespace GreenshotPlugin.Core {
|
||||||
return currentLanguage;
|
return currentLanguage;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
string ietf = ClearIETF(value);
|
string ietf = FindBestIETFMatch(value);
|
||||||
LOG.DebugFormat("CurrentLangue = {0}, new value {1} ({2})", currentLanguage, value, ietf);
|
if (!languageFiles.ContainsKey(ietf)) {
|
||||||
if (!string.IsNullOrEmpty(ietf)) {
|
LOG.WarnFormat("No match for language {0} found!", ietf);
|
||||||
if (!languageFiles.ContainsKey(ietf)) {
|
} else {
|
||||||
LOG.WarnFormat("Unknown language {0}, trying best match!", ietf);
|
if (currentLanguage == null || !currentLanguage.Equals(ietf)) {
|
||||||
foreach (string availableIETF in languageFiles.Keys) {
|
currentLanguage = ietf;
|
||||||
if (availableIETF.StartsWith(ietf)) {
|
Reload();
|
||||||
LOG.InfoFormat("Found language {0}, best match for!", availableIETF, ietf);
|
return;
|
||||||
ietf = availableIETF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!languageFiles.ContainsKey(ietf)) {
|
|
||||||
LOG.WarnFormat("No match for language {0} found!", ietf);
|
|
||||||
} else {
|
|
||||||
if (currentLanguage == null || !currentLanguage.Equals(ietf)) {
|
|
||||||
currentLanguage = ietf;
|
|
||||||
Reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.Debug("CurrentLanguage not changed!");
|
LOG.Debug("CurrentLanguage not changed!");
|
||||||
|
@ -201,16 +189,46 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This helper method clears all non alpha characters from the IETF, and does a tolower.
|
/// Try to find the best match for the supplied IETF
|
||||||
/// So only "dede" or "enus" is left, this prevents problems with multiple formats or typos.
|
/// </summary>
|
||||||
|
/// <param name="inputIETF"></param>
|
||||||
|
/// <returns>IETF</returns>
|
||||||
|
private static string FindBestIETFMatch(string inputIETF) {
|
||||||
|
string returnIETF = inputIETF;
|
||||||
|
if (string.IsNullOrEmpty(returnIETF)) {
|
||||||
|
returnIETF = DEFAULT_LANGUAGE;
|
||||||
|
}
|
||||||
|
returnIETF = ReformatIETF(returnIETF);
|
||||||
|
if (!languageFiles.ContainsKey(returnIETF)) {
|
||||||
|
LOG.WarnFormat("Unknown language {0}, trying best match!", returnIETF);
|
||||||
|
if (returnIETF.Length == 5) {
|
||||||
|
returnIETF = returnIETF.Substring(0, 2);
|
||||||
|
}
|
||||||
|
foreach (string availableIETF in languageFiles.Keys) {
|
||||||
|
if (availableIETF.StartsWith(returnIETF)) {
|
||||||
|
LOG.InfoFormat("Found language {0}, best match for!", availableIETF, returnIETF);
|
||||||
|
returnIETF = availableIETF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnIETF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This helper method clears all non alpha characters from the IETF, and does a reformatting.
|
||||||
|
/// This prevents problems with multiple formats or typos.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputIETF"></param>
|
/// <param name="inputIETF"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static string ClearIETF(string inputIETF) {
|
private static string ReformatIETF(string inputIETF) {
|
||||||
string returnIETF = null;
|
string returnIETF = null;
|
||||||
if (!string.IsNullOrEmpty(inputIETF)) {
|
if (!string.IsNullOrEmpty(inputIETF)) {
|
||||||
returnIETF = inputIETF.ToLower();
|
returnIETF = inputIETF.ToLower();
|
||||||
returnIETF = IETF_REGEXP.Replace(returnIETF, "");
|
returnIETF = IETF_CLEAN_REGEXP.Replace(returnIETF, "");
|
||||||
|
if (returnIETF.Length == 4) {
|
||||||
|
returnIETF = returnIETF.Substring(0, 2) + "-" + returnIETF.Substring(2, 2).ToUpper();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return returnIETF;
|
return returnIETF;
|
||||||
}
|
}
|
||||||
|
@ -293,7 +311,9 @@ namespace GreenshotPlugin.Core {
|
||||||
languageFile.Filepath = languageFilePath;
|
languageFile.Filepath = languageFilePath;
|
||||||
XmlNode node = nodes.Item(0);
|
XmlNode node = nodes.Item(0);
|
||||||
languageFile.Description = node.Attributes["description"].Value;
|
languageFile.Description = node.Attributes["description"].Value;
|
||||||
languageFile.Ietf = ClearIETF(node.Attributes["ietf"].Value);
|
if (node.Attributes["ietf"] != null) {
|
||||||
|
languageFile.Ietf = ReformatIETF(node.Attributes["ietf"].Value);
|
||||||
|
}
|
||||||
if (node.Attributes["version"] != null) {
|
if (node.Attributes["version"] != null) {
|
||||||
languageFile.Version = new Version(node.Attributes["version"].Value);
|
languageFile.Version = new Version(node.Attributes["version"].Value);
|
||||||
}
|
}
|
||||||
|
@ -333,6 +353,18 @@ namespace GreenshotPlugin.Core {
|
||||||
if (languageFile == null) {
|
if (languageFile == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(languageFile.Ietf)) {
|
||||||
|
LOG.WarnFormat("Fixing missing ietf in language-file {0}", languageFilepath);
|
||||||
|
string languageFilename = Path.GetFileName(languageFilepath);
|
||||||
|
if (IETF_REGEXP.IsMatch(languageFilename)) {
|
||||||
|
string replacementIETF = IETF_REGEXP.Replace(languageFilename, "$1");
|
||||||
|
languageFile.Ietf = ReformatIETF(replacementIETF);
|
||||||
|
LOG.InfoFormat("Fixed IETF to {0}", languageFile.Ietf);
|
||||||
|
} else {
|
||||||
|
LOG.ErrorFormat("Missing ietf , no recover possible... skipping language-file {0}!", languageFilepath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we can display the file
|
// Check if we can display the file
|
||||||
if (!string.IsNullOrEmpty(languageFile.LanguageGroup) && unsupportedLanguageGroups.Contains(languageFile.LanguageGroup)) {
|
if (!string.IsNullOrEmpty(languageFile.LanguageGroup) && unsupportedLanguageGroups.Contains(languageFile.LanguageGroup)) {
|
||||||
|
@ -393,7 +425,7 @@ namespace GreenshotPlugin.Core {
|
||||||
foreach (string helpFilepath in Directory.GetFiles(languagePath, HELP_FILENAME_PATTERN, SearchOption.AllDirectories)) {
|
foreach (string helpFilepath in Directory.GetFiles(languagePath, HELP_FILENAME_PATTERN, SearchOption.AllDirectories)) {
|
||||||
LOG.DebugFormat("Found help file: {0}", helpFilepath);
|
LOG.DebugFormat("Found help file: {0}", helpFilepath);
|
||||||
string helpFilename = Path.GetFileName(helpFilepath);
|
string helpFilename = Path.GetFileName(helpFilepath);
|
||||||
string ietf = ClearIETF(helpFilename.Replace(".html", "").Replace("help-", ""));
|
string ietf = ReformatIETF(helpFilename.Replace(".html", "").Replace("help-", ""));
|
||||||
if (!helpFiles.ContainsKey(ietf)) {
|
if (!helpFiles.ContainsKey(ietf)) {
|
||||||
helpFiles.Add(ietf, helpFilepath);
|
helpFiles.Add(ietf, helpFilepath);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue