forked from vinumeris/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-strings.js
More file actions
executable file
·40 lines (34 loc) · 1.88 KB
/
Copy pathextract-strings.js
File metadata and controls
executable file
·40 lines (34 loc) · 1.88 KB
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
#!/usr/bin/env jjs -scripting
// Tool to extract strings from source code and merge them into the pot file. We use this to automate execution of
// the xgettext tool and to properly handle strings in FXML.
//
// This is written in Nashorn-flavoured Javascript. Nashorn is a Javascript engine that ships with JDK 8.
//
// Useful language extensions we get in this mode include:
//
// - bash style backtick callouts to the shell
// - shorter lambda forms
// - for each loops
// - use of Java APIs
"use strict";
var Files = java.nio.file.Files;
var Paths = java.nio.file.Paths;
var files = `find client/src/main/resources/lighthouse -name *.fxml`.split("\n").filter(function(i) i != "");
var output = "";
for each (var file in files) {
var xml = new org.xml.sax.InputSource(file);
var xpath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
var results = xpath.evaluate("//@*[starts-with(., '%')]", xml, javax.xml.xpath.XPathConstants.NODESET);
for (var i = 0; i < results.getLength(); i++) {
output += "_(\"" + results.item(i).value.replace(/\n/g, "\\n").substr(1) + "\")";
output += "\n";
}
}
$EXEC("xgettext -k_ -cTRANS --no-location --language=C /dev/stdin -o i18n/lighthouse.pot --join-existing --from-code=UTF-8", output);
$EXEC("xargs xgettext -ktr -cTRANS --no-location --language=Java -o i18n/lighthouse.pot --join-existing --from-code=UTF-8", `find client -name *.java`);
// We need this disgusting hack because Kotlin treats $s in strings specially and requires escaping to avoid it.
// This doesn't play nicely with positional parameters. So pre-process each .kt file here. See KT-7258.
for each (var kt in `find client -name *.kt`.split("\n")) {
var processedKT = $EXEC("cat " + kt).replace(/\\\$/g, "$");
$EXEC("xgettext -ktr -cTRANS --no-location --language=Java -o i18n/lighthouse.pot --join-existing --from-code=UTF-8 /dev/stdin", processedKT);
}