File size: 1,659 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * Maps ISO 639-1 language codes to PostgreSQL text search configuration names
 * Always returns a valid PostgreSQL text search configuration name
 * Falls back to 'simple' if the language is not supported or unknown
 */
export function mapLanguageCodeToPostgresConfig(
  languageCode: string | null | undefined,
): string {
  if (!languageCode) {
    return "simple";
  }

  const normalizedCode = languageCode.toLowerCase().trim();

  // Map ISO 639-1 codes to PostgreSQL text search configuration names
  const languageMap: Record<string, string> = {
    // Common languages - ISO 639-1 codes
    en: "english",
    sv: "swedish",
    da: "danish",
    no: "norwegian",
    de: "german",
    fr: "french",
    es: "spanish",
    it: "italian",
    pt: "portuguese",
    ru: "russian",
    nl: "dutch",
    fi: "finnish",
    pl: "polish",
    tr: "turkish",
    cs: "czech",
    hu: "hungarian",
    ro: "romanian",
    // Full names that might be returned
    english: "english",
    swedish: "swedish",
    danish: "danish",
    norwegian: "norwegian",
    german: "german",
    french: "french",
    spanish: "spanish",
    italian: "italian",
    portuguese: "portuguese",
    russian: "russian",
    dutch: "dutch",
    finnish: "finnish",
    polish: "polish",
    turkish: "turkish",
    czech: "czech",
    hungarian: "hungarian",
    romanian: "romanian",
  };

  // Check if it's already a valid PostgreSQL config name
  if (languageMap[normalizedCode]) {
    return languageMap[normalizedCode];
  }

  // If not found, default to 'simple' which works for any language
  // but doesn't provide language-specific stemming
  return "simple";
}