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

@transifex/cli: Detect Vue3 script setup #208

Merged
merged 1 commit into from
Jan 11, 2024
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
7 changes: 7 additions & 0 deletions packages/cli/src/api/parsers/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ function vueElementVisitor(HASHES, relativeFile, options) {
function extractVuePhrases(HASHES, source, relativeFile, options) {
// Use the vue-template-compiler API to parse content
const vueContent = vueTemplateCompiler.parse(source);

// Get the JS Content from the file and extract hashes/phrases with Babel
if (vueContent.descriptor.script && vueContent.descriptor.script.content) {
const script = vueContent.descriptor.script.content;
babelExtractPhrases(HASHES, script, relativeFile, options);
}

// Also detect Vue3 script setup
if (vueContent.descriptor.scriptSetup && vueContent.descriptor.scriptSetup.content) {
const script = vueContent.descriptor.scriptSetup.content;
babelExtractPhrases(HASHES, script, relativeFile, options);
}

// Get the template content from the file and extract hashes/phrases with
// custom traverse function
if (vueContent.descriptor.template && vueContent.descriptor.template.content) {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/test/api/extract.hashedkeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ describe('extractPhrases with hashed keys', () => {
string: 'Text 5',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
'39bcf931264f8a4de0d4c993ba8e7094': {
string: 'Text 6',
d42dd30c271a7dc6ecfaddd2cee7e457: {
string: 'Text in script',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
'2d97d5484416727f585501ee9f842ab1': {
string: 'Text in script setup',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
});
Expand Down
12 changes: 8 additions & 4 deletions packages/cli/test/api/extract.sourcekeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ describe('extractPhrases with source keys', () => {
string: 'Text 5',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
'Text 6': {
string: 'Text 6',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
'Text 7': {
meta: {
context: [],
Expand Down Expand Up @@ -528,6 +524,14 @@ describe('extractPhrases with source keys', () => {
},
string: 'Text 9 with siblings',
},
'Text in script': {
string: 'Text in script',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
'Text in script setup': {
string: 'Text in script setup',
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
},
});
});
});
13 changes: 12 additions & 1 deletion packages/cli/test/fixtures/vuejs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,23 @@
/>
</div>
</template>

<script>
import { defineComponent } from '@vue/composition-api'

export default defineComponent({
setup() {
t('Text 6')
t('Text in script')
},
})
</script>

<script setup>
import { defineComponent } from '@vue/composition-api'

export default defineComponent({
setup() {
t('Text in script setup')
},
})
</script>
Loading