From 25be9b8c93ce31a88a5c560908c9bfd2708f44a5 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 16 Dec 2012 18:52:39 +0100 Subject: [PATCH] Add kick-off code for client-side l10n --- src/static/js/html10n.js | 8 ++++++++ src/static/js/l10n.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/static/js/l10n.js diff --git a/src/static/js/html10n.js b/src/static/js/html10n.js index a38f76d78..9c85cd2f8 100644 --- a/src/static/js/html10n.js +++ b/src/static/js/html10n.js @@ -804,6 +804,14 @@ window.html10n = (function(window, document, undefined) { cb(null, build) }) } + + /** + * Returns the language that was last applied to the translations hash + * thus overriding most of the formerly applied langs + */ + html10n.getLanguage = function() { + this.language + } /** * Index all s diff --git a/src/static/js/l10n.js b/src/static/js/l10n.js new file mode 100644 index 000000000..0bd060fe1 --- /dev/null +++ b/src/static/js/l10n.js @@ -0,0 +1,13 @@ +(function(document) { + // Set language for l10n + var language = document.cookie.match(/language=(\w{2})/); + if(language) language = language[1]; + + html10n.bind('indexed', function() { + html10n.localize([language, navigator.language, navigator.userLanguage, 'en']) + }) + + html10n.bind('localized', function() { + document.documentElement.lang = html10n.getLanguage() + }) +})(document) \ No newline at end of file