Skip to content

Commit

Permalink
Merge pull request #56 from tolbahadi/feat/locale/updateHtmlLangAttr
Browse files Browse the repository at this point in the history
Update the lang attribute of the html tag when the locale changes
  • Loading branch information
doshprompt committed Aug 18, 2015
2 parents 1ce1284 + db2c2d2 commit ee1fff3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ angular.module('ngLocalize')
.service('locale', function ($injector, $http, $q, $log, $rootScope, $window, localeConf, localeEvents, localeSupported, localeFallbacks) {
var TOKEN_REGEX = new RegExp('^[\\w\\.-]+\\.[\\w\\s\\.-]+\\w(:.*)?$'),

$html = angular.element(document.body).parent(),
currentLocale,
deferrences,
bundles,
Expand Down Expand Up @@ -227,6 +228,12 @@ angular.module('ngLocalize')
return result;
}

function updateHtmlTagLangAttr(lang) {
lang = lang.split('-')[0];

$html.attr('lang', lang);
}

function setLocale(value) {
var lang;

Expand All @@ -249,6 +256,8 @@ angular.module('ngLocalize')
deferrences = {};
currentLocale = lang;

updateHtmlTagLangAttr(lang);

$rootScope.$broadcast(localeEvents.localeChanges, currentLocale);
$rootScope.$broadcast(localeEvents.resourceUpdates);

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/serviceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ describe('service', function () {
it('should validate tokens with whitespace', inject(function (locale) {
expect(locale.isToken('test.hello world')).toBe(true);
}));

it('should update the lang attribute of the html tag', inject(function (locale) {
locale.setLocale('en-US');
expect(angular.element(document.body).parent().attr('lang')).toBe('en');
}));
});
});

0 comments on commit ee1fff3

Please sign in to comment.