nani/website/tools/list.scm

list.scm

1
;;; Nani Project website
2
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
3
;;;
4
;;; This file is part of the Nani Project website.
5
;;;
6
;;; The Nani Project website is free software; you can redistribute it and/or modify it
7
;;; under the terms of the GNU Affero General Public License as published by
8
;;; the Free Software Foundation; either version 3 of the License, or (at
9
;;; your option) any later version.
10
;;;
11
;;; The Nani Project website is distributed in the hope that it will be useful, but
12
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
;;; GNU Affero General Public License for more details.
15
;;;
16
;;; You should have received a copy of the GNU Affero General Public License
17
;;; along with the Nani Project website.  If not, see <http://www.gnu.org/licenses/>.
18
19
(use-modules (tools i18n))
20
(use-modules (nani radk))
21
(use-modules (nani jmdict serialize))
22
(use-modules (gcrypt hash))
23
(use-modules (ice-9 match))
24
(use-modules (ice-9 format))
25
(use-modules (ice-9 binary-ports))
26
27
(define* (description dico #:key (long? #f) (lang "en"))
28
  (define radk-synopsis
29
    `(_ "Radical to Kanji dictionary from the Electronic Dictionary Research and Development Group."))
30
  (define radk-description
31
    `(_ "This dictionary allows you to enter kanji by selecting some of its
32
    components.  Tap the water component button on the bottom of the screen to
33
    access the kanji selection by component view"))
34
35
  (define wadoku-synopsis
36
    `(_ "Japanese/German dictionary from Wadoku."))
37
  (define wadoku-description
38
    `(_ "This dictionary allows you to do searches on the main view of this app.
39
        Failing to download on of these dictionaries will make the app unusable
40
        as you can't search for anything.  This dictionary can be searched for
41
        by kanji, reading (kana) and by German translation."))
42
43
  (define (jmdict-synopsis lang)
44
    (match lang
45
      ("e" `(_ "Japanese/English dictionary from the Electronic Dictionary Research and Development Group."))
46
      ("dut" `(_ "Japanese/Dutch dictionary from the Electronic Dictionary Research and Development Group."))
47
      ("fre" `(_ "Japanese/French dictionary from the Electronic Dictionary Research and Development Group."))
48
      ("ger" `(_ "Japanese/German dictionary from the Electronic Dictionary Research and Development Group."))
49
      ("hun" `(_ "Japanese/Hungarian dictionary from the Electronic Dictionary Research and Development Group."))
50
      ("rus" `(_ "Japanese/Russian dictionary from the Electronic Dictionary Research and Development Group."))
51
      ("slv" `(_ "Japanese/Slovenian dictionary from the Electronic Dictionary Research and Development Group."))
52
      ("spa" `(_ "Japanese/Spanish dictionary from the Electronic Dictionary Research and Development Group."))
53
      ("swe" `(_ "Japanese/Swedish dictionary from the Electronic Dictionary Research and Development Group."))))
54
  (define (jmdict-description lang)
55
    `(_ "This dictionary allows you to do searches on the main view of this app.
56
        Failing to download one of these dictionaries will make the app unusable
57
        as you can't search for anything.  This dictionary can be searched for by
58
        kanji, reading (kana) and by meaning in the languages you selected."))
59
60
  (let* ((english
61
          (cond
62
            ((equal? (dico-type dico) "radk")
63
             (if long?
64
                 radk-description
65
                 radk-synopsis))
66
            ((equal? (dico-type dico) "wadoku")
67
             (if long?
68
                 wadoku-description
69
                 wadoku-synopsis))
70
            ((equal? (dico-type dico) "jmdict")
71
             (let ((dico-lang (substring dico 7)))
72
               (if long?
73
                   (jmdict-description dico-lang)
74
                   (jmdict-synopsis dico-lang))))))
75
         (translated (translate english lang)))
76
    (if (and (equal? english translated) (not (equal? lang "en")))
77
        #f
78
        translated)))
79
80
(define (filesize file)
81
  (stat:size (stat file)))
82
83
(define (sha256 file)
84
  (define hash (file-sha256 file))
85
  (apply
86
    string-append
87
    (map
88
      (lambda (n)
89
        (format #f "~2,'0x" n))
90
      (array->list hash))))
91
92
(define (dico-type file)
93
  (cond
94
    ((equal? file "radicals") "radk")
95
    ((and (> (string-length file) 6) (equal? (substring file 0 6) "JMdict"))
96
     "jmdict")
97
    ((equal? file "wadoku_ger") "wadoku")))
98
99
(define (entries file)
100
  (cond
101
    ((equal? (dico-type (dico-name file)) "radk")
102
     (kanji-count file))
103
    ((member (dico-type (dico-name file)) '("jmdict" "wadoku"))
104
     (jmdict-entry-count file))))
105
106
(define (dico-name file)
107
  (basename file ".nani"))
108
109
(match (command-line)
110
  ((_ output dicos ...)
111
   (with-output-to-file output
112
     (lambda _
113
       (for-each
114
         (lambda (dico)
115
           (let* ((sha256 (sha256 dico))
116
                  (size (filesize dico))
117
                  (name (dico-name dico))
118
                  (type (dico-type name))
119
                  (entry-count (entries dico)))
120
             (format #t "[~a]~%" name)
121
             (for-each
122
               (lambda (lang)
123
                 (let ((synopsis (description name #:lang lang))
124
                       (description (description name #:lang lang #:long? #t)))
125
                   (when synopsis
126
                     (format #t "synopsis=~a=~a~%" lang synopsis))
127
                   (when description
128
                     (format #t "description=~a=~a~%" lang description))))
129
               (filter (lambda (lang) (not (equal? lang ""))) languages))
130
             (format #t "sha256=~a~%" sha256)
131
             (format #t "size=~a~%" size)
132
             (format #t "type=~a~%" type)
133
             (format #t "entries=~a~%" entry-count)
134
             (format #t "url=~a~%" (string-append "https://nani.lepiller.eu/" dico))
135
             (format #t "~%")))
136
         dicos)))))
137