All files / web/src/arcade-games/know-your-world messages.ts

75.8% Statements 47/62
100% Branches 0/0
0% Functions 0/2
75.8% Lines 47/62

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 631x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x 1x              
/**
 * Know Your World translations aggregated by locale
 * Co-located with the game code
 */
 
// Import existing locale files
import en from './i18n/locales/en.json'
import de from './i18n/locales/de.json'
import es from './i18n/locales/es.json'
import goh from './i18n/locales/goh.json'
import hi from './i18n/locales/hi.json'
import ja from './i18n/locales/ja.json'
import la from './i18n/locales/la.json'
 
export const knowYourWorldMessages = {
  en: { knowYourWorld: en },
  de: { knowYourWorld: de },
  es: { knowYourWorld: es },
  goh: { knowYourWorld: goh },
  hi: { knowYourWorld: hi },
  ja: { knowYourWorld: ja },
  la: { knowYourWorld: la },
} as const
 
/**
 * Type for hint lookup
 */
export type HintMap = 'usa' | 'world' | 'europe' | 'africa'
export type HintsData = {
  hints: {
    usa: Record<string, string[]>
    world: Record<string, string[]>
    europe: Record<string, string[]>
    africa: Record<string, string[]>
  }
}
 
/**
 * Get all hints for a region in the specified locale
 * Returns undefined if no hints exist
 */
export function getHints(
  locale: keyof typeof knowYourWorldMessages,
  map: HintMap,
  regionId: string
): string[] | undefined {
  const localeData = knowYourWorldMessages[locale]?.knowYourWorld as HintsData | undefined
  const hints = localeData?.hints?.[map]?.[regionId]
  // Return undefined if no hints or empty array
  return hints && hints.length > 0 ? hints : undefined
}
 
/**
 * Check if hints exist for a region in the specified locale
 */
export function hasHints(
  locale: keyof typeof knowYourWorldMessages,
  map: HintMap,
  regionId: string
): boolean {
  return getHints(locale, map, regionId) !== undefined
}