/
generate_pot.elv
executable file
·54 lines (44 loc) · 1.12 KB
/
generate_pot.elv
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
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env elvish
local:workdir = cache
local:alldir = all
local:transdir = kcp
if ?(test -e $workdir) {
rm -rf $workdir
}
mkdir $workdir
local:ignored = "^(vendor|resources|cache|build|"$workdir")"
fn extract_all []{
i18n4go -c extract-strings -v --po -d . -r -o $workdir/$alldir --ignore-regexp $ignored -output-match-package
}
fn extract_trans []{
put **/consts.go | each [file]{
local:d = $workdir/$transdir/(dirname $file)
i18n4go -c extract-strings -v --po -f $file -o $d --ignore-regexp $ignored
}
}
fn merge_json [d]{
i18n4go -c merge-strings -d $workdir/$d -r -source-language en
local:json = []
put $workdir/$d/**/en.all.json | each [f]{
local:j = (cat $f | from-json)
@j = (all $j | each [e]{ dissoc $e modified })
@json = $@json $@j
}
put $json | to-json > $workdir/$d/kcp.json
}
fn convert_json [d]{
json2po -P $workdir/$d/kcp.{json,pot}
}
fn merge_po [d]{
xgettext -o $workdir/$d/kcp.pot $workdir/$d/**.po
}
if (> (count $args) 0) {
local:e = $args[0]
if (is $e --all) {
extract_all
merge_json $alldir
merge_po $alldir
}
}
extract_trans
merge_po $transdir