From cbc9ad3cb6f8eaa7308feb83fde1c54be3958927 Mon Sep 17 00:00:00 2001 From: Samuel Chantaraud Date: Wed, 26 Feb 2014 16:09:58 -0400 Subject: [PATCH] Correct formatting of locale to make it compatible with l10n (safari issue) --- web/compatibility.js | 22 +++++++++++++--------- web/viewer.js | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/web/compatibility.js b/web/compatibility.js index 7253d8d59..64ce745bd 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -452,16 +452,20 @@ if (typeof PDFJS === 'undefined') { // Checks if navigator.language is supported (function checkNavigatorLanguage() { - if ('language' in navigator) + if ('language' in navigator && + /^[a-z]+(-[A-Z]+)?$/.test(navigator.language)) { return; - Object.defineProperty(navigator, 'language', { - get: function navigatorLanguage() { - var language = navigator.userLanguage || 'en-US'; - return language.substring(0, 2).toLowerCase() + - language.substring(2).toUpperCase(); - }, - enumerable: true - }); + } + function formatLocale(locale) { + var split = locale.split(/[-_]/); + split[0] = split[0].toLowerCase(); + if (split.length > 1) { + split[1] = split[1].toUpperCase(); + } + return split.join('-'); + } + var language = navigator.language || navigator.userLanguage || 'en-US'; + PDFJS.locale = formatLocale(language); })(); (function checkRangeRequests() { diff --git a/web/viewer.js b/web/viewer.js index 7ab9fda21..174e33835 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1666,7 +1666,7 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) { } //#if !(FIREFOX || MOZCENTRAL) - var locale = navigator.language; + var locale = PDFJS.locale || navigator.language; if ('locale' in hashParams) locale = hashParams['locale']; mozL10n.setLanguage(locale);