Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UTF-8 handling for VueJs scanner. #242

Merged
merged 3 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>