www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 33b40829b897bdca9501f8d446cba3a61758bc71
parent 2addf6b27b1466bf5520881fc007a31cd645076b
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 21 Jul 2017 05:30:49 -0400

Add locale switcher to Advanced prefs

Closes https://www.zotero.org/trac/ticket/1733 (!)

Diffstat:
Mchrome/content/zotero/preferences/preferences_advanced.js | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mchrome/content/zotero/preferences/preferences_advanced.xul | 11+++++++++++
Achrome/content/zotero/xpcom/locale.js | 44++++++++++++++++++++++++++++++++++++++++++++
Mchrome/locale/en-US/zotero/zotero.properties | 2++
Mchrome/skin/default/zotero/preferences.css | 3++-
Mcomponents/zotero-service.js | 3++-
6 files changed, 141 insertions(+), 3 deletions(-)

diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js @@ -23,7 +23,7 @@ ***** END LICENSE BLOCK ***** */ -"use strict"; +Components.utils.import("resource://gre/modules/Services.jsm"); Zotero_Preferences.Advanced = { _openURLResolvers: null, @@ -34,6 +34,7 @@ Zotero_Preferences.Advanced = { Zotero_Preferences.Keys.init(); this.onDataDirLoad(); + this.refreshLocale(); }, @@ -405,6 +406,84 @@ Zotero_Preferences.Advanced = { onOpenURLCustomized: function () { document.getElementById('openURLMenu').value = "custom"; + }, + + + _getAutomaticLocaleMenuLabel: function () { + return Zotero.getString( + 'zotero.preferences.locale.automaticWithLocale', + Zotero.Locale.availableLocales[Zotero.locale] || Zotero.locale + ); + }, + + + refreshLocale: function () { + var matchOS = Zotero.Prefs.get('intl.locale.matchOS', true); + var autoLocaleName, currentValue; + + // If matching OS, get the name of the current locale + if (matchOS) { + autoLocaleName = this._getAutomaticLocaleMenuLabel(); + currentValue = 'automatic'; + } + // Otherwise get the name of the locale specified in the pref + else { + let branch = Services.prefs.getBranch(""); + let locale = branch.getComplexValue( + 'general.useragent.locale', Components.interfaces.nsIPrefLocalizedString + ); + autoLocaleName = Zotero.getString('zotero.preferences.locale.automatic'); + currentValue = locale; + } + + // Populate menu + var menu = document.getElementById('locale-menu'); + var menupopup = menu.firstChild; + menupopup.textContent = ''; + // Show "Automatic (English)", "Automatic (Français)", etc. + menu.appendItem(autoLocaleName, 'automatic'); + menu.menupopup.appendChild(document.createElement('menuseparator')); + // Add all available locales + for (let locale in Zotero.Locale.availableLocales) { + menu.appendItem(Zotero.Locale.availableLocales[locale], locale); + } + menu.value = currentValue; + }, + + onLocaleChange: function () { + var menu = document.getElementById('locale-menu'); + if (menu.value == 'automatic') { + // Changed if not already set to automatic (unless we have the automatic locale name, + // meaning we just switched away to the same manual locale and back to automatic) + var changed = !Zotero.Prefs.get('intl.locale.matchOS', true) + && menu.label != this._getAutomaticLocaleMenuLabel(); + Zotero.Prefs.set('intl.locale.matchOS', true, true); + } + else { + // Changed if moving to a locale other than the current one + var changed = Zotero.locale != menu.value + Zotero.Prefs.set('intl.locale.matchOS', false, true); + Zotero.Prefs.set('general.useragent.locale', menu.value, true); + } + + if (!changed) { + return; + } + + var ps = Services.prompt; + var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING + + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING; + var index = ps.confirmEx(null, + Zotero.getString('general.restartRequired'), + Zotero.getString('general.restartRequiredForChange', Zotero.appName), + buttonFlags, + Zotero.getString('general.restartNow'), + Zotero.getString('general.restartLater'), + null, null, {}); + + if (index == 0) { + Zotero.Utilities.Internal.quitZotero(true); + } } }; diff --git a/chrome/content/zotero/preferences/preferences_advanced.xul b/chrome/content/zotero/preferences/preferences_advanced.xul @@ -133,6 +133,17 @@ <groupbox id="zotero-prefpane-advanced-miscellaneous"> <caption label="&zotero.preferences.miscellaneous;"/> + + <hbox align="center"> + <label value="&zotero.bibliography.locale.label;"/> + <menulist id="locale-menu" + oncommand="Zotero_Preferences.Advanced.onLocaleChange()"> + <menupopup/> + </menulist> + </hbox> + + <separator/> + <hbox id="zotero-prefpane-advanced-openbuttons" align="center" style="display: block"> <button id="openAboutConfig" label="&zotero.preferences.openAboutConfig;" diff --git a/chrome/content/zotero/xpcom/locale.js b/chrome/content/zotero/xpcom/locale.js @@ -0,0 +1,44 @@ +Zotero.Locale = { + /** + * Keep this up to date with chrome.manifest + */ + availableLocales: Object.freeze({ + 'ar': 'عربي', + 'bg-BG': 'Български', + 'ca-AD': 'Català', + 'cs-CZ': 'Čeština', + 'da-DK': 'Dansk', + 'de': 'Deutsch', + 'en-US': 'English', + 'es-ES': 'Español', + 'et-EE': 'Eesti keel', + 'fa': 'فارسی', + 'fi': 'suomi', + 'fr': 'Français', + 'gl-ES': 'Galego', + 'hu-HU': 'magyar', + 'id-ID': 'Bahasa Indonesia', + 'is-IS': 'íslenska', + 'it-IT': 'Italiano', + 'ja-JP': '日本語', + 'km': 'ខ្មែរ', + 'ko-KR': '한국어', + 'lt-LT': 'Lietuvių', + 'nl-NL': 'Nederlands', + 'pl-PL': 'Polski', + 'pt-BR': 'Português (do Brasil)', + 'pt-PT': 'Português (Europeu)', + 'ro-RO': 'Română', + 'ru-RU': 'Русский', + 'sk-SK': 'slovenčina', + 'sl-SI': 'Slovenščina', + 'sr-RS': 'Српски', + 'sv-SE': 'Svenska', + 'th-TH': 'ไทย', + 'tr-TR': 'Türkçe', + 'uk-UA': 'Українська', + 'vi-VN': 'Tiếng Việt', + 'zh-CN': '中文 (简体)', + 'zh-TW': '正體中文 (繁體)' + }) +} diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties @@ -603,6 +603,8 @@ zotero.preferences.launchNonNativeFiles = Open PDFs and other zotero.preferences.openurl.resolversFound.zero = %S resolvers found zotero.preferences.openurl.resolversFound.singular = %S resolver found zotero.preferences.openurl.resolversFound.plural = %S resolvers found +zotero.preferences.locale.automaticWithLocale = Automatic (%S) +zotero.preferences.locale.automatic = Automatic zotero.preferences.sync.purgeStorage.title = Purge Attachment Files on Zotero Servers? zotero.preferences.sync.purgeStorage.desc = If you plan to use WebDAV for file syncing and you previously synced attachment files in My Library to the Zotero servers, you can purge those files from the Zotero servers to give you more storage space for groups.\n\nYou can purge files at any time from your account settings on zotero.org. diff --git a/chrome/skin/default/zotero/preferences.css b/chrome/skin/default/zotero/preferences.css @@ -26,7 +26,8 @@ radio[pane] .statusLine { - margin: .75em 0; + margin-top: .75em; + margin-bottom: .75em; font-size: .85em; } diff --git a/components/zotero-service.js b/components/zotero-service.js @@ -96,6 +96,7 @@ const xpcomFilesLocal = [ 'id', 'integration', 'itemTreeView', + 'locale', 'locateManager', 'mime', 'notifier', @@ -297,7 +298,7 @@ function makeZoteroContext(isConnector) { // Load xpcomFiles for specific mode for (let xpcomFile of (isConnector ? xpcomFilesConnector : xpcomFilesLocal)) { try { - subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFile + ".js", zContext); + subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFile + ".js", zContext, "UTF-8"); } catch (e) { dump("Error loading " + xpcomFile + ".js\n\n");