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