mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 13:34:04 +03:00
fix(i18n): tool search in current language and handle switching
Fix #486
This commit is contained in:
1 parent
be4d22587f
commit
e5a2017f7d
5 files changed
+168
-107
No files matched your search
@@ -9574,6 +9574,24 @@ tools:
|
|||||||
cidr-expands-to-hostcount-ips-exceeding-limit-of-max_cidr_ips: CIDR expands to {0} IPs, exceeding limit of {1}
|
cidr-expands-to-hostcount-ips-exceeding-limit-of-max_cidr_ips: CIDR expands to {0} IPs, exceeding limit of {1}
|
||||||
tag-reachable: Reachable
|
tag-reachable: Reachable
|
||||||
tag-unreachable: Unreachable
|
tag-unreachable: Unreachable
|
||||||
|
command-palette:
|
||||||
|
store:
|
||||||
|
texts:
|
||||||
|
pages: Pages
|
||||||
|
learn-more-about-it-tools: Learn more about IT-Tools.
|
||||||
|
actions-0: Actions
|
||||||
|
report-a-bug-or-an-issue-to-help-improve-it-tools: Report a bug or an issue to help improve it-tools.
|
||||||
|
report-a-bug-or-an-issue: Report a bug or an issue
|
||||||
|
view-the-source-code-of-it-tools-on-github: View the source code of it-tools on Github.
|
||||||
|
external: External
|
||||||
|
github-repository: Github repository
|
||||||
|
actions: Actions
|
||||||
|
toggle-dark-mode-on-or-off: Toggle dark mode on or off.
|
||||||
|
toggle-dark-mode: Toggle dark mode
|
||||||
|
tools-0: Tools
|
||||||
|
get-a-random-tool-from-the-list: Get a random tool from the list.
|
||||||
|
random-tool: Random tool
|
||||||
|
tools: Tools
|
||||||
collapsibleToolMenu:
|
collapsibleToolMenu:
|
||||||
text:
|
text:
|
||||||
expanding: Expanding...
|
expanding: Expanding...
|
||||||
|
|||||||
@@ -27,13 +27,15 @@ watchEffect(() => {
|
|||||||
document.documentElement.style.setProperty('--app-topbar-height', `${Math.round(navbarHeight.value)}px`);
|
document.documentElement.style.setProperty('--app-topbar-height', `${Math.round(navbarHeight.value)}px`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
|
|
||||||
const toolStore = useToolStore();
|
const toolStore = useToolStore();
|
||||||
const { favoriteTools, toolsByCategory } = storeToRefs(toolStore);
|
const { favoriteTools, toolsByCategory } = storeToRefs(toolStore);
|
||||||
|
|
||||||
const tools = computed<ToolCategory[]>(() => [
|
const tools = computed<ToolCategory[]>(() => [
|
||||||
...(favoriteTools.value.length > 0 ? [{ name: t('tools.categories.favorite-tools'), components: favoriteTools.value }] : []),
|
...(favoriteTools.value.length > 0
|
||||||
|
? [{ name: t('tools.categories.favorite-tools'), components: favoriteTools.value }]
|
||||||
|
: []),
|
||||||
...toolsByCategory.value,
|
...toolsByCategory.value,
|
||||||
]);
|
]);
|
||||||
</script>
|
</script>
|
||||||
@@ -44,9 +46,7 @@ const tools = computed<ToolCategory[]>(() => [
|
|||||||
<RouterLink to="/" class="hero-wrapper">
|
<RouterLink to="/" class="hero-wrapper">
|
||||||
<HeroGradient class="gradient" />
|
<HeroGradient class="gradient" />
|
||||||
<div class="text-wrapper">
|
<div class="text-wrapper">
|
||||||
<div class="title">
|
<div class="title">IT - TOOLS</div>
|
||||||
IT - TOOLS
|
|
||||||
</div>
|
|
||||||
<div class="divider" />
|
<div class="divider" />
|
||||||
<div class="subtitle">
|
<div class="subtitle">
|
||||||
{{ $t('home.subtitle') }}
|
{{ $t('home.subtitle') }}
|
||||||
@@ -109,12 +109,20 @@ const tools = computed<ToolCategory[]>(() => [
|
|||||||
</c-tooltip>
|
</c-tooltip>
|
||||||
|
|
||||||
<c-tooltip :tooltip="$t('home.uiLib')" position="bottom">
|
<c-tooltip :tooltip="$t('home.uiLib')" position="bottom">
|
||||||
<c-button v-if="config.app.env === 'development'" to="/c-lib" circle variant="text" :aria-label="$t('home.uiLib')">
|
<c-button
|
||||||
|
v-if="config.app.env === 'development'"
|
||||||
|
to="/c-lib"
|
||||||
|
circle
|
||||||
|
variant="text"
|
||||||
|
:aria-label="$t('home.uiLib')"
|
||||||
|
>
|
||||||
<icon-mdi:brush-variant text-20px />
|
<icon-mdi:brush-variant text-20px />
|
||||||
</c-button>
|
</c-button>
|
||||||
</c-tooltip>
|
</c-tooltip>
|
||||||
|
|
||||||
<command-palette />
|
<Suspense>
|
||||||
|
<command-palette :key="locale" />
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<NavbarButtons v-if="!styleStore.isSmallScreen" />
|
<NavbarButtons v-if="!styleStore.isSmallScreen" />
|
||||||
|
|||||||
@@ -11,85 +11,89 @@ import DiceIcon from '~icons/mdi/dice-5';
|
|||||||
import InfoIcon from '~icons/mdi/information-outline';
|
import InfoIcon from '~icons/mdi/information-outline';
|
||||||
import { useFlexSearch } from '@/composable/flexSearch';
|
import { useFlexSearch } from '@/composable/flexSearch';
|
||||||
|
|
||||||
|
import { translate as t } from '@/plugins/i18n.plugin';
|
||||||
|
|
||||||
const maxSearchResultsPerCategory = import.meta.env.VITE_MAX_SEARCH_RESULT || 25;
|
const maxSearchResultsPerCategory = import.meta.env.VITE_MAX_SEARCH_RESULT || 25;
|
||||||
|
|
||||||
export const useCommandPaletteStore = defineStore('command-palette', () => {
|
export const useCommandPaletteStore = (locale: string) =>
|
||||||
const toolStore = useToolStore();
|
defineStore(`command-palette-${locale}`, () => {
|
||||||
const styleStore = useStyleStore();
|
const toolStore = useToolStore();
|
||||||
const router = useRouter();
|
const styleStore = useStyleStore();
|
||||||
const searchPrompt = ref('');
|
const router = useRouter();
|
||||||
|
const searchPrompt = ref('');
|
||||||
|
|
||||||
const toolsOptions = toolStore.tools.map(tool => ({
|
const toolsOptions = toolStore.tools.map((tool) => ({
|
||||||
...tool,
|
...tool,
|
||||||
to: tool.path,
|
to: tool.path,
|
||||||
toolCategory: tool.category,
|
toolCategory: tool.category,
|
||||||
category: 'Tools',
|
category: t('tools.command-palette.store.texts.tools'),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const searchOptions: PaletteOption[] = [
|
const searchOptions: PaletteOption[] = [
|
||||||
...toolsOptions,
|
...toolsOptions,
|
||||||
{
|
{
|
||||||
name: 'Random tool',
|
name: t('tools.command-palette.store.texts.random-tool'),
|
||||||
description: 'Get a random tool from the list.',
|
description: t('tools.command-palette.store.texts.get-a-random-tool-from-the-list'),
|
||||||
action: () => {
|
action: () => {
|
||||||
const { path } = _.sample(toolStore.tools)!;
|
const { path } = _.sample(toolStore.tools)!;
|
||||||
router.push(path);
|
router.push(path);
|
||||||
|
},
|
||||||
|
icon: DiceIcon,
|
||||||
|
category: t('tools.command-palette.store.texts.tools-0'),
|
||||||
|
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
||||||
|
closeOnSelect: true,
|
||||||
},
|
},
|
||||||
icon: DiceIcon,
|
{
|
||||||
category: 'Tools',
|
name: t('tools.command-palette.store.texts.toggle-dark-mode'),
|
||||||
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
description: t('tools.command-palette.store.texts.toggle-dark-mode-on-or-off'),
|
||||||
closeOnSelect: true,
|
action: () => styleStore.toggleDark(),
|
||||||
},
|
icon: SunIcon,
|
||||||
{
|
category: t('tools.command-palette.store.texts.actions'),
|
||||||
name: 'Toggle dark mode',
|
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
||||||
description: 'Toggle dark mode on or off.',
|
},
|
||||||
action: () => styleStore.toggleDark(),
|
{
|
||||||
icon: SunIcon,
|
name: t('tools.command-palette.store.texts.github-repository'),
|
||||||
category: 'Actions',
|
href: 'https://github.com/sharevb/it-tools',
|
||||||
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
category: t('tools.command-palette.store.texts.external'),
|
||||||
},
|
description: t('tools.command-palette.store.texts.view-the-source-code-of-it-tools-on-github'),
|
||||||
{
|
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
||||||
name: 'Github repository',
|
icon: GithubIcon,
|
||||||
href: 'https://github.com/sharevb/it-tools',
|
},
|
||||||
category: 'External',
|
{
|
||||||
description: 'View the source code of it-tools on Github.',
|
name: t('tools.command-palette.store.texts.report-a-bug-or-an-issue'),
|
||||||
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
description: t('tools.command-palette.store.texts.report-a-bug-or-an-issue-to-help-improve-it-tools'),
|
||||||
icon: GithubIcon,
|
href: 'https://github.com/sharevb/it-tools/issues/new/choose',
|
||||||
},
|
category: t('tools.command-palette.store.texts.actions-0'),
|
||||||
{
|
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
||||||
name: 'Report a bug or an issue',
|
icon: BugIcon,
|
||||||
description: 'Report a bug or an issue to help improve it-tools.',
|
},
|
||||||
href: 'https://github.com/sharevb/it-tools/issues/new/choose',
|
{
|
||||||
category: 'Actions',
|
name: t('tools.pomodoro-timer.PomodoroApp.text.about'),
|
||||||
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
description: t('tools.command-palette.store.texts.learn-more-about-it-tools'),
|
||||||
icon: BugIcon,
|
to: '/about',
|
||||||
},
|
category: t('tools.command-palette.store.texts.pages'),
|
||||||
{
|
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
||||||
name: 'About',
|
icon: InfoIcon,
|
||||||
description: 'Learn more about IT-Tools.',
|
},
|
||||||
to: '/about',
|
];
|
||||||
category: 'Pages',
|
|
||||||
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
|
||||||
icon: InfoIcon,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const { searchResult } = useFlexSearch({
|
const { searchResult } = useFlexSearch({
|
||||||
search: searchPrompt,
|
search: searchPrompt,
|
||||||
data: searchOptions,
|
data: searchOptions,
|
||||||
options: {
|
options: {
|
||||||
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredSearchResult = computed(() =>
|
const filteredSearchResult = computed(() =>
|
||||||
_.mapValues(
|
_.mapValues(
|
||||||
_.groupBy(searchResult.value, option => option.category),
|
_.groupBy(searchResult.value, (option) => option.category),
|
||||||
categoryOptions => categoryOptions.slice(0, maxSearchResultsPerCategory),
|
(categoryOptions) => categoryOptions.slice(0, maxSearchResultsPerCategory),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filteredSearchResult,
|
filteredSearchResult,
|
||||||
searchPrompt,
|
searchPrompt,
|
||||||
};
|
};
|
||||||
});
|
})();
|
||||||
@@ -3,13 +3,17 @@ import { storeToRefs } from 'pinia';
|
|||||||
import * as _ from 'es-toolkit/compat';
|
import * as _ from 'es-toolkit/compat';
|
||||||
import { useCommandPaletteStore } from './command-palette.store';
|
import { useCommandPaletteStore } from './command-palette.store';
|
||||||
import type { PaletteOption } from './command-palette.types';
|
import type { PaletteOption } from './command-palette.types';
|
||||||
|
import { loadLocaleMessages } from '@/plugins/i18n.plugin';
|
||||||
|
|
||||||
const isModalOpen = ref(false);
|
const isModalOpen = ref(false);
|
||||||
const inputRef = ref();
|
const inputRef = ref();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const isMac = computed(() => window.navigator.userAgent.toLowerCase().includes('mac'));
|
const isMac = computed(() => window.navigator.userAgent.toLowerCase().includes('mac'));
|
||||||
|
|
||||||
const commandPaletteStore = useCommandPaletteStore();
|
const { locale } = useI18n();
|
||||||
|
await loadLocaleMessages(locale.value);
|
||||||
|
|
||||||
|
const commandPaletteStore = useCommandPaletteStore(locale.value);
|
||||||
const { searchPrompt, filteredSearchResult } = storeToRefs(commandPaletteStore);
|
const { searchPrompt, filteredSearchResult } = storeToRefs(commandPaletteStore);
|
||||||
|
|
||||||
const keys = useMagicKeys({
|
const keys = useMagicKeys({
|
||||||
@@ -32,7 +36,7 @@ whenever(keys.meta_k, open);
|
|||||||
whenever(keys.escape, close);
|
whenever(keys.escape, close);
|
||||||
|
|
||||||
function open() {
|
function open() {
|
||||||
return isModalOpen.value = true;
|
return (isModalOpen.value = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
@@ -67,7 +71,9 @@ function handleKeydown(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getOptionIndex(option: PaletteOption) {
|
function getOptionIndex(option: PaletteOption) {
|
||||||
return Object.values(filteredSearchResult.value).flat().findIndex(o => o === option);
|
return Object.values(filteredSearchResult.value)
|
||||||
|
.flat()
|
||||||
|
.findIndex((o) => o === option);
|
||||||
}
|
}
|
||||||
|
|
||||||
function activateOption(option: PaletteOption) {
|
function activateOption(option: PaletteOption) {
|
||||||
@@ -108,7 +114,6 @@ function activateOption(option: PaletteOption) {
|
|||||||
<div flex-1>
|
<div flex-1>
|
||||||
<c-button w-full important:justify-start @click="isModalOpen = true">
|
<c-button w-full important:justify-start @click="isModalOpen = true">
|
||||||
<span flex items-center gap-3 op-40>
|
<span flex items-center gap-3 op-40>
|
||||||
|
|
||||||
<icon-mdi-search />
|
<icon-mdi-search />
|
||||||
{{ $t('search.label') }}
|
{{ $t('search.label') }}
|
||||||
|
|
||||||
@@ -118,14 +123,36 @@ function activateOption(option: PaletteOption) {
|
|||||||
</span>
|
</span>
|
||||||
</c-button>
|
</c-button>
|
||||||
|
|
||||||
<c-modal v-model:open="isModalOpen" class="palette-modal" overflow-y-auto shadow-xl important:max-w-650px pretty-scrollbar important:pa-12px @keydown="handleKeydown">
|
<c-modal
|
||||||
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text :placeholder="$t('search.placeholder')" autofocus clearable />
|
v-model:open="isModalOpen"
|
||||||
|
class="palette-modal"
|
||||||
|
overflow-y-auto
|
||||||
|
shadow-xl
|
||||||
|
important:max-w-650px
|
||||||
|
pretty-scrollbar
|
||||||
|
important:pa-12px
|
||||||
|
@keydown="handleKeydown"
|
||||||
|
>
|
||||||
|
<c-input-text
|
||||||
|
ref="inputRef"
|
||||||
|
v-model:value="searchPrompt"
|
||||||
|
raw-text
|
||||||
|
:placeholder="$t('search.placeholder')"
|
||||||
|
autofocus
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
|
||||||
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
||||||
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
||||||
{{ category }}
|
{{ category }}
|
||||||
</div>
|
</div>
|
||||||
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
|
<command-palette-option
|
||||||
|
v-for="option in options"
|
||||||
|
:key="option.name"
|
||||||
|
:option="option"
|
||||||
|
:selected="selectedOptionIndex === getOptionIndex(option)"
|
||||||
|
@activated="activateOption"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</c-modal>
|
</c-modal>
|
||||||
</div>
|
</div>
|
||||||
@@ -136,8 +163,8 @@ function activateOption(option: PaletteOption) {
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
|
||||||
::v-deep(.input-wrapper) {
|
::v-deep(.input-wrapper) {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
padding-left: 18px;
|
padding-left: 18px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-17
@@ -6,36 +6,37 @@ import type { Tool, ToolCategory, ToolWithCategory } from './tools.types';
|
|||||||
import { tools as allTools } from './index';
|
import { tools as allTools } from './index';
|
||||||
import { useITStorage } from '@/composable/queryParams';
|
import { useITStorage } from '@/composable/queryParams';
|
||||||
|
|
||||||
|
import { translate as t } from '@/plugins/i18n.plugin';
|
||||||
|
|
||||||
export const useToolStore = defineStore('tools', () => {
|
export const useToolStore = defineStore('tools', () => {
|
||||||
const favoriteToolsName = useITStorage('favoriteToolsName', []) as Ref<string[]>;
|
const favoriteToolsName = useITStorage('favoriteToolsName', []) as Ref<string[]>;
|
||||||
const { t } = useI18n();
|
|
||||||
|
|
||||||
const tools = computed<ToolWithCategory[]>(() => allTools
|
const tools = computed<ToolWithCategory[]>(() =>
|
||||||
.map((tool) => {
|
allTools.map((tool) => {
|
||||||
const toolI18nKey = tool.path.replace(/\//g, '');
|
const toolI18nKey = tool.path.replace(/\//g, '');
|
||||||
const category = tool.category || 'Development';
|
const category = tool.category || 'Development';
|
||||||
|
|
||||||
return ({
|
return {
|
||||||
...tool,
|
...tool,
|
||||||
path: tool.path,
|
path: tool.path,
|
||||||
name: t(`tools.${toolI18nKey}.title`, tool.name),
|
name: t(`tools.${toolI18nKey}.title`, tool.name),
|
||||||
description: t(`tools.${toolI18nKey}.description`, tool.description),
|
description: t(`tools.${toolI18nKey}.description`, tool.description),
|
||||||
category: t(`tools.categories.${category.toLowerCase()}`, category),
|
category: t(`tools.categories.${category.toLowerCase()}`, category),
|
||||||
});
|
};
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const toolsByCategory = computed<ToolCategory[]>(() => {
|
const toolsByCategory = computed<ToolCategory[]>(() => {
|
||||||
const orderedTools = _.orderBy(tools.value, ['category', 'name'], ['asc', 'asc']);
|
const orderedTools = _.orderBy(tools.value, ['category', 'name'], ['asc', 'asc']);
|
||||||
return Object.entries(_.groupBy(orderedTools, tool => tool.category))
|
return Object.entries(_.groupBy(orderedTools, (tool) => tool.category)).map(([name, components]) => ({
|
||||||
.map(([name, components]) => ({
|
name,
|
||||||
name,
|
components,
|
||||||
components,
|
}));
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const favoriteTools = computed(() => {
|
const favoriteTools = computed(() => {
|
||||||
return favoriteToolsName.value
|
return favoriteToolsName.value
|
||||||
.map(favoriteName => tools.value.find(({ name, path }) => name === favoriteName || path === favoriteName))
|
.map((favoriteName) => tools.value.find(({ name, path }) => name === favoriteName || path === favoriteName))
|
||||||
.filter(Boolean) as ToolWithCategory[]; // cast because .filter(Boolean) does not remove undefined from type
|
.filter(Boolean) as ToolWithCategory[]; // cast because .filter(Boolean) does not remove undefined from type
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,17 +55,20 @@ export const useToolStore = defineStore('tools', () => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeToolFromFavorites({ tool }: { tool: MaybeRef<Tool> }) {
|
removeToolFromFavorites({ tool }: { tool: MaybeRef<Tool> }) {
|
||||||
favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name && get(tool).path !== name);
|
favoriteToolsName.value = favoriteToolsName.value.filter(
|
||||||
favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name && get(tool).path !== name);
|
(name) => get(tool).name !== name && get(tool).path !== name,
|
||||||
|
);
|
||||||
|
favoriteToolsName.value = favoriteToolsName.value.filter(
|
||||||
|
(name) => get(tool).name !== name && get(tool).path !== name,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
isToolFavorite({ tool }: { tool: MaybeRef<Tool> }) {
|
isToolFavorite({ tool }: { tool: MaybeRef<Tool> }) {
|
||||||
return favoriteToolsName.value.includes(get(tool).name)
|
return favoriteToolsName.value.includes(get(tool).name) || favoriteToolsName.value.includes(get(tool).path);
|
||||||
|| favoriteToolsName.value.includes(get(tool).path);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateFavoriteTools(newOrder: ToolWithCategory[]) {
|
updateFavoriteTools(newOrder: ToolWithCategory[]) {
|
||||||
favoriteToolsName.value = newOrder.map(tool => tool.path);
|
favoriteToolsName.value = newOrder.map((tool) => tool.path);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user