/** * ConvertDBDialog Component * * Dialog for configuring collation parameters and database conversion options * Uses ICU4X collation settings based on BCP 47 locale extensions */ import React, { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { IonItem, IonLabel, IonList, IonNote, IonCheckbox, } from '@ionic/react'; import { MdxProfile } from '../types'; // ICU4X Collation Types export interface CollationOptions { language: string; collationType?: string; strength: 'level1' | 'level2' | 'level3' | 'level4'; alternateHandling: 'noignore' | 'shifted'; caseLevel: 'true' | 'false'; caseFirst: 'off' | 'upper' | 'lower'; } // Conversion Options export interface ConvertOptions { collation: CollationOptions; removeOldFiles: boolean; createFulltextIndex: boolean; } // Supported languages with collation (based on ICU4X documentation) // This list includes languages with special collation rules const COLLATION_LANGUAGES = [ { code: 'ar', nameKey: 'lang_arabic', collations: ['standard'] }, { code: 'ca', nameKey: 'lang_catalan', collations: ['standard'] }, { code: 'cs', nameKey: 'lang_czech', collations: ['standard'] }, { code: 'da', nameKey: 'lang_danish', collations: ['standard'] }, { code: 'de', nameKey: 'lang_german', collations: ['standard', 'phonebk'] }, { code: 'el', nameKey: 'lang_greek', collations: ['standard'] }, { code: 'en', nameKey: 'lang_english', collations: ['standard'] }, { code: 'es', nameKey: 'lang_spanish', collations: ['standard', 'trad'] }, { code: 'fi', nameKey: 'lang_finnish', collations: ['standard'] }, { code: 'fr', nameKey: 'lang_french', collations: ['standard'] }, { code: 'he', nameKey: 'lang_hebrew', collations: ['standard'] }, { code: 'hi', nameKey: 'lang_hindi', collations: ['standard'] }, { code: 'hu', nameKey: 'lang_hungarian', collations: ['standard'] }, { code: 'is', nameKey: 'lang_icelandic', collations: ['standard'] }, { code: 'it', nameKey: 'lang_italian', collations: ['standard'] }, { code: 'ja', nameKey: 'lang_japanese', collations: ['standard'] }, { code: 'ko', nameKey: 'lang_korean', collations: ['standard'] }, { code: 'nb', nameKey: 'lang_norwegian', collations: ['standard'] }, { code: 'nl', nameKey: 'lang_dutch', collations: ['standard'] }, { code: 'pl', nameKey: 'lang_polish', collations: ['standard'] }, { code: 'pt', nameKey: 'lang_portuguese', collations: ['standard'] }, { code: 'ro', nameKey: 'lang_romanian', collations: ['standard'] }, { code: 'ru', nameKey: 'lang_russian', collations: ['standard'] }, { code: 'sv', nameKey: 'lang_swedish', collations: ['standard'] }, { code: 'th', nameKey: 'lang_thai', collations: ['standard'] }, { code: 'tr', nameKey: 'lang_turkish', collations: ['standard'] }, { code: 'uk', nameKey: 'lang_ukrainian', collations: ['standard'] }, { code: 'vi', nameKey: 'lang_vietnamese', collations: ['standard'] }, { code: 'zh', nameKey: 'lang_chinese', collations: ['standard','pinyin', 'stroke', 'zhuyin'] }, ]; // Strength level descriptions (keys for i18n) const STRENGTH_DESCRIPTIONS = { level1: { labelKey: 'Level 1 (Primary)', descriptionKey: 'Compares base characters only, ignoring accents and case', exampleKey: 'strength_level1_example', }, level2: { labelKey: 'Level 2 (Secondary)', descriptionKey: 'Compares base characters and accents, ignoring case', exampleKey: 'strength_level2_example', }, level3: { labelKey: 'Level 3 (Tertiary)', descriptionKey: 'Compares base characters, accents, and case', exampleKey: 'strength_level3_example', }, level4: { labelKey: 'Level 4 (Quaternary)', descriptionKey: 'Distinguishes punctuation and whitespace', exampleKey: 'strength_level4_example', }, }; interface ConvertDBDialogProps { profile: MdxProfile; options: ConvertOptions; onOptionsChange: (options: ConvertOptions) => void; isProfileInUse?: boolean; } export const ConvertDBDialog: React.FC = ({ profile, options, onOptionsChange, isProfileInUse = false, }) => { const { t } = useTranslation(); // Get available collation types for selected language const availableCollations = useMemo(() => { const lang = COLLATION_LANGUAGES.find((l) => l.code === options.collation.language); return lang?.collations || ['standard']; }, [options.collation.language]); // Shared select styles const selectStyle: React.CSSProperties = { width: '100%', padding: '10px', marginTop: '8px', fontSize: '16px', border: '1px solid var(--ion-color-medium)', borderRadius: '8px', backgroundColor: 'var(--ion-background-color)', color: 'var(--ion-text-color)', cursor: 'pointer', }; return ( <>

{t('Rebuild Index')} : {profile.title}

{t('Collation settings for dictionary index')} {/* Language Selection */} {t('Language') + ': '} {t('Select the primary language for sorting')} {/* Collation Type Selection */} {availableCollations.length > 1 && ( {t('Collation Type') + ': '} {t('Language-specific sorting algorithm')} )} {/* Strength Level */} {t('Collation Strength') + ': '} {t('Determines how strictly characters are compared during sorting')} {t('Example')}:{' '} {t(STRENGTH_DESCRIPTIONS[options.collation.strength].exampleKey)} {/* Alternate Handling */} {t('Alternate Handling') + ': '} {t('How to treat punctuation and whitespace')} {/* Case Level */} {t('Case Level') + ': '} {t('Enable case-sensitive sorting at primary strength')} {/* Case First */} {t('Case First') + ': '} {t('Sort uppercase or lowercase letters first')} {/* Replace Original File */}

{t('Replace Original File')}

{isProfileInUse ? t('File is currently in use and cannot be replaced') : t('Automatically replace original MDX/MDD files after successful conversion')}
onOptionsChange({ ...options, removeOldFiles: e.detail.checked })} />
{/* Create Fulltext Index */}

{t('Create Fulltext Index')}

{t('Create fulltext search index after conversion for faster searching')}
onOptionsChange({ ...options, createFulltextIndex: e.detail.checked })} />
); }; /** * Hook for using ConvertDBDialog imperatively */ export const useConvertDBDialog = () => { const showConvertDBDialog = ( profile: MdxProfile, onConvert: (profileId: number, options: ConvertOptions) => Promise ) => { // This would need to be implemented using the EnhancedDialog system // For now, we'll use this as a typed interface return { profile, onConvert }; }; return { showConvertDBDialog }; };