This means that the documentElement attributes (lang, dir) might not be updated until the locale is changed — which would break non-default RTL locales. I think you want to do something like:
```javascript

function initLocale() {
  var lang = navigator.mozL10n.language.code;

  // set the 'lang' and 'dir' attributes to <html> when the page is translated
  document.documentElement.lang = lang;
  document.documentElement.dir = navigator.mozL10n.language.direction;

  // [define / copy these two functions here]
  updateLanguage(lang);
  updateKeyboard(lang);
}

navigator.mozL10n.ready(function startupLocalized() {
  initLocale;
  // XXX this might call `initLocale()` twice until bug 882592 is fixed
  window.addEventListener('localized', initLocale);
});
```

This might call `initLoca