There’s only 2 real places a locale is defined in a vanilla WordPress install:
- For the site.
- For the user account.
In the admin the user account’s locale will be used, while on the front end the site’s locale will be used. For REST API requests the user locale can be used by passing
_locale=user as a parameter.
determine_locale() function is what performs the logic to determine whether the user or site’s locale should be used, with additional logic that handles setting the locale during install.
get_locale() function is used by
determine_locale to get the site’s locale. It returns the site’s language as set in Settings > General. The site language can also be defined as a constant in
wp-config.php or filtered by plugins. This is the function you’d normally use to get a site’s locale.
Individual pages and posts do not have a locale. If you are using a plugin to create versions of pages in multiple languages then you will need to refer to that plugin’s documentation for the correct way to get the correct language.