[rkward-cvs] SF.net SVN: rkward-code:[4811] trunk/rkward/rkward/plugin/rkcomponentmap. cpp

tfry at users.sf.net tfry at users.sf.net
Sun Sep 7 16:36:04 UTC 2014


Revision: 4811
          http://sourceforge.net/p/rkward/code/4811
Author:   tfry
Date:     2014-09-07 16:36:02 +0000 (Sun, 07 Sep 2014)
Log Message:
-----------
Add experimental support for static i18n using localized pluginmaps. See http://www.mail-archive.com/rkward-devel@lists.sourceforge.net/msg02317.html

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2014-09-07 15:46:03 UTC (rev 4810)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2014-09-07 16:36:02 UTC (rev 4811)
@@ -382,6 +382,41 @@
 	for (XMLChildList::const_iterator it=list.constBegin (); it != list.constEnd (); ++it) {
 		if ((*it).hasAttribute ("file")) {
 			QString file = pluginmap_file_desc->makeFileName (xml->getStringAttribute (*it, "file", QString (), DL_ERROR));
+			/// EXPERIMENTAL: Look for localized version of required pluginmap
+			if (xml->getBoolAttribute (*it, "localized", false, DL_INFO)) {
+				QFileInfo fi(file);
+				QDir dir = fi.absoluteDir ();
+				QString fn = fi.fileName ();
+				QString lang = KGlobal::locale ()->language ();
+				RK_DEBUG (PLUGIN, DL_INFO, "Looking for localized version of %s, (locale is %s)", qPrintable (file), qPrintable (lang));
+				QString country = lang.section ('_', 1, 1);	// in case it's something like 'de_DE'
+				lang = lang.section ('_', 0, 0);
+				QStringList candidates = dir.entryList (QStringList () << lang + "*." + fn);
+				QString plain_match, exact_match;
+				// if full language code is 'de_DE', look for (in order of preference):
+				// de_DE, de, de_SOMETHING
+				for (int i = 0; i < candidates.length (); ++i) {
+					if (candidates[i] == lang + '_' + country + '.' + fn) {
+						exact_match = candidates[i];
+						break;
+					} else if (candidates[i] == lang + '.' + fn) {
+						plain_match = candidates[i];
+					}
+				}
+				if (!exact_match.isEmpty ()) {
+					file = exact_match;
+					RK_DEBUG (PLUGIN, DL_INFO, "Found exact match");
+				} else if (!plain_match.isEmpty ()) {
+					file = plain_match;
+					RK_DEBUG (PLUGIN, DL_INFO, "Found language match");
+				} else if (!candidates.isEmpty ()) {
+					file = candidates[0];
+					RK_DEBUG (PLUGIN, DL_INFO, "Using %s as best match");
+				} else {
+					RK_DEBUG (PLUGIN, DL_INFO, "No suitable localized version found");
+				}
+			}
+			/// END
 			if (QFileInfo (file).isReadable ()) {
 				includelist.append (file);
 			} else {





More information about the rkward-tracker mailing list