|
1 | 1 | import Parser, { type SyntaxNode } from "tree-sitter"; |
2 | 2 | import { i18nFunctions } from "../const.js"; |
3 | | - |
4 | 3 | import { Block, SetOfBlocks } from "gettext-merger"; |
5 | 4 | import { getParser } from "../fs/glob.js"; |
6 | 5 | import { reverseSlashes, stripTranslationMarkup } from "../utils/common.js"; |
@@ -103,8 +102,10 @@ export function doTree( |
103 | 102 | // set up the parser |
104 | 103 | const parser = new Parser(); |
105 | 104 | const parserExt = getParser(filepath); |
| 105 | + |
106 | 106 | // if no parser is found return empty |
107 | 107 | if (!parserExt) return new SetOfBlocks([], filepath); |
| 108 | + |
108 | 109 | // set the parser language |
109 | 110 | parser.setLanguage(parserExt); |
110 | 111 |
|
@@ -212,18 +213,15 @@ export function doTree( |
212 | 213 | // the translation key (eg. msgid) |
213 | 214 | const currentKey = translationKeys[ |
214 | 215 | translationKeyIndex |
215 | | - ] as keyof typeof translation; |
| 216 | + ] as keyof typeof translation; |
216 | 217 |
|
217 | 218 | // Resolve the value using our new function (handles quotes and escapes) |
218 | 219 | let nodeValue: string = resolveStringValue(node); |
219 | 220 |
|
220 | | - if (node?.type && stringType.includes(node.type)) { |
221 | | - // unquote the strings |
222 | | - nodeValue = nodeValue.slice(1, -1); |
223 | | - } else if (currentKey === 'number'){ |
| 221 | + if (currentKey === 'number') { |
224 | 222 | // `number` accepts any value, this will not be provided in the POT file |
225 | 223 | nodeValue = node.text; |
226 | | - } else { |
| 224 | + } else if (!node?.type || !stringType.includes(node.type)) { |
227 | 225 | // Whenever we get an unexpected node type this string is not translatable and should be skipped |
228 | 226 | if (debugEnabled) { |
229 | 227 | console.error( |
|
0 commit comments