@tim-greller/xgettext-regex 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/xgettext-regex.js +1 -1
- package/index.js +13 -2
- package/package.json +1 -1
package/bin/xgettext-regex.js
CHANGED
|
@@ -16,7 +16,7 @@ var outFile = argv.o || argv.outfile
|
|
|
16
16
|
var opts = {
|
|
17
17
|
fn: (argv.f || argv.fn)
|
|
18
18
|
}
|
|
19
|
-
if (argv.r || argv.regex) opts.regex = new RegExp(argv.r || argv.regex, '
|
|
19
|
+
if (argv.r || argv.regex) opts.regex = new RegExp(argv.r || argv.regex, 'gs')
|
|
20
20
|
if (argv.i || argv.index) opts.regexTextCaptureIndex = argv.i || argv.index
|
|
21
21
|
|
|
22
22
|
if (argv._.length) {
|
package/index.js
CHANGED
|
@@ -50,7 +50,7 @@ function createDuplexStream (filename, opts) {
|
|
|
50
50
|
* \) closing paranthesis
|
|
51
51
|
* ) end of positive lookahead
|
|
52
52
|
*/
|
|
53
|
-
opts.regex = opts.regex || new RegExp("(?<=" + opts.fn + "\\(\\s*(?:(?:\"(?:[^\"]|\\\\.)*\"|'(?:[^']|\\\\.)*')\\s*,\\s*)*)(([\"'])(?:(?=(\\\\?))\\3.)*?\\2)(?=(?:\\s*,\\s*(?:\"(?:[^\"]|\\\\.)*\"|'(?:[^']|\\\\.)*'|[^\"')]+))*\\s*\\))", '
|
|
53
|
+
opts.regex = opts.regex || new RegExp("(?<=" + opts.fn + "\\(\\s*(?:(?:\"(?:[^\"]|\\\\.)*\"|'(?:[^']|\\\\.)*')\\s*,\\s*)*)(([\"'])(?:(?=(\\\\?))\\3.)*?\\2)(?=(?:\\s*,\\s*(?:\"(?:[^\"]|\\\\.)*\"|'(?:[^']|\\\\.)*'|[^\"')]+))*\\s*\\))", 'gs')
|
|
54
54
|
opts.regexTextCaptureIndex = opts.regexTextCaptureIndex || 1
|
|
55
55
|
|
|
56
56
|
var chunks = []
|
|
@@ -83,11 +83,22 @@ function createDuplexStream (filename, opts) {
|
|
|
83
83
|
text = '"' + text.replace(/"/g, '\\"') + '"'
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// handle triple-quoted string (java code blocks)
|
|
87
|
+
if (text.slice(0, 3) == '"""') {
|
|
88
|
+
text = text
|
|
89
|
+
.slice(3, -3)
|
|
90
|
+
.replace(/^\r?\n\s*/, '') // remove initial new line
|
|
91
|
+
.replace(/\\\r?\n\s*/g, '') // escaped linebreak + indent
|
|
92
|
+
.replace(/\r?\n\s*/g, '\\n') // normal linebreak + indent
|
|
93
|
+
text = `"${text}"`
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
this.push([
|
|
87
97
|
``,
|
|
88
98
|
`#: ${relativeFilename}:${lineNum}`,
|
|
89
99
|
`msgid ${text}`,
|
|
90
|
-
`msgstr ${text}
|
|
100
|
+
`msgstr ${text}`,
|
|
101
|
+
``
|
|
91
102
|
].join('\n'))
|
|
92
103
|
}
|
|
93
104
|
|