/
core.clj
43 lines (35 loc) · 1.25 KB
/
core.clj
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(ns pottery.core
(:require [pottery.po :as po]
[pottery.scan :as scan]
[clojure.java.io :as io]))
(defn- default-scan-options []
{:dir "src"
:extract-fn #'scan/default-extractor
:template-file (io/file "resources/gettext/template.pot")})
(defmacro make-extractor
"Returns an extraction function using the core.match pattern syntax.
Example:
(make-extractor
['tr s] s
['trn [s1 s2] _] [s1 s2]) "
[& args]
`(scan/make-extractor ~@args))
(defn scan-codebase!
"Recursively reads the code in dir, scans all strings and outputs a
.pot file according to the gettext format with all the translatable
strings.
Opts is a map which accepts:
:dir - The source dir to be scanned.
:extract-fn - The extraction function that gets called with every
expression in the codebase
:template-file - The POT file where the results are to be written.
All of these options have defaults."
([] (scan-codebase! {}))
([opts]
(let [{:keys [template-file] :as opts} (merge (default-scan-options) opts)]
(io/make-parents template-file)
(->> (scan/scan-files opts)
(po/gen-template)
(spit template-file)))))
(def read-po-file #'po/read-po-file)
(def read-po-str #'po/read-po-str)