View Issue Details

IDProjectCategoryView StatusLast Update
0000760CATS.cacert.orgAdmin Interfacepublic2011-07-27 21:18
ReporterJ Steijlen Assigned ToTed  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionwon't fix 
Summary0000760: adding UI languages - a different approach
DescriptionRead/contemplate add_dutch_UI_translation.patch first.
https://bugs.cacert.org/view.php?id=759


No more hardcoding (well.. less anyway), just drop a file in the appropriate place and (re)build the translation lists.

Uh, and update the new and improved "questiontype_v2" table of course.
(We should add a commented INSERT statement at the top of the language files. To ease work for the unlucky admin having to include/update an UI language.)
Additional InformationApplying a decent set_error_handler makes this a setup to do
        try{
            try{
                include_once (sprintf("lang/%s.php", $_SESSION['profile']['language']));
            }
            catch(){
                /* translation apparently does not exist
                   load default (english) language pack */
            }
        }
        catch(){
            /* complete failure */
        }
If that translation exists, load it. Otherwise load default.
TagsNo tags attached.

Relationships

related to 0000759 closedTed Dutch translation of the UI 

Activities

2009-07-24 19:06

 

UI_translation_-_add_translation_-_another_approach.patch (3,105 bytes)   
Read/contemplate add_dutch_UI_translation.patch first.
Note that this diff is against SVN.


Applying a decent set_error_handler makes this a setup to do
		try{
			try{
				include_once (sprintf("lang/%s.php", $_SESSION['profile']['language']));
			}
			catch(){
				/* translation apparently does not exist
				   load default (english) language pack */
			}
		}
		catch(){
			/* complete failure */
		}
If that translation exists, load it. Otherwise load default.

No more hardcoding, just drop a file in the appropriate place and (re)build the translation lists.
Uh, and update the new and improved "questiontype_v2" table of course.
(We should add a commented INSERT statement at the top of the language files)


Index: CATS/functions/translation.php
===================================================================
--- CATS/functions/translation.php	(revision 1641)
+++ CATS/functions/translation.php	(working copy)
@@ -2,12 +2,32 @@
 
  function getlang(){
 
-  if(isset($_SESSION['profile']['language']) && $_SESSION['profile']['language']=='DE'){
-   include_once ("lang/german.php");      
+/* could be made even cleaner by proper use of set_error_handler & errorexception
+   http://nl3.php.net/manual/en/class.errorexception.php#errorexception.examples */
+  try{
+    function loadlangfile($s){
+      if(file_exists($s)){
+        include_once ($s);
+      }
+      else{
+        throw new Exception("can't load file");
+      }	 
+    }
+    try{
+      switch($_SESSION['profile']['language']){
+        case "DE" :  loadlangfile ("lang/german.php"); break;
+        case "NL" :  loadlangfile ("lang/dutch.php"); break;
+        default :  throw new Exception("no translation available?"); break; 
+      }
+    }
+    catch(Exception $e){
+    	/* log error somehow? */
+      loadlangfile("lang/english.php");
+    }	 
+  }
+  catch(Exception $e){
+    die("can\'t load ANY language file");
   }
-  else{
-   include_once ("lang/english.php");  
-  }
  
  }
  
Index: CATS/index.php.template
===================================================================
--- CATS/index.php.template	(revision 1641)
+++ CATS/index.php.template	(working copy)
@@ -56,10 +56,16 @@
 ?><div id="language">
  <form action="index.php" method="post">
   <div>
-  <select size="1" class="dropdown_language" name="language">
+  <select size="1" class="dropdown_language" name="language">
    <option value="none">choose language</option>
-   <option value="DE">DE</option>
-   <option value="EN">EN</option>
+   <optgroup label="Default">
+	   <option value="EN">EN</option>
+   </optgroup>
+   <optgroup label="Other languages">
+<?php
+	include_once("lang/langpacks.php");
+?>
+   </optgroup>
   </select><input name="submit" class="language_Button" type="submit" value="change" />
   </div>
  </form><?php
Index: CATS/lang/langpacks.php
===================================================================
--- CATS/lang/langpacks.php	(revision 0)
+++ CATS/lang/langpacks.php	(revision 0)
@@ -0,0 +1,2 @@
+     <option value="DE">DE</option>
+     <option value="NL">NL</option>

Ted

2009-07-28 20:36

administrator   ~0001467

I prefer the hardcoded switch case list. It's easier to understand and, believe me, the list won't be getting really long... ;)

Issue History

Date Modified Username Field Change
2009-07-24 19:06 J Steijlen New Issue
2009-07-24 19:06 J Steijlen File Added: UI_translation_-_add_translation_-_another_approach.patch
2009-07-28 20:32 Ted Relationship added related to 0000759
2009-07-28 20:36 Ted Note Added: 0001467
2009-07-28 20:36 Ted Assigned To => Ted
2009-07-28 20:36 Ted Status new => solved?
2009-07-28 20:36 Ted Resolution open => won't fix
2011-07-27 21:18 Ted Status solved? => closed