Where does the locale come from?

Locale comes from WPLANG constant defined in wp-config.php. In the last version of WordPress (4.0, maybe 3.9) something is changing. You can install more languages setting WPLANG to different locale. Then you can select the language in the backend from Settings > General > Site language and set locale in the header. It seems that starting from WordPress v4.1 will be possible also install new languages from backend.