Skip to content

Commit

Permalink
Add locale switcher to Advanced prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Jul 21, 2017
1 parent 2addf6b commit 33b4082
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 3 deletions.
81 changes: 80 additions & 1 deletion chrome/content/zotero/preferences/preferences_advanced.js
Expand Up @@ -23,7 +23,7 @@
***** END LICENSE BLOCK *****
*/

"use strict";
Components.utils.import("resource://gre/modules/Services.jsm");

Zotero_Preferences.Advanced = {
_openURLResolvers: null,
Expand All @@ -34,6 +34,7 @@ Zotero_Preferences.Advanced = {
Zotero_Preferences.Keys.init();

this.onDataDirLoad();
this.refreshLocale();
},


Expand Down Expand Up @@ -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);
}
}
};

Expand Down
11 changes: 11 additions & 0 deletions chrome/content/zotero/preferences/preferences_advanced.xul
Expand Up @@ -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;"
Expand Down
44 changes: 44 additions & 0 deletions 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': '正體中文 (繁體)'
})
}
2 changes: 2 additions & 0 deletions chrome/locale/en-US/zotero/zotero.properties
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion chrome/skin/default/zotero/preferences.css
Expand Up @@ -26,7 +26,8 @@ radio[pane]

.statusLine
{
margin: .75em 0;
margin-top: .75em;
margin-bottom: .75em;
font-size: .85em;
}

Expand Down
3 changes: 2 additions & 1 deletion components/zotero-service.js
Expand Up @@ -96,6 +96,7 @@ const xpcomFilesLocal = [
'id',
'integration',
'itemTreeView',
'locale',
'locateManager',
'mime',
'notifier',
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 33b4082

Please sign in to comment.