If you don't want to add controller to your <html>
tag and if you are using angular-translate then you can use a simple directive to achieve the same.
Angular-translates gives an event $translateChangeSuccess
when your translation loaded successfully or when you change the language (I assume you will use $translate.use
to change the current language). We can create a custom directive using that event.
Directive Code Snippet:
function updateLanguage( $rootScope ) {
return {
link: function( scope, element ) {
var listener = function( event, translationResp ) {
var defaultLang = "en",
currentlang = translationResp.language;
element.attr("lang", currentlang || defaultLang );
};
$rootScope.$on('$translateChangeSuccess', listener);
}
};
}
angular.module('app').directive( 'updateLanguage', updateLanguage );
And you have add the same directive in you html attribute.
<html update-language>