Output redirection now handles symlinks
[opus_libre.git] / lib / 30-readlang.scm
bloba31228e242d63226f96fce935efd5ffab9789989
1 ;------------------------------------------------------------------;
2 ; opus_libre -- 30-readlang.scm                                    ;
3 ;                                                                  ;
4 ; (c) 2008-2011 Valentin Villenave <valentin@villenave.net>        ;
5 ;                                                                  ;
6 ;     opus_libre is a free framework for GNU LilyPond: you may     ;
7 ; redistribute it and/or modify it under the terms of the GNU      ;
8 ; General Public License as published by the Free Software         ;
9 ; Foundation, either version 3 of the License, or (at your option) ;
10 ; any later version.                                               ;
11 ;     This program is distributed WITHOUT ANY WARRANTY; without    ;
12 ; even the implied warranty of MERCHANTABILITY or FITNESS FOR A    ;
13 ; PARTICULAR PURPOSE.  You should have received a copy of the GNU  ;
14 ; General Public License along with this program (typically in the ;
15 ; share/doc/ directory).  If not, see http://www.gnu.org/licenses/ ;
16 ;                                                                  ;
17 ;------------------------------------------------------------------;
20 ; Language selection.
22 (define eval-lang
23 ;;   "Look for a user-specified language, and load
24 ;; language files accordingly, first globally, then
25 ;; locally.  Note that the default language file,
26 ;; typically in etc/ly.conf.d/lang.conf, is always
27 ;; loaded (which allows for lighter language files
28 ;; that only define what needs to be overriden)."
29   (let* ((guess-lang
30            (let* ((port (open-input-pipe "locale | grep --color=never LANG"))
31                   (result (read-line port))
32                   (str (if (string? result)
33                            (car (reverse (string-split result #\=)))
34                            #f)))
35              (if str
36                  (set! str
37                        (if (>= (string-length str) 2)
38                            (string-take str 2)
39                            #f)))
40             (close-pipe port)
41             str))
42          (input-lang
43           (if (defined-string? 'input)
44               (ly:parser-lookup 'input)
45               (begin
46                 (ly:debug-message "Input language not defined.")
47                     (if guess-lang
48                         (begin
49                            (ly:debug-message "Using system's default: ~a"
50                                   guess-lang)
51                            guess-lang)
52                         (begin
53                            (ly:debug-message "Using default language: ~a"
54                                   conf:default-language)
55                            conf:default-language)))))
56          (input-lang-file
57           (string-append conf:locale-dir "/" input-lang ".conf"))
58          (local-lang-file
59           (string-append conf:local-conf-dir "/" input-lang ".conf"))
60          (load-lang-file
61           (lambda (f)
62             (if (exists? f)
63                 (begin
64                   (ly:debug-message "Loading language file ~a..." f)
65                   (parse-def-file f conf:lang-prefix))
66                 (ly:debug-message "Language file not found: ~a."
67                                 f)))))
68     (load-lang-file input-lang-file)
69     (load-lang-file local-lang-file)))