This commit is contained in:
Ibrahima G. Coulibaly
2025-07-14 14:51:46 +01:00
parent c64c29878e
commit 6c9898f2d3
13 changed files with 129 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
import { UpdateField } from '@components/options/ToolOptions';
import { getToolsByCategory } from '@tools/index';
import { ToolCategory } from '@tools/defineTool';
import { I18nNamespaces } from '../i18n';
// Here starting the shared values for string manipulation.
@@ -110,3 +112,39 @@ export function itemCounter(
export const getToolCategoryTitle = (categoryName: string): string =>
getToolsByCategory().find((category) => category.type === categoryName)!
.rawTitle;
// Type guard to check if a value is a valid I18nNamespaces
const isValidI18nNamespace = (value: string): value is I18nNamespaces => {
const validNamespaces: I18nNamespaces[] = [
'string',
'number',
'video',
'list',
'json',
'time',
'csv',
'pdf',
'audio',
'xml',
'translation',
'image'
];
return validNamespaces.includes(value as I18nNamespaces);
};
export const getI18nNamespaceFromToolCategory = (
category: ToolCategory
): I18nNamespaces => {
// Map image-related categories to 'image'
if (['png', 'image-generic'].includes(category)) {
return 'image';
} else if (['gif'].includes(category)) {
return 'video';
}
// Use type guard to check if category is a valid I18nNamespaces
if (isValidI18nNamespace(category)) {
return category;
}
return 'translation';
};