mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix(Scripts): extract string, avoid if has already t() + /* NO EXTRACT SCRIPT */
This commit is contained in:
1 parent
3f8d2db9b9
commit
c30d598d77
4 files changed
+19
-3
No files matched your search
@@ -48,9 +48,22 @@ function processVueComponent(filePath, toolName) {
|
||||
return `${attr}: t('tools.${toolName}.texts.${key}')`;
|
||||
});
|
||||
|
||||
if (content.includes("/* NO EXTRACT SCRIPT */")) {
|
||||
console.log(`Marked to not extract: ${filePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const hasAlreayI18n = filePath.endsWith('.vue')
|
||||
? content.includes("const { t } = useI18n();")
|
||||
: content.includes("import { translate as t } from '@/plugins/i18n.plugin';");
|
||||
if (hasAlreayI18n) {
|
||||
console.log(`Already extracted: ${filePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (filePath.endsWith('.vue')) {
|
||||
// Regex to find label or placeholder attributes
|
||||
regex = /(?<!:)((?:input-|output-)?(?:label|placeholder|title))="([^"]+)"/g;
|
||||
regex = /(?<!:)((?:[a-z]+-)?(?:label|placeholder|title))="([^"]+)"/g;
|
||||
content = content.replace(regex, (match, attr, text) => {
|
||||
if (!text?.trim()) {
|
||||
return match;
|
||||
@@ -88,13 +101,13 @@ function processVueComponent(filePath, toolName) {
|
||||
|
||||
if (filePath.endsWith('.vue')) {
|
||||
// Ensure the useI18n import exists
|
||||
if (!content.includes("const { t } = useI18n();")) {
|
||||
if (!hasAlreayI18n) {
|
||||
content = content.replace(/\<script setup( lang="ts")?\>/, "<script setup lang=\"ts\">\nimport { useI18n } from 'vue-i18n';\nconst { t } = useI18n();");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Ensure the useI18n import exists
|
||||
if (!content.includes("import { translate as t } from '@/plugins/i18n.plugin';")) {
|
||||
if (!hasAlreayI18n) {
|
||||
content = 'import { translate as t } from "@/plugins/i18n.plugin";\n' + content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
/* NO EXTRACT SCRIPT */
|
||||
import { defineComponent, ref } from 'vue';
|
||||
import { downloadLinks } from './multi-link-downloader.service';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
/* NO EXTRACT SCRIPT */
|
||||
import PomodoroApp from './app/PomodoroApp.vue';
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
/* NO EXTRACT SCRIPT */
|
||||
const allowedDomains = ref<string[]>([]);
|
||||
const allowedIPv4s = ref<string[]>([]);
|
||||
const allowedIPv6s = ref<string[]>([]);
|
||||
|
||||
Reference in new issue
Block a user