[kupfer] websearch: Use localized firefox-addons directory



commit 29e09c24231d65caf653072ac5acdf6d87b6e5f7
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 14 21:47:18 2011 +0100

    websearch: Use localized firefox-addons directory
    
    Use firefox-addons/searchplugins/ subdirectory from locale, if
    it does not exist we try en-US.
    Bug reported and explained by Paolo Gherpelli
    
    Launchpad-bug: https://bugs.launchpad.net/kupfer/+bug/735083

 kupfer/plugin/websearch.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/websearch.py b/kupfer/plugin/websearch.py
index 8c5a8b2..2cb0658 100644
--- a/kupfer/plugin/websearch.py
+++ b/kupfer/plugin/websearch.py
@@ -9,6 +9,7 @@ __description__ = _("Search the web with OpenSearch search engines")
 __version__ = ""
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
+import locale
 import os
 import urllib
 import xml.etree.cElementTree as ElementTree
@@ -175,8 +176,15 @@ class OpenSearchSource (Source):
 			package="iceweasel"))
 
 		addon_dir = "/usr/lib/firefox-addons/searchplugins"
-		if os.path.exists(addon_dir):
-			plugin_dirs.append(addon_dir)
+		cur_lang, _ignored = locale.getlocale(locale.LC_MESSAGES)
+		suffixes = ["en-US"]
+		if cur_lang:
+			suffixes = [cur_lang.replace("_", "-"), cur_lang[:2]] + suffixes
+		for suffix in suffixes:
+			addon_lang_dir = os.path.join(addon_dir, suffix)
+			if os.path.exists(addon_lang_dir):
+				plugin_dirs.append(addon_lang_dir)
+				break
 
 		self.output_debug("Found following searchplugins directories",
 				sep="\n", *plugin_dirs)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]