[sawfish: 1/6] Fix the awful find-lang-string.



commit da85568030135d30da9bad1a2be97e9f911cbffc
Author: Timo Korvola <tkorvola iki fi>
Date:   Tue Sep 22 18:06:30 2009 +0300

    Fix the awful find-lang-string.
    
    It was just too ugly.

 lisp/sawfish/wm/ext/fdo-menu.jl |   42 ++++++++++++++------------------------
 1 files changed, 16 insertions(+), 26 deletions(-)
---
diff --git a/lisp/sawfish/wm/ext/fdo-menu.jl b/lisp/sawfish/wm/ext/fdo-menu.jl
index 4673259..dc12e06 100644
--- a/lisp/sawfish/wm/ext/fdo-menu.jl
+++ b/lisp/sawfish/wm/ext/fdo-menu.jl
@@ -128,33 +128,23 @@
        (string
 	(substring string 0 (- (length string) 1)))))
 
+    ;; This is wrong.  Read the desktop entry spec to see how it should
+    ;; be done.  It's complicated.
     (define (find-lang-string)
-      (cond
-       ((getenv "LANGUAGE")
-	(let ((mlang (getenv "LANGUAGE")))
-	  (if (>= (length mlang) 2)
-	      (if (>= (length mlang) 5)
-		  (substring mlang 0 5)
-		(substring mlang 0 2)) "xx")))
-       ((getenv "LC_ALL")
-	(let ((mlang (getenv "LC_ALL")))
-	  (if (>= (length mlang) 2)
-	      (if (>= (length mlang) 5)
-		  (substring mlang 0 5)
-		(substring mlang 0 2)) "xx")))
-       ((getenv "LC_MESSAGES")
-	(let ((mlang (getenv "LC_MESSAGES")))
-	  (if (>= (length mlang) 2)
-	      (if (>= (length mlang) 5)
-		  (substring mlang 0 5)
-		(substring mlang 0 2)) "xx")))
-       ((getenv "LANG")
-	(let ((mlang (getenv "LANG")))
-	  (if (>= (length mlang) 2)
-	      (if (>= (length mlang) 5)
-		  (substring mlang 0 5)
-		(substring mlang 0 2)) "xx")))
-       (t "xx")))
+      (define (simplify mlang)
+        ;; N.B.: returns nil if mlang is "C" or "POSIX",
+        ;; "fi" if it is "finnish", "sw" if it is "swedish"
+        ;; Swedes can set locale to "sv_SE" or start learning Swahili.
+        (and (string-looking-at "([a-z][a-z])(_..)?" mlang)
+             (expand-last-match "\\0")))
+      (or
+       (let loop ((lang-vars '("LC_ALL" "LC_MESSAGES" "LANG")))
+            (and lang-vars
+                 (let ((mlang (getenv (car lang-vars))))
+                   (if mlang (simplify mlang)
+                     (loop (cdr lang-vars))))))
+       ;; Kluge to keep braindead code from breaking.
+       "xx"))
 
     ;; Variables that can be set in .sawfish[/]rc    
     



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