Skip to content

Commit fabc8b9

Browse files
author
Oscar Otero
authored
Merge pull request #242 from briedis/vuejs-utf8-fix
Fix UTF-8 handling for VueJs scanner.
2 parents 494237c + f695cde commit fabc8b9

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/Extractors/VueJs.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ protected static function convertHtmlToDom($html)
165165
$dom = new DOMDocument;
166166

167167
libxml_use_internal_errors(true);
168-
$dom->loadHTML($html);
168+
169+
// Prepend xml encoding so DOMDocument document handles UTF8 correctly.
170+
// Assuming that vue template files will not have any xml encoding tags, because duplicate tags may be ignored.
171+
$dom->loadHTML('<?xml encoding="utf-8"?>' . $html);
169172

170173
libxml_clear_errors();
171174

tests/AssetsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,18 @@ public function testMissingDomainScanWithOtherStringsInFile()
557557
self::assertCount(0, $translations);
558558
}
559559

560+
public function testVueJsUtf8Scanning()
561+
{
562+
$translations = new Translations();
563+
564+
VueJs::fromFile(static::asset('vuejs3/input.vue'), $translations);
565+
566+
self::assertCount(2, $translations);
567+
568+
self::assertNotFalse($translations->find('', 'Let’s test ā ūtf8 štriņģ 😎️'));
569+
self::assertNotFalse($translations->find('', 'We’re happy to have you here, 愛'));
570+
}
571+
560572
public function testXliffUnitIds()
561573
{
562574
$translations = static::get('xliff/Xliff', 'Xliff', ['unitid_as_id' => true]);

tests/assets/vuejs3/input.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
{{ __('Let’s test ā ūtf8 štriņģ 😎️') }}
3+
</template>
4+
5+
<script>
6+
export default {
7+
computed: {
8+
buttonText() {
9+
return __('We’re happy to have you here, 愛');
10+
}
11+
},
12+
}
13+
</script>

0 commit comments

Comments
 (0)