Skip to content

Commit

Permalink
Merge pull request #242 from briedis/vuejs-utf8-fix
Browse files Browse the repository at this point in the history
Fix UTF-8 handling for VueJs scanner.
  • Loading branch information
oscarotero authored Dec 2, 2019
2 parents 494237c + f695cde commit fabc8b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Extractors/VueJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ protected static function convertHtmlToDom($html)
$dom = new DOMDocument;

libxml_use_internal_errors(true);
$dom->loadHTML($html);

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

libxml_clear_errors();

Expand Down
12 changes: 12 additions & 0 deletions tests/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,18 @@ public function testMissingDomainScanWithOtherStringsInFile()
self::assertCount(0, $translations);
}

public function testVueJsUtf8Scanning()
{
$translations = new Translations();

VueJs::fromFile(static::asset('vuejs3/input.vue'), $translations);

self::assertCount(2, $translations);

self::assertNotFalse($translations->find('', 'Let’s test ā ūtf8 štriņģ 😎️'));
self::assertNotFalse($translations->find('', 'We’re happy to have you here, 愛'));
}

public function testXliffUnitIds()
{
$translations = static::get('xliff/Xliff', 'Xliff', ['unitid_as_id' => true]);
Expand Down
13 changes: 13 additions & 0 deletions tests/assets/vuejs3/input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
{{ __('Let’s test ā ūtf8 štriņģ 😎️') }}
</template>

<script>
export default {
computed: {
buttonText() {
return __('We’re happy to have you here, 愛');
}
},
}
</script>

0 comments on commit fabc8b9

Please sign in to comment.