[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace
From:       Chusslove Illich <caslav.ilic () gmx ! net>
Date:       2008-03-02 20:16:50
Message-ID: 1204489010.168333.11990.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 781416 by ilic:

i18n for startup splash themes.

 M  +2 -3      ksplash/ksplashx/README  
 M  +47 -2     ksplash/ksplashx/splash.cpp  
 M  +14 -2     kstartupconfig/kdostartupconfig.cpp  
 M  +6 -0      startkde.cmake  


--- trunk/KDE/kdebase/workspace/ksplash/ksplashx/README #781415:781416
@@ -8,9 +8,8 @@
 
 LIMITATIONS:
 This implementation can only draw images and animations. This means that
-e.g. texts need to be pre-rendered into images. There is currently no
-support for i18n but if needed it could be easily added by first trying
-images in a certain locale-named directory.
+e.g. texts need to be pre-rendered into images. i18n support is however
+provided by mimicking KLocale's mechanism for localizing non-text resources.
 
 
 USAGE:
--- trunk/KDE/kdebase/workspace/ksplash/ksplashx/splash.cpp #781415:781416
@@ -44,6 +44,7 @@
 #include <string.h>
 #include <assert.h>
 #include <dirent.h>
+#include <libgen.h>
 
 #include <X11/Xutil.h>
 
@@ -233,11 +234,55 @@
     }
 
 // returns a pointer to a static !
+static const char* findLocalizedFileWithDepth( const char* name, int* w, int* h, bool locolor )
+    {
+    const int bufsz = 1024;
+
+    // Split name into dirname and basename.
+    char name2[ bufsz ];
+    strncpy( name2, name, bufsz );
+    name2[ bufsz - 1 ] = '\0';
+    char* basn = basename( name2 ); // must preceed dirname
+    char* dirn = dirname( name2 ); // modifies name2
+
+    // Check for localized file by parsing languages from KLOCALE_LANGUAGES,
+    // as provided by startkde via kstartupconfig4. It contains list of
+    // language codes, colon-separated and ordered by decreasing priority.
+    const char* lvarname = "KLOCALE_LANGUAGES";
+    if( getenv( lvarname ) && getenv( lvarname )[ 0 ] )
+        {
+        char lvar[ bufsz ];
+        strncpy( lvar, getenv( lvarname ), bufsz );
+        lvar[ bufsz - 1 ] = '\0';
+
+        // Go through colon-separated list of languages.
+        char* lang = strtok( lvar, ":" );
+        while( 1 )
+            {
+            char locname[ bufsz ];
+            snprintf( locname, bufsz, "%s/l10n/%s/%s", dirn, lang, basn );
+            locname[ bufsz - 1 ] = '\0';
+
+            // Check if this path exists.
+            const char* path = findFileWithDepth( locname, w, h, locolor );
+            if( path[ 0 ] )
+                return path;
+
+            if( ( lang = strtok( 0, ":" ) ) == 0 )
+                break;
+            }
+        }
+
+    // Fall back to unlocalized file.
+    return findFileWithDepth( name, w, h, locolor );
+    }
+
+// returns a pointer to a static !
 static const char* findFile( const char* name, int* w = NULL, int* h = NULL, bool* locolor = NULL )
     {
     if( x11Depth() <= 8 )
         {
-        if( const char* ret = findFileWithDepth( name, w, h, true )) // try locolor
+        if( const char* ret = findLocalizedFileWithDepth( name, w, h, true )) // try locolor
             {
             if( locolor != NULL )
                 *locolor = true;
@@ -246,7 +291,7 @@
         }
     if( locolor != NULL )
         *locolor = false;
-    return findFileWithDepth( name, w, h, false ); // no locolor
+    return findLocalizedFileWithDepth( name, w, h, false ); // no locolor
     }
 
 // If a properly sized image doesn't exist save it in the cache location
--- trunk/KDE/kdebase/workspace/kstartupconfig/kdostartupconfig.cpp #781415:781416
@@ -32,6 +32,9 @@
 #include <kconfig.h>
 #include <kconfiggroup.h>
 #include <kdebug.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
 
 
 #if defined _WIN32 || defined _WIN64
@@ -67,10 +70,15 @@
     return ret;
     }
 
-int main()
+int main( int argc, char **argv )
     {
-    KComponentData inst( "kdostartupconfig" );
+    #define I18N_NOEXTRACT( x ) ki18n( x )
+    // Set catalog to "kdelibs4" for KLocale to initialize languages properly.
+    KAboutData about( "kdostartupconfig4", "kdelibs4",
+                      I18N_NOEXTRACT( "kdostartupconfig4" ), "1.0" );
+    KComponentData inst( &about );
     kDebug() << "Running kdostartupconfig.";
+    KCmdLineArgs::init( argc, argv, &about ); // for KLocale not to complain about encoding
     QString keysname = KStandardDirs::locateLocal( "config", "startupconfigkeys" );
     QFile keys( keysname );
     if( !keys.open( QIODevice::ReadOnly ))
@@ -152,5 +160,9 @@
             }
         startupconfigfiles << "*\n";
         }
+
+        // Get languages by priority from KLocale.
+        QStringList langs = KGlobal::locale()->languageList();
+        startupconfig << "klocale_languages=" << langs.join( ":" ) << "\n";
     return 0;
     }
--- trunk/KDE/kdebase/workspace/startkde.cmake #781415:781416
@@ -78,6 +78,7 @@
 kcmrandrrc [Screen2]
 kcmrandrrc [Screen3]
 kcmfonts General forceFontDPI 0
+kdeglobals Locale Language '' # trigger requesting languages from KLocale
 EOF
 kstartupconfig4
 if test $? -ne 0; then
@@ -159,6 +160,9 @@
 
 ksplash_pid=
 if test -z "$dl"; then
+  # languages as resolved by KLocale, for the splash screens use
+  # klocale_languages is assembled by kdostartupconfig4 calling KLocale
+  export KLOCALE_LANGUAGES="$klocale_languages"
   # the splashscreen and progress indicator
   case "$ksplashrc_ksplash_engine" in
     KSplashX)
@@ -172,6 +176,8 @@
     *)
       ;;
   esac
+  # no longer needed in the environment
+  unset KLOCALE_LANGUAGES
 fi
 
 # Source scripts found in <localprefix>/env/*.sh and <prefixes>/env/*.sh
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic