|
| 1 | +<script setup> |
| 2 | +import { ref } from 'vue'; |
| 3 | +import { useQueryParamOrStorage } from '@/composable/queryParams'; |
| 4 | +
|
| 5 | +const query = ref(''); |
| 6 | +const language = useQueryParamOrStorage({ name: 'lang', storageName: 'wiktionary:l', defaultValue: 'en' }); |
| 7 | +
|
| 8 | +// Extend this list as needed |
| 9 | +const languageOptions = [ |
| 10 | + { label: 'English', value: 'en' }, |
| 11 | + { label: 'French', value: 'fr' }, |
| 12 | + { label: 'German', value: 'de' }, |
| 13 | + { label: 'Spanish', value: 'es' }, |
| 14 | + { label: 'Italian', value: 'it' }, |
| 15 | + { label: 'Russian', value: 'ru' }, |
| 16 | + { label: 'Chinese', value: 'zh' }, |
| 17 | + { label: 'Japanese', value: 'ja' }, |
| 18 | + { label: 'Arabic', value: 'ar' }, |
| 19 | +]; |
| 20 | +
|
| 21 | +const iframeUrl = ref(''); |
| 22 | +function openSearch() { |
| 23 | + const encoded = encodeURIComponent(query.value.trim()); |
| 24 | + iframeUrl.value = `https://${language.value}.wiktionary.org/wiki/Special:Search?search=${encoded}`; |
| 25 | +} |
| 26 | +</script> |
| 27 | + |
| 28 | +<template> |
| 29 | + <div> |
| 30 | + <n-form-item label="" label-placement="left"> |
| 31 | + <n-input |
| 32 | + v-model:value="query" |
| 33 | + placeholder="Enter a word…" |
| 34 | + clearable |
| 35 | + mr-1 |
| 36 | + /> |
| 37 | + |
| 38 | + <n-select |
| 39 | + v-model:value="language" |
| 40 | + :options="languageOptions" |
| 41 | + placeholder="Select a language" |
| 42 | + filterable |
| 43 | + /> |
| 44 | + </n-form-item> |
| 45 | + |
| 46 | + <n-space justify="center"> |
| 47 | + <n-button |
| 48 | + type="primary" |
| 49 | + :disabled="!query || !language" |
| 50 | + @click="openSearch" |
| 51 | + > |
| 52 | + Search on Wiktionary |
| 53 | + </n-button> |
| 54 | + </n-space> |
| 55 | + |
| 56 | + <n-divider /> |
| 57 | + |
| 58 | + <div style="height: 70vh; border: 1px solid #ddd; border-radius: 6px; overflow: hidden;"> |
| 59 | + <iframe |
| 60 | + v-if="iframeUrl" |
| 61 | + :src="iframeUrl" |
| 62 | + style="width: 100%; height: 100%; border: none;" |
| 63 | + /> |
| 64 | + <div v-else style="padding: 1rem; text-align: center; color: #888;"> |
| 65 | + Enter a word and select a language to load Wiktionary |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | +</template> |
0 commit comments