I have previously tried getting the language using locale, but it had problems when system language and region were different.
But your solution seems to be universally correct, I will try using it.