| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | |
| 20 | |
| 21 | |
| 22 |
|
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 |
|
| 28 | (use-modules (guix build po)
|
| 29 | (ice-9 match)
|
| 30 | (ice-9 textual-ports))
|
| 31 |
|
| 32 | (define (escape str)
|
| 33 | "Escape msgid or msgstr. Replace by C-style escape sequences."
|
| 34 | (let* ((in (open-input-string str))
|
| 35 | (text (get-string-all in))
|
| 36 | (escaped-text-as-list
|
| 37 | (string-fold-right
|
| 38 | (lambda (char result)
|
| 39 | (cons (case char
|
| 40 | ((#\") "\\\"")
|
| 41 | ((#\\) "\\\\")
|
| 42 | ((#\linefeed) "\\n")
|
| 43 | ((#\return) "\\r")
|
| 44 | ((#\tab) "\\t")
|
| 45 | (else (string char)))
|
| 46 | result))
|
| 47 | '()
|
| 48 | text))
|
| 49 | (escaped-text (apply string-append escaped-text-as-list)))
|
| 50 | (display escaped-text)))
|
| 51 |
|
| 52 | (match (command-line)
|
| 53 | ((program pofile)
|
| 54 | (let ((input (open-input-file pofile)))
|
| 55 | |
| 56 | (letrec ((copy
|
| 57 | (lambda ()
|
| 58 | (let ((next-line (get-line input)))
|
| 59 | (display next-line)
|
| 60 | (newline)
|
| 61 | (when (> (string-length next-line) 0)
|
| 62 | (copy))))))
|
| 63 | (copy))
|
| 64 | |
| 65 | (for-each
|
| 66 | (lambda (msg)
|
| 67 | (match msg
|
| 68 | ((msgid . msgstr)
|
| 69 | (display "msgid \"")
|
| 70 | (escape msgid)
|
| 71 | (display "\"")
|
| 72 | (newline)
|
| 73 | (display "msgstr \"")
|
| 74 | (escape msgstr)
|
| 75 | (display "\"")
|
| 76 | (newline)
|
| 77 | (newline))))
|
| 78 | (read-po-file input)))))
|