Skip to content

Commit 94fc8bc

Browse files
committed
Refine node value determination for number and non-translatable types
1 parent 6d73750 commit 94fc8bc

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/parser/tree.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Parser, { type SyntaxNode } from "tree-sitter";
22
import { i18nFunctions } from "../const.js";
3-
43
import { Block, SetOfBlocks } from "gettext-merger";
54
import { getParser } from "../fs/glob.js";
65
import { reverseSlashes, stripTranslationMarkup } from "../utils/common.js";
@@ -103,8 +102,10 @@ export function doTree(
103102
// set up the parser
104103
const parser = new Parser();
105104
const parserExt = getParser(filepath);
105+
106106
// if no parser is found return empty
107107
if (!parserExt) return new SetOfBlocks([], filepath);
108+
108109
// set the parser language
109110
parser.setLanguage(parserExt);
110111

@@ -212,18 +213,15 @@ export function doTree(
212213
// the translation key (eg. msgid)
213214
const currentKey = translationKeys[
214215
translationKeyIndex
215-
] as keyof typeof translation;
216+
] as keyof typeof translation;
216217

217218
// Resolve the value using our new function (handles quotes and escapes)
218219
let nodeValue: string = resolveStringValue(node);
219220

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') {
224222
// `number` accepts any value, this will not be provided in the POT file
225223
nodeValue = node.text;
226-
} else {
224+
} else if (!node?.type || !stringType.includes(node.type)) {
227225
// Whenever we get an unexpected node type this string is not translatable and should be skipped
228226
if (debugEnabled) {
229227
console.error(

0 commit comments

Comments
 (0)