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 kanji kanjidic)) |
21 | (use-modules (nani kanji radk)) |
22 | (use-modules (nani result result)) |
23 | (use-modules (nani pitch pitch)) |
24 | (use-modules (gcrypt hash)) |
25 | (use-modules (ice-9 match)) |
26 | (use-modules (ice-9 format)) |
27 | (use-modules (ice-9 binary-ports)) |
28 | |
29 | (define* (description dico #:key (long? #f) (lang "en")) |
30 | (define radk-synopsis |
31 | `(_ "Radical to Kanji dictionary from the Electronic Dictionary Research and Development Group.")) |
32 | (define radk-description |
33 | `(_ "This dictionary allows you to enter kanji by selecting some of its |
34 | components. Tap the water component button on the bottom of the screen to |
35 | access the kanji selection by component view")) |
36 | |
37 | (define wadoku-synopsis |
38 | `(_ "Japanese/German dictionary from Wadoku.")) |
39 | (define wadoku-description |
40 | `(_ "This dictionary allows you to do searches on the main view of this app. |
41 | Failing to download one of these dictionaries will make the app unusable |
42 | as you can't search for anything. This dictionary can be searched for |
43 | by kanji, reading (kana) and by German translation.")) |
44 | |
45 | (define wadoku-pitch-synopsis |
46 | `(_ "Pitch accent dictionary from Wadoku.")) |
47 | (define wadoku-pitch-description |
48 | `(_ "This dictionary allows you to augment search results on the main view |
49 | with pitch accent (pronunciation) information. Japanese is not flat, |
50 | and this dictionary will add information that will help you pronounce |
51 | words better, with a standard Japanese pitch accent.")) |
52 | |
53 | (define jibiki-synopsis |
54 | `(_ "Japanese/French dictionary from the Jibiki project.")) |
55 | (define jibiki-description |
56 | `(_ "This dictionary allows you to do searches on the main view of this app. |
57 | Failing to download one of these dictionaries will make the app unusable |
58 | as you can't search for anything. This dictionary can be searched for |
59 | by kanji, reading (kana) and by French translation.")) |
60 | |
61 | (define (jmdict-synopsis lang) |
62 | (match lang |
63 | ("e" `(_ "Japanese/English dictionary from the Electronic Dictionary Research and Development Group.")) |
64 | ("dut" `(_ "Japanese/Dutch dictionary from the Electronic Dictionary Research and Development Group.")) |
65 | ("fre" `(_ "Japanese/French dictionary from the Electronic Dictionary Research and Development Group.")) |
66 | ("ger" `(_ "Japanese/German dictionary from the Electronic Dictionary Research and Development Group.")) |
67 | ("hun" `(_ "Japanese/Hungarian dictionary from the Electronic Dictionary Research and Development Group.")) |
68 | ("rus" `(_ "Japanese/Russian dictionary from the Electronic Dictionary Research and Development Group.")) |
69 | ("slv" `(_ "Japanese/Slovenian dictionary from the Electronic Dictionary Research and Development Group.")) |
70 | ("spa" `(_ "Japanese/Spanish dictionary from the Electronic Dictionary Research and Development Group.")) |
71 | ("swe" `(_ "Japanese/Swedish dictionary from the Electronic Dictionary Research and Development Group.")))) |
72 | (define (jmdict-description lang) |
73 | `(_ "This dictionary allows you to do searches on the main view of this app. |
74 | Failing to download one of these dictionaries will make the app unusable |
75 | as you can't search for anything. This dictionary can be searched for by |
76 | kanji, reading (kana) and by meaning in the languages you selected.")) |
77 | |
78 | (define (kanjidic-synopsis lang) |
79 | (match lang |
80 | ("en" `(_ "Kanji dictionary with English meanings.")) |
81 | ("es" `(_ "Kanji dictionary with Spanish meanings.")) |
82 | ("fr" `(_ "Kanji dictionary with French meanings.")) |
83 | ("pt" `(_ "Kanji dictionary with Portuguese meanings.")))) |
84 | (define (kanjidic-description lang) |
85 | `(_ "This dictionary allows you to search for kanji and view kanji information |
86 | such as number of strokes, pronunciations and meanings.")) |
87 | |
88 | (let* ((english |
89 | (cond |
90 | ((equal? (dico-type dico) "radk") |
91 | (if long? |
92 | radk-description |
93 | radk-synopsis)) |
94 | ((equal? (dico-type dico) "kanjidic") |
95 | (let ((dico-lang (substring dico 9))) |
96 | (if long? |
97 | (kanjidic-description dico-lang) |
98 | (kanjidic-synopsis dico-lang)))) |
99 | ((equal? (dico-type dico) "wadoku") |
100 | (if long? |
101 | wadoku-description |
102 | wadoku-synopsis)) |
103 | ((equal? (dico-type dico) "wadoku_pitch") |
104 | (if long? |
105 | wadoku-pitch-description |
106 | wadoku-pitch-synopsis)) |
107 | ((equal? (dico-type dico) "jibiki") |
108 | (if long? |
109 | jibiki-description |
110 | jibiki-synopsis)) |
111 | ((equal? (dico-type dico) "jmdict") |
112 | (let ((dico-lang (substring dico 7))) |
113 | (if long? |
114 | (jmdict-description dico-lang) |
115 | (jmdict-synopsis dico-lang)))))) |
116 | (translated (translate english lang))) |
117 | (if (and (equal? english translated) (not (equal? lang "en"))) |
118 | #f |
119 | translated))) |
120 | |
121 | (define (filesize file) |
122 | (stat:size (stat file))) |
123 | |
124 | (define (sha256 file) |
125 | (define hash (file-sha256 file)) |
126 | (apply |
127 | string-append |
128 | (map |
129 | (lambda (n) |
130 | (format #f "~2,'0x" n)) |
131 | (array->list hash)))) |
132 | |
133 | (define (dico-type file) |
134 | (cond |
135 | ((equal? file "radicals") "radk") |
136 | ((and (> (string-length file) 8) (equal? (substring file 0 8) "kanjidic")) |
137 | "kanjidic") |
138 | ((and (> (string-length file) 6) (equal? (substring file 0 6) "JMdict")) |
139 | "jmdict") |
140 | ((equal? file "jibiki_fre") "jibiki") |
141 | ((equal? file "wadoku_ger") "wadoku") |
142 | ((equal? file "wadoku_pitch") "wadoku_pitch"))) |
143 | |
144 | (define (entries file) |
145 | (cond |
146 | ((equal? (dico-type (dico-name file)) "radk") |
147 | (kanji-count file)) |
148 | ((equal? (dico-type (dico-name file)) "kanjidic") |
149 | (kanjidic-entry-count file)) |
150 | ((member (dico-type (dico-name file)) '("jmdict" "wadoku" "jibiki")) |
151 | (dictionary-entry-count file)) |
152 | ((equal? (dico-type (dico-name file)) "wadoku_pitch") |
153 | (pitch-entry-count file)))) |
154 | |
155 | (define (dico-name file) |
156 | (basename file ".nani")) |
157 | |
158 | (define (dico-lang name) |
159 | (cond |
160 | ((equal? name "radicals") "") |
161 | ((equal? name "kanjidic") "") |
162 | ((equal? name "wadoku_pitch") "") |
163 | ((and (> (string-length name) 6) (equal? (substring name 0 6) "JMdict")) |
164 | (let ((lang (substring name 7))) |
165 | (match lang |
166 | ("e" "en") |
167 | ("dut" "nl") |
168 | ("fre" "fr") |
169 | ("ger" "de") |
170 | ("hun" "hu") |
171 | ("rus" "ru") |
172 | ("slv" "sl") |
173 | ("spa" "es") |
174 | ("swe" "sv")))) |
175 | ((equal? name "jibiki_fre") "fr") |
176 | ((equal? name "wadoku_ger") "de"))) |
177 | |
178 | (match (command-line) |
179 | ((_ output dicos ...) |
180 | (with-output-to-file output |
181 | (lambda _ |
182 | (for-each |
183 | (lambda (dico) |
184 | (let* ((sha256 (sha256 dico)) |
185 | (size (filesize dico)) |
186 | (name (dico-name dico)) |
187 | (lang (dico-lang name)) |
188 | (type (dico-type name)) |
189 | (entry-count (entries dico))) |
190 | (format #t "[~a]~%" name) |
191 | (for-each |
192 | (lambda (lang) |
193 | (let ((synopsis (description name #:lang lang)) |
194 | (description (description name #:lang lang #:long? #t))) |
195 | (when synopsis |
196 | (format #t "synopsis=~a=~a~%" lang synopsis)) |
197 | (when description |
198 | (format #t "description=~a=~a~%" lang description)))) |
199 | (filter (lambda (lang) (not (equal? lang ""))) languages)) |
200 | (format #t "lang=~a~%" lang) |
201 | (format #t "sha256=~a~%" sha256) |
202 | (format #t "size=~a~%" size) |
203 | (format #t "type=~a~%" type) |
204 | (format #t "entries=~a~%" entry-count) |
205 | (format #t "url=~a~%" (string-append "https://nani.lepiller.eu/" dico)) |
206 | (format #t "~%"))) |
207 | dicos))))) |
208 |