[patch] load i18n versions of commands/reccmds.conf

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

 



Hi,

I'd like to propose a patch for further i18n of VDR, namely in the
commands.conf and reccmds.conf files. Even if any user can customize
these files to his whishes (and language), I think that it is more
consistent from the VDR user interface point of view if the commands
defined there also change their language on the OSD, according to the
OSD language setting.
All that the user has to do, is to provide, additionally to the "normal"
files commands.conf and reccmds.conf, the version(s) in the language(s)
he want's to use as commands.conf.xyz and reccmds.conf.xyz, where ".xyz"
is the 3-characters language code defined in VDR's i18n.c:

  // The 3-letter names of the language...
  { "eng,dos",
    "deu,ger",
    "slv,slo",
    "ita",
    "dut,nla,nld",
    "por",
    "fra,fre",
    "nor",
    "fin,smi",
    "pol",
    "esl,spa",
    "ell,gre",
    "sve,swe",
    "rom,rum",
    "hun",
    "cat,cln",
    "rus",
    "hrv",
    "est",
    "dan",
  },

Important notes:
- There is *no problem* if VDR does not find such translated command
files at startup or at OSD language switching on the fly, it will always
fall back to the default and if those are missing, as you  already know,
it's not a big deal either, so the behaviour doesn't change (except that
there is a syslog message if such a customized file hasn't been found,
just to inform users who are reading the logs, that *they could have*
multiple command file versions according to configured OSD language, for
english setups it#s absolutely silent as before);
- this will only work with the *first* name for languages where multiple
3-letter names are defined;
- As english is all over in VDR's source code specially treated, this
makes no exception here, so it's indeed treated specially: english files
need *no* such 3-letter extension, and are *only* loaded in their
default form.

Have phun,
Lucian
-------------- next part --------------
diff -Naur vdr-1.3.36_orig/config.c vdr-1.3.36/config.c
--- vdr-1.3.36_orig/config.c	2005-09-09 17:08:59.000000000 +0200
+++ vdr-1.3.36/config.c	2005-11-14 13:19:45.010000000 +0100
@@ -16,6 +16,8 @@
 #include "plugin.h"
 #include "recording.h"
 
+const char *ConfigDirectory = NULL;
+
 // IMPORTANT NOTE: in the 'sscanf()' calls there is a blank after the '%d'
 // format characters in order to allow any number of blanks after a numeric
 // value!
@@ -535,3 +537,31 @@
      }
   return false;
 }
+
+bool LoadCommandsI18n(cCommands & cmds, const char *FileName, bool AllowComments, bool MustExist)
+{
+    bool bRet = true;
+    bool bLoadDefault = (Setup.OSDLanguage == 0);
+    if (!bLoadDefault) {
+	// attempt to load a translated file
+	char LangCode[4];
+	strncpy(LangCode, I18nLanguageCode(Setup.OSDLanguage), 3);
+	LangCode[3] = '\0';
+	char *FullPath = NULL;
+	asprintf(&FullPath, "%s/%s.%s", ConfigDirectory && *ConfigDirectory ? ConfigDirectory : ".", FileName, LangCode);
+
+	if (!cmds.Load((FullPath), AllowComments, true)) { // require to exist, just to be able to log
+	    // fallback
+	    bLoadDefault = true;
+	    esyslog("Failed to load translated '%s.%s' for language %d (%s)", FileName, LangCode, Setup.OSDLanguage, I18nLanguages()[Setup.OSDLanguage]);
+	    esyslog("Falling back to default '%s' (if any)", FileName);
+	}
+	free(FullPath);
+    }
+    if (bLoadDefault) {
+	// let's do it the normal way
+	bRet = cmds.Load(AddDirectory(ConfigDirectory, FileName), AllowComments, MustExist);
+    }
+    // return status only for the default commands file
+    return bRet;
+}
diff -Naur vdr-1.3.36_orig/config.h vdr-1.3.36/config.h
--- vdr-1.3.36_orig/config.h	2005-11-04 16:55:05.000000000 +0100
+++ vdr-1.3.36/config.h	2005-11-14 13:16:13.170000000 +0100
@@ -34,6 +34,8 @@
 #define MaxSkinName 16
 #define MaxThemeName 16
 
+extern const char *ConfigDirectory;
+
 class cCommand : public cListObject {
 private:
   char *title;
@@ -265,4 +267,6 @@
 
 extern cSetup Setup;
 
+bool LoadCommandsI18n(cCommands & cmds, const char *FileName = NULL, bool AllowComments = false, bool MustExist = false);
+
 #endif //__CONFIG_H
diff -Naur vdr-1.3.36_orig/menu.c vdr-1.3.36/menu.c
--- vdr-1.3.36_orig/menu.c	2005-11-05 18:29:22.000000000 +0100
+++ vdr-1.3.36/menu.c	2005-11-14 13:21:47.450000000 +0100
@@ -1910,6 +1910,10 @@
      Setup.OSDLanguage = data.OSDLanguage;
      cFont::SetCode(I18nCharSets()[Setup.OSDLanguage]);
 
+     // try to load translated command files if available, otherwise fallback to defaults
+     LoadCommandsI18n(Commands, "commands.conf", true);
+     LoadCommandsI18n(RecordingCommands, "reccmds.conf", true);
+
      cSkin *Skin = Skins.Get(skinIndex);
      if (Skin) {
         char *d = themes.NumThemes() ? strdup(themes.Descriptions()[themeIndex]) : NULL;
diff -Naur vdr-1.3.36_orig/vdr.c vdr-1.3.36/vdr.c
--- vdr-1.3.36_orig/vdr.c	2005-11-04 14:48:39.000000000 +0100
+++ vdr-1.3.36/vdr.c	2005-11-14 13:21:32.700000000 +0100
@@ -109,7 +109,6 @@
 
   int SVDRPport = DEFAULTSVDRPPORT;
   const char *AudioCommand = NULL;
-  const char *ConfigDirectory = NULL;
   const char *EpgDataFileName = DEFAULTEPGDATAFILENAME;
   bool DisplayHelp = false;
   bool DisplayVersion = false;
@@ -420,8 +419,9 @@
         Diseqcs.Load(AddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC) &&
         Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"), false, true) &&
         Timers.Load(AddDirectory(ConfigDirectory, "timers.conf")) &&
-        Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"), true) &&
-        RecordingCommands.Load(AddDirectory(ConfigDirectory, "reccmds.conf"), true) &&
+        // try to load translated command files if available, otherwise fallback to defaults
+        LoadCommandsI18n(Commands, "commands.conf", true) &&
+        LoadCommandsI18n(RecordingCommands, "reccmds.conf", true) &&
         SVDRPhosts.Load(AddDirectory(ConfigDirectory, "svdrphosts.conf"), true) &&
         CaDefinitions.Load(AddDirectory(ConfigDirectory, "ca.conf"), true) &&
         Keys.Load(AddDirectory(ConfigDirectory, "remote.conf")) &&

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux