Skip to content

Commit 05f7955

Browse files
author
Nikos Vasileiou
committed
@transifex/cli Detect Vue script setup
1 parent 831b71d commit 05f7955

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

packages/cli/src/api/parsers/vue.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,19 @@ function vueElementVisitor(HASHES, relativeFile, options) {
125125
function extractVuePhrases(HASHES, source, relativeFile, options) {
126126
// Use the vue-template-compiler API to parse content
127127
const vueContent = vueTemplateCompiler.parse(source);
128+
128129
// Get the JS Content from the file and extract hashes/phrases with Babel
129130
if (vueContent.descriptor.script && vueContent.descriptor.script.content) {
130131
const script = vueContent.descriptor.script.content;
131132
babelExtractPhrases(HASHES, script, relativeFile, options);
132133
}
133134

135+
// Also detect Vue3 script setup
136+
if (vueContent.descriptor.scriptSetup && vueContent.descriptor.scriptSetup.content) {
137+
const script = vueContent.descriptor.scriptSetup.content;
138+
babelExtractPhrases(HASHES, script, relativeFile, options);
139+
}
140+
134141
// Get the template content from the file and extract hashes/phrases with
135142
// custom traverse function
136143
if (vueContent.descriptor.template && vueContent.descriptor.template.content) {

packages/cli/test/api/extract.hashedkeys.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,12 @@ describe('extractPhrases with hashed keys', () => {
543543
string: 'Text 5',
544544
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
545545
},
546-
'39bcf931264f8a4de0d4c993ba8e7094': {
547-
string: 'Text 6',
546+
d42dd30c271a7dc6ecfaddd2cee7e457: {
547+
string: 'Text in script',
548+
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
549+
},
550+
'2d97d5484416727f585501ee9f842ab1': {
551+
string: 'Text in script setup',
548552
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
549553
},
550554
});

packages/cli/test/api/extract.sourcekeys.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,6 @@ describe('extractPhrases with source keys', () => {
484484
string: 'Text 5',
485485
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
486486
},
487-
'Text 6': {
488-
string: 'Text 6',
489-
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
490-
},
491487
'Text 7': {
492488
meta: {
493489
context: [],
@@ -528,6 +524,14 @@ describe('extractPhrases with source keys', () => {
528524
},
529525
string: 'Text 9 with siblings',
530526
},
527+
'Text in script': {
528+
string: 'Text in script',
529+
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
530+
},
531+
'Text in script setup': {
532+
string: 'Text in script setup',
533+
meta: { context: [], tags: [], occurrences: ['vuejs.vue'] },
534+
},
531535
});
532536
});
533537
});

packages/cli/test/fixtures/vuejs.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,23 @@
3535
/>
3636
</div>
3737
</template>
38+
3839
<script>
3940
import { defineComponent } from '@vue/composition-api'
4041
4142
export default defineComponent({
4243
setup() {
43-
t('Text 6')
44+
t('Text in script')
45+
},
46+
})
47+
</script>
48+
49+
<script setup>
50+
import { defineComponent } from '@vue/composition-api'
51+
52+
export default defineComponent({
53+
setup() {
54+
t('Text in script setup')
4455
},
4556
})
4657
</script>

0 commit comments

Comments
 (0)