Skip to content

Commit c272f3c

Browse files
authored
Allow TS extensions (#7)
Typescript file scanning added (same as JS, just different extension), minor fixes.
1 parent 0c490df commit c272f3c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/MessageExtractor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class MessageExtractor
2424
{
2525
const EXTRACTORS = [
2626
'js' => JsCode::class,
27+
'ts' => JsCode::class,
2728
'vue' => VueJs::class,
2829
'php' => PhpCode::class,
2930
];

src/MessageStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private function isJsFile(string $filename): bool
334334
{
335335
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
336336

337-
return in_array($extension, ['vue', 'js'], true);
337+
return in_array($extension, ['vue', 'js', 'ts'], true);
338338
}
339339

340340
/**

tests/TestCases/JsMessageTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testExtract()
4040
$translationsByDomain = $this->scanner->extract([
4141
new ScanItem($this->getDummyFile('js/dummy.js')), // 1 JS message
4242
new ScanItem($this->getDummyFile('js/dummy.vue')), // 2 JS messages
43+
new ScanItem($this->getDummyFile('js/dummy-ts.ts')),
4344
new ScanItem($this->getDummyFile('dummy-file.php')), // PHP messages, should be ignored
4445
]);
4546

@@ -55,9 +56,10 @@ public function testExtract()
5556

5657
$translations = $this->storage->getEnabledTranslatedJs('en_US', 'domain');
5758

58-
self::assertCount(3, $translations, '3 translations extracted');
59-
self::assertNotFalse($translations->find('ctx', 'JS 1'), 'Translation found');
60-
self::assertNotFalse($translations->find('', 'JS 2'), 'Translation found');
61-
self::assertNotFalse($translations->find('', 'JS 3'), 'Translation found');
59+
self::assertCount(4, $translations, 'The number of translations extracted does not match');
60+
self::assertNotFalse($translations->find('ctx', 'JS 1'), 'Translation not found');
61+
self::assertNotFalse($translations->find('', 'JS 2'), 'Translation not found');
62+
self::assertNotFalse($translations->find('', 'JS 3'), 'Translation not found');
63+
self::assertNotFalse($translations->find('', 'JS TS'), 'Translation not found');
6264
}
6365
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(function () {
2+
'use strict';
3+
alert(gettext('JS TS'));
4+
})();

0 commit comments

Comments
 (0)