I18N: Refactor determine_locale() for performance and readability.
determine_locale()
Refactors the function to avoid unnecessary get_locale() calls and slightly improve performance, while keeping it readable.
get_locale()
Adds tests.
Props Cybr, spacedmonkey, swissspidy. Fixes #58317.