@@ -353,22 +353,32 @@ def derive_player_count(
353353
354354
355355def get_igdb_preferred_locale (rom : Rom | None = None ) -> str | None :
356- """Get IGDB locale, preferring the rom 's own region tag when available.
356+ """Get IGDB locale from the ROM 's prioritized regions when available.
357357
358358 Maps region priority codes to IGDB's game_localizations region identifiers.
359- Checks the rom's tagged regions first, then falls back to scan.priority.region.
359+ Prioritizes the ROM's tagged regions by scan.priority.region, then falls
360+ back to scan.priority.region.
360361
361362 Returns:
362363 IGDB region identifier (e.g., "ja-JP", "EU") or None for default
363364 """
365+ config = cm .get_config ()
366+ priority = config .SCAN_REGION_PRIORITY
367+
364368 if rom is not None and isinstance (rom .regions , list ):
369+ rom_codes : list [str ] = []
365370 for region_name in rom .regions :
366371 code = region_name_to_provider_shortcode (region_name )
367372 if code and code in REGION_TO_IGDB_LOCALE :
368- return REGION_TO_IGDB_LOCALE [ code ]
373+ rom_codes . append ( code )
369374
370- config = cm .get_config ()
371- for region in config .SCAN_REGION_PRIORITY :
375+ rom_codes .sort (
376+ key = lambda code : priority .index (code ) if code in priority else len (priority )
377+ )
378+ if rom_codes :
379+ return REGION_TO_IGDB_LOCALE [rom_codes [0 ]]
380+
381+ for region in priority :
372382 if region .lower () in REGION_TO_IGDB_LOCALE :
373383 return REGION_TO_IGDB_LOCALE [region .lower ()]
374384
0 commit comments