Skip to content

Commit d54768c

Browse files
author
MBriedis
committed
Fix UTF-8 handling for VueJs scanner.
1 parent 207719c commit d54768c

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
@@ -548,6 +548,18 @@ public function testVueJs2MultipleDomainScanning()
548548
}
549549
}
550550

551+
public function testVueJsUtf8Scanning()
552+
{
553+
$translations = new Translations();
554+
555+
VueJs::fromFile(static::asset('vuejs3/input.vue'), $translations);
556+
557+
self::assertCount(2, $translations);
558+
559+
self::assertNotFalse($translations->find('', 'Let’s test ā ūtf8 štriņģ ❤️'));
560+
self::assertNotFalse($translations->find('', 'We’re happy to have you here, 愛'));
561+
}
562+
551563
public function testXliffUnitIds()
552564
{
553565
$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)