mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 22:07:10 -04:00
Added Chinese version
Added Chinese version
This commit is contained in:
parent
d037338a23
commit
730a68b92a
466 changed files with 31255 additions and 0 deletions
91
zh-CN/src/modules/command-palette/command-palette.store.ts
Normal file
91
zh-CN/src/modules/command-palette/command-palette.store.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import _ from 'lodash';
|
||||
import type { PaletteOption } from './command-palette.types';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
import SunIcon from '~icons/mdi/white-balance-sunny';
|
||||
import GithubIcon from '~icons/mdi/github';
|
||||
import BugIcon from '~icons/mdi/bug-outline';
|
||||
import DiceIcon from '~icons/mdi/dice-5';
|
||||
import InfoIcon from '~icons/mdi/information-outline';
|
||||
|
||||
export const useCommandPaletteStore = defineStore('command-palette', () => {
|
||||
const toolStore = useToolStore();
|
||||
const styleStore = useStyleStore();
|
||||
const router = useRouter();
|
||||
const searchPrompt = ref('');
|
||||
|
||||
const toolsOptions = toolStore.tools.map(tool => ({
|
||||
...tool,
|
||||
to: tool.path,
|
||||
toolCategory: tool.category,
|
||||
category: 'Tools',
|
||||
}));
|
||||
|
||||
const searchOptions: PaletteOption[] = [
|
||||
...toolsOptions,
|
||||
{
|
||||
name: 'Random tool',
|
||||
description: 'Get a random tool from the list.',
|
||||
action: () => {
|
||||
const { path } = _.sample(toolStore.tools)!;
|
||||
router.push(path);
|
||||
},
|
||||
icon: DiceIcon,
|
||||
category: 'Tools',
|
||||
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
||||
closeOnSelect: true,
|
||||
},
|
||||
{
|
||||
name: 'Toggle dark mode',
|
||||
description: 'Toggle dark mode on or off.',
|
||||
action: () => styleStore.toggleDark(),
|
||||
icon: SunIcon,
|
||||
category: 'Actions',
|
||||
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
||||
},
|
||||
{
|
||||
name: 'Github repository',
|
||||
href: 'https://github.com/angelofan/it-tools',
|
||||
category: 'External',
|
||||
description: 'View the source code of it-tools on Github.',
|
||||
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
||||
icon: GithubIcon,
|
||||
},
|
||||
{
|
||||
name: 'Report a bug or an issue',
|
||||
description: 'Report a bug or an issue to help improve it-tools.',
|
||||
href: 'https://github.com/angelofan/it-tools/issues/new/choose',
|
||||
category: 'Actions',
|
||||
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
||||
icon: BugIcon,
|
||||
},
|
||||
{
|
||||
name: 'About',
|
||||
description: 'Learn more about IT-Tools.',
|
||||
to: '/about',
|
||||
category: 'Pages',
|
||||
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
||||
icon: InfoIcon,
|
||||
},
|
||||
];
|
||||
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: searchPrompt,
|
||||
data: searchOptions,
|
||||
options: {
|
||||
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
||||
threshold: 0.3,
|
||||
},
|
||||
});
|
||||
|
||||
const filteredSearchResult = computed(() =>
|
||||
_.chain(searchResult.value).groupBy('category').mapValues(categoryOptions => _.take(categoryOptions, 5)).value());
|
||||
|
||||
return {
|
||||
filteredSearchResult,
|
||||
searchPrompt,
|
||||
};
|
||||
});
|
14
zh-CN/src/modules/command-palette/command-palette.types.ts
Normal file
14
zh-CN/src/modules/command-palette/command-palette.types.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import type { Component } from 'vue';
|
||||
import type { RouteLocationRaw } from 'vue-router';
|
||||
|
||||
export interface PaletteOption {
|
||||
name: string
|
||||
description?: string
|
||||
icon?: Component
|
||||
action?: () => void
|
||||
to?: RouteLocationRaw
|
||||
category: string
|
||||
keywords?: string[]
|
||||
href?: string
|
||||
closeOnSelect?: boolean
|
||||
}
|
154
zh-CN/src/modules/command-palette/command-palette.vue
Normal file
154
zh-CN/src/modules/command-palette/command-palette.vue
Normal file
|
@ -0,0 +1,154 @@
|
|||
<script setup lang="ts">
|
||||
import { storeToRefs } from 'pinia';
|
||||
import _ from 'lodash';
|
||||
import { useCommandPaletteStore } from './command-palette.store';
|
||||
import type { PaletteOption } from './command-palette.types';
|
||||
|
||||
const isModalOpen = ref(false);
|
||||
const inputRef = ref();
|
||||
const router = useRouter();
|
||||
const isMac = computed(() => window.navigator.userAgent.toLowerCase().includes('mac'));
|
||||
|
||||
const commandPaletteStore = useCommandPaletteStore();
|
||||
const { searchPrompt, filteredSearchResult } = storeToRefs(commandPaletteStore);
|
||||
|
||||
const keys = useMagicKeys({
|
||||
passive: false,
|
||||
onEventFired(e) {
|
||||
if (e.ctrlKey && e.key === 'k' && e.type === 'keydown') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (e.metaKey && e.key === 'k' && e.type === 'keydown') {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
whenever(isModalOpen, () => inputRef.value?.focus());
|
||||
|
||||
whenever(keys.ctrl_k, open);
|
||||
whenever(keys.meta_k, open);
|
||||
whenever(keys.escape, close);
|
||||
|
||||
function open() {
|
||||
return isModalOpen.value = true;
|
||||
}
|
||||
|
||||
function close() {
|
||||
isModalOpen.value = false;
|
||||
searchPrompt.value = '';
|
||||
}
|
||||
|
||||
const selectedOptionIndex = ref(0);
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
const { key } = event;
|
||||
const isEnterPressed = key === 'Enter';
|
||||
const isArrowUpOrDown = ['ArrowUp', 'ArrowDown'].includes(key);
|
||||
const isArrowDown = key === 'ArrowDown';
|
||||
|
||||
if (isArrowUpOrDown) {
|
||||
const increment = isArrowDown ? 1 : -1;
|
||||
const maxIndex = Math.max(_.chain(filteredSearchResult.value).values().flatten().size().value() - 1, 0);
|
||||
|
||||
selectedOptionIndex.value = Math.min(Math.max(selectedOptionIndex.value + increment, 0), maxIndex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnterPressed) {
|
||||
const option = _.chain(filteredSearchResult.value)
|
||||
.values()
|
||||
.flatten()
|
||||
.nth(selectedOptionIndex.value)
|
||||
.value();
|
||||
|
||||
activateOption(option);
|
||||
}
|
||||
}
|
||||
|
||||
function getOptionIndex(option: PaletteOption) {
|
||||
return _.chain(filteredSearchResult.value)
|
||||
.values()
|
||||
.flatten()
|
||||
.findIndex(o => o === option)
|
||||
.value();
|
||||
}
|
||||
|
||||
function activateOption(option: PaletteOption) {
|
||||
const { closeOnSelect } = option;
|
||||
|
||||
if (option.action) {
|
||||
option.action();
|
||||
|
||||
if (closeOnSelect) {
|
||||
close();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const closeAfterNavigation = closeOnSelect || _.isUndefined(closeOnSelect);
|
||||
|
||||
if (option.to) {
|
||||
router.push(option.to);
|
||||
|
||||
if (closeAfterNavigation) {
|
||||
close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (option.href) {
|
||||
window.open(option.href, '_blank');
|
||||
|
||||
if (closeAfterNavigation) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div flex-1>
|
||||
<c-button w-full important:justify-start @click="isModalOpen = true">
|
||||
<span flex items-center gap-3 op-40>
|
||||
|
||||
<icon-mdi-search />
|
||||
{{ $t('search.label') }}
|
||||
|
||||
<span hidden flex-1 border border-current border-op-40 rounded border-solid px-5px py-3px sm:inline>
|
||||
{{ isMac ? 'Cmd' : 'Ctrl' }} + K
|
||||
</span>
|
||||
</span>
|
||||
</c-button>
|
||||
|
||||
<c-modal v-model:open="isModalOpen" class="palette-modal" shadow-xl important:max-w-650px important:pa-12px @keydown="handleKeydown">
|
||||
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text placeholder="搜索工具或命令..." autofocus clearable />
|
||||
|
||||
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
||||
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
||||
{{ category }}
|
||||
</div>
|
||||
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
|
||||
</div>
|
||||
</c-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.c-input-text {
|
||||
font-size: 18px;
|
||||
|
||||
::v-deep(.input-wrapper) {
|
||||
padding: 4px;
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.c-modal--overlay {
|
||||
align-items: flex-start !important;
|
||||
padding-top: 80px;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,36 @@
|
|||
<script setup lang="ts">
|
||||
import type { PaletteOption } from '../command-palette.types';
|
||||
|
||||
const props = withDefaults(defineProps<{ option: PaletteOption; selected?: boolean }>(), {
|
||||
selected: false,
|
||||
});
|
||||
const emit = defineEmits(['activated']);
|
||||
const { option } = toRefs(props);
|
||||
|
||||
const { selected } = toRefs(props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
role="option"
|
||||
:aria-selected="selected"
|
||||
:class="{
|
||||
'text-white': selected,
|
||||
'bg-primary': selected,
|
||||
}"
|
||||
w-full flex cursor-pointer items-center overflow-hidden rounded pa-3 transition hover:bg-primary hover:text-white
|
||||
@click="() => emit('activated', option)"
|
||||
>
|
||||
<component :is="option.icon" v-if="option.icon" mr-3 h-30px w-30px shrink-0 op-50 />
|
||||
|
||||
<div flex-1 overflow-hidden>
|
||||
<div truncate font-bold lh-tight op-90>
|
||||
{{ option.name }}
|
||||
</div>
|
||||
|
||||
<div v-if="option.description" truncate lh-tight op-60>
|
||||
{{ option.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
28
zh-CN/src/modules/i18n/components/locale-selector.vue
Normal file
28
zh-CN/src/modules/i18n/components/locale-selector.vue
Normal file
|
@ -0,0 +1,28 @@
|
|||
<script setup lang="ts">
|
||||
const { availableLocales, locale } = useI18n();
|
||||
|
||||
const localesLong: Record<string, string> = {
|
||||
en: 'English',
|
||||
es: 'Español',
|
||||
fr: 'Français',
|
||||
pt: 'Português',
|
||||
ru: 'Русский',
|
||||
zh: '中文',
|
||||
};
|
||||
|
||||
const localeOptions = computed(() =>
|
||||
availableLocales.map(locale => ({
|
||||
label: localesLong[locale] ?? locale,
|
||||
value: locale,
|
||||
})),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-select
|
||||
v-model:value="locale"
|
||||
:options="localeOptions"
|
||||
placeholder="Select a language"
|
||||
w-100px
|
||||
/>
|
||||
</template>
|
7
zh-CN/src/modules/shared/date.models.ts
Normal file
7
zh-CN/src/modules/shared/date.models.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { format } from 'date-fns';
|
||||
|
||||
export { getUrlFriendlyDateTime };
|
||||
|
||||
function getUrlFriendlyDateTime({ date = new Date() }: { date?: Date } = {}) {
|
||||
return format(date, 'yyyy-MM-dd-HH-mm-ss');
|
||||
}
|
5
zh-CN/src/modules/shared/number.models.ts
Normal file
5
zh-CN/src/modules/shared/number.models.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
function clamp({ value, min = 0, max = 100 }: { value: number; min?: number; max?: number }) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
export { clamp };
|
27
zh-CN/src/modules/tracker/tracker.services.ts
Normal file
27
zh-CN/src/modules/tracker/tracker.services.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import _ from 'lodash';
|
||||
import type Plausible from 'plausible-tracker';
|
||||
import { inject } from 'vue';
|
||||
|
||||
export { createTrackerService, useTracker };
|
||||
|
||||
function createTrackerService({ plausible }: { plausible: ReturnType<typeof Plausible> }) {
|
||||
return {
|
||||
trackEvent({ eventName }: { eventName: string }) {
|
||||
plausible.trackEvent(eventName);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useTracker() {
|
||||
const plausible: ReturnType<typeof Plausible> | undefined = inject('plausible');
|
||||
|
||||
if (_.isNil(plausible)) {
|
||||
throw new TypeError('Plausible must be instantiated');
|
||||
}
|
||||
|
||||
const tracker = createTrackerService({ plausible });
|
||||
|
||||
return {
|
||||
tracker,
|
||||
};
|
||||
}
|
3
zh-CN/src/modules/tracker/tracker.types.ts
Normal file
3
zh-CN/src/modules/tracker/tracker.types.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import type { createTrackerService } from './tracker.services';
|
||||
|
||||
export type TrackerService = ReturnType<typeof createTrackerService>;
|
Loading…
Add table
Add a link
Reference in a new issue