Bug 129469

Summary: kmahjongg: untranslatable strings in dialogs
Product: [Applications] kmahjongg Reporter: Burkhard Lück <lueck>
Component: generalAssignee: Mauricio Piacentini <piacentini>
Status: RESOLVED FIXED    
Severity: normal CC: aleixpol
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:

Description Burkhard Lück 2006-06-20 09:29:03 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

In several dialog are untranslatable items:

Choose Theme Dialog -> default, pirates

Change Tile Set Dialog -> default, traditional, pirates, runes

Change Background Image -> default, haze, pirates, slate, wood

Change Board Layout -> default, cross, pirates, pyramid, stax, tower, triangle

These strings are taken from the filenames in kmahjongg/pics (*.theme, *.tileset, *.bgnd and *.layout files).
This design makes it unpossible to extract strings for translation, it is an i18n error in kmahjongg
Comment 1 Mauricio Piacentini 2006-08-25 21:31:15 UTC
This is an interesting issue. I would not call it a bug exactly, it is more like a limitation of the current approach used in several components of kde, specially games, where additional levels are loaded by their filenames on disk.
I definately agree this is an important issue to address, but I am still trying to find a way to deal with this in an optimal way. Maybe a solution is to use KNewStuff, which has some support for localization.
I will confirm this as an issue for now, and will get more feedback from other developers at aKademy with ideas on how to address it for KDE4.

We are already working on other enhancements for KMahjongg in KDE4, you can read more about this at
http://tsdgeos.blogspot.com/2006/08/kmahjongg-revamp.html
Comment 2 Mauricio Piacentini 2006-12-06 00:01:58 UTC
SVN commit 610889 by piacentini:

Change tileset format to a shared location, installed by libkmahjongg. 
Also change tileset description data to use .desktop files. This
will allow localization of tileset names, as asked for in
BUG: 129469


 M  +1 -1      kmahjongg/boardwidget.cpp  
 M  +1 -32     kmahjongg/pics/CMakeLists.txt  
 D             kmahjongg/pics/classic.svg  
 D             kmahjongg/pics/classic.tileset  
 D             kmahjongg/pics/default.tileset  
 D             kmahjongg/pics/default_tileset.svgz  
 M  +2 -0      libkmahjongg/CMakeLists.txt  
 M  +37 -37    libkmahjongg/kmahjonggtileset.cpp  
 M  +2 -1      libkmahjongg/kmahjonggtileset.h  
 A             libkmahjongg/tilesets (directory)  
 A             libkmahjongg/tilesets/CMakeLists.txt  
 A             libkmahjongg/tilesets/classic.copyright  
 A             libkmahjongg/tilesets/classic.desktop  
 A             libkmahjongg/tilesets/classic.svg   kmahjongg/pics/classic.svg#610850
 A             libkmahjongg/tilesets/default.copyright  
 A             libkmahjongg/tilesets/default.desktop  
 A             libkmahjongg/tilesets/default.svgz   kmahjongg/pics/default_tileset.svgz#610850


--- trunk/KDE/kdegames/kmahjongg/boardwidget.cpp #610888:610889
@@ -1216,7 +1216,7 @@
     return true;
   } else {
     if (theTiles.loadDefault()) {
-      Prefs::setTileSet(path);
+      Prefs::setTileSet(theTiles.path());
       Prefs::writeConfig();
       resizeTileset(size());
       return false;
--- trunk/KDE/kdegames/kmahjongg/pics/CMakeLists.txt #610888:610889
@@ -1,38 +1,7 @@
 
-
-
-
 ########### install files ###############
 
-#install( FILES kmahjongg.png kmahjongg_bgnd.png splash.png DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
-#install( FILES default.theme DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
+
 install( FILES default.bgnd DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
-install( FILES default.tileset default_tileset.svgz DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
-install( FILES classic.tileset classic.svg DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
 install( FILES default.layout cross.layout pirates.layout  	pyramid.layout stax.layout test.layout test2.layout  	tower.layout triangle.layout  DESTINATION  ${DATA_INSTALL_DIR}/kmahjongg/pics )
 
-
-
-
-
-#original Makefile.am contents follow:
-
-#theme_DATA = default.theme pirates.theme
-#themedir = $(kde_datadir)/kmahjongg/pics
-#
-#pics_DATA = kmahjongg.png kmahjongg_bgnd.png splash.png newnum.xpm
-#picsdir = $(kde_datadir)/kmahjongg/pics
-#
-#layout_DATA = default.layout cross.layout pirates.layout \
-#	pyramid.layout stax.layout test.layout test2.layout \
-#	tower.layout triangle.layout
-#layoutdir = $(kde_datadir)/kmahjongg/pics
-#
-#bgnd_DATA = default.bgnd haze.bgnd pirates.bgnd slate.bgnd \
-#	wood.bgnd
-#bgnddir = $(kde_datadir)/kmahjongg/pics
-#
-#tileset_DATA = default.tileset pirates.tileset runes.tileset traditional.tileset
-#tilesetdir = $(kde_datadir)/kmahjongg/pics
-#
-#EXTRA_DIST = $(pics_DATA) $(layout_DATA) $(bgnd_DATA) $(tileset_DATA) $(theme_DATA)
--- trunk/KDE/kdegames/libkmahjongg/CMakeLists.txt #610888:610889
@@ -1,5 +1,7 @@
 project(libkmahjongg)
 
+add_subdirectory( tilesets ) 
+
 ########### next target ###############
 
 set(kmahjongg_LIB_SRCS
--- trunk/KDE/kdegames/libkmahjongg/kmahjonggtileset.cpp #610888:610889
@@ -19,6 +19,8 @@
 
 #include <stdlib.h>
 #include "kmahjonggtileset.h"
+#include <klocale.h>
+#include <ksimpleconfig.h>
 #include <qimage.h>
 #include <kstandarddirs.h>
 #include <QPainter>
@@ -32,8 +34,16 @@
 
 KMahjonggTileset::KMahjonggTileset()
 {
-	filename = "";
-	buildElementIdTable();
+    filename = "";
+    buildElementIdTable();
+
+    static bool _inited = false;
+    if (_inited)
+        return;
+    KGlobal::dirs()->addResourceType("kmahjonggtileset", KStandardDirs::kde_default("data") + QString::fromLatin1("kmahjongglib/tilesets/"));
+
+    KGlobal::locale()->insertCatalog("libkmahjongglib");
+    _inited = true;
 }
 
 // ---------------------------------------------------------
@@ -77,11 +87,10 @@
 
 bool KMahjonggTileset::loadDefault()
 {
-    QString picsPos = "pics/";
-    picsPos += "default.tileset";
+    QString idx = "default.desktop";
 
-    QString tilesetPath = KStandardDirs::locate("appdata", picsPos);
-
+    QString tilesetPath = KStandardDirs::locate("kmahjonggtileset", idx);
+qDebug() << "Inside LoadDefault(), located path at " << tilesetPath;
     if (tilesetPath.isEmpty()) {
 		return false;
     }
@@ -90,55 +99,46 @@
 
 
 // ---------------------------------------------------------
-bool KMahjonggTileset::loadTileset( const QString& tilesetPath)
+bool KMahjonggTileset::loadTileset( QString tilesetPath)
 {
 
     QImage qiTiles;
     QString graphicsPath;
+qDebug() << "Attempting to load .desktop at " << tilesetPath;
 
     if (filename == tilesetPath) {
 	return true;
     }
 
-    // verify if it is a valid XML file first and if we can open it
-    QDomDocument doc("tileset");
+    // verify if it is a valid file first and if we can open it
     QFile tilesetfile(tilesetPath);
     if (!tilesetfile.open(QIODevice::ReadOnly)) {
       return (false);
     }
-    if (!doc.setContent(&tilesetfile)) {
-      tilesetfile.close();
-      return (false);
-    }
     tilesetfile.close();
 
-    //now see if it is a kdegames mahjongg tileset
-    QDomElement root = doc.documentElement();
-    if (root.tagName() != "kdegames-tileset") {
-        return (false);
-    } else if (root.hasAttribute("version")
-                && root.attribute("version") != "1.0") {
-        return (false);
-    }
+    KSimpleConfig tileconfig(tilesetPath);
+    tileconfig.setGroup(QString::fromLatin1("KMahjonggTileset"));
 
-    QDomElement graphics = root.firstChildElement("graphics");
-    if (!graphics.isNull()) {
-        QString graphName = graphics.firstChildElement("path").text();
-    	QString graphPos = "pics/"+graphName;
+    QString themeName = tileconfig.readEntry("Name"); // Returns translated data
+    //Versioning???
 
-    	graphicsPath = KStandardDirs::locate("appdata", graphPos);
-	filename = graphicsPath;
-	isSVG = (graphics.attribute("type") == "svg");
-	originaldata.w      = graphics.firstChildElement("tilewidth").text().toInt();
-	originaldata.h      = graphics.firstChildElement("tileheight").text().toInt();
-	originaldata.fw  =  graphics.firstChildElement("tilefacewidth").text().toInt();
-	originaldata.fh = graphics.firstChildElement("tilefaceheight").text().toInt();
-	originaldata.lvloff     =  graphics.firstChildElement("leveloffset").text().toInt();
-     	if (graphicsPath.isEmpty()) return (false);
-     } else {
-	return (false);
-     }
+    QString graphName = tileconfig.readEntry("FileName");
 
+    graphicsPath = KStandardDirs::locate("kmahjonggtileset", graphName);
+qDebug() << "Using tileset at " << graphicsPath;
+    filename = graphicsPath;
+
+    //only SVG for now
+    isSVG = true;
+
+    originaldata.w      = tileconfig.readEntry("TileWidth",0);
+    originaldata.h      = tileconfig.readEntry("TileHeight",0);
+    originaldata.fw  =  tileconfig.readEntry("TileFaceWidth",0);
+    originaldata.fh = tileconfig.readEntry("TileFaceHeight",0);
+    originaldata.lvloff     =  tileconfig.readEntry("LevelOffset",0);
+    if (graphicsPath.isEmpty()) return (false);
+
     if( isSVG ) {
 	//really?
 	svg.load(graphicsPath);
--- trunk/KDE/kdegames/libkmahjongg/kmahjonggtileset.h #610888:610889
@@ -37,7 +37,7 @@
      ~KMahjonggTileset();	
 
      bool loadDefault();
-     bool loadTileset(const QString &filesetPath);
+     bool loadTileset(QString tilesetPath);
      bool reloadTileset( QSize newTilesize);
      QSize preferredTileSize(QSize boardsize, int horizontalCells, int verticalCells);
 
@@ -46,6 +46,7 @@
      short levelOffset() {return scaleddata.lvloff;};
      short qWidth() {return (short) (scaleddata.fw / 2.0);};
      short qHeight() {return (short) (scaleddata.fh / 2.0);};
+     QString path() {return filename;};
 
      QPixmap selectedTile(int num);
      QPixmap unselectedTile(int num);
Comment 3 Aleix Pol 2012-06-20 00:57:20 UTC
Git commit 919e477a10b4a0caa3400e9810a84b004102eacb by Aleix Pol.
Committed on 20/06/2012 at 02:56.
Pushed by apol into branch '4.3'.

Improve Build directory retrieval

Properly navigate the original tree structure

M  +2    -2    projectmanagers/cmake/cmakemanager.cpp

http://commits.kde.org/kdevelop/919e477a10b4a0caa3400e9810a84b004102eacb
Comment 4 Aleix Pol 2012-06-20 00:57:21 UTC
Git commit db1685a8a3c1df3810e49991a5a1983f2a34ce81 by Aleix Pol.
Committed on 20/06/2012 at 02:56.
Pushed by apol into branch 'master'.

Improve Build directory retrieval

Properly navigate the original tree structure

M  +2    -2    projectmanagers/cmake/cmakemanager.cpp

http://commits.kde.org/kdevelop/db1685a8a3c1df3810e49991a5a1983f2a34ce81
Comment 5 Aleix Pol 2012-06-20 13:00:11 UTC
my bad, I used the wrong bug ID's.

sorry about that