-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This adds support for localized script description/name. Refs greasemonkey#1963.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ var gIoService = Components.classes["@mozilla.org/network/io-service;1"] | |
var gLineSplitRegexp = /.+/g; | ||
var gAllMetaRegexp = new RegExp( | ||
'^// ==UserScript==([\\s\\S]*?)^// ==/UserScript==', 'm'); | ||
var gMetaLineRegexp = new RegExp('// @(\\S+)(?:\\s+(.*))?'); | ||
var gMetaLineRegexp = new RegExp('// @([^\\s:]+)(?::([a-zA-Z-]+))?(?:\\s+(.*))?'); | ||
This comment has been minimized.
Sorry, something went wrong.
Martii
|
||
var gStringBundle = Components | ||
.classes["@mozilla.org/intl/stringbundle;1"] | ||
.getService(Components.interfaces.nsIStringBundleService) | ||
|
@@ -55,11 +55,20 @@ function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) { | |
if (!match) continue; | ||
|
||
var header = match[1]; | ||
var value = match[2] || null; | ||
var locale = match[2]; | ||
var value = match[3] || null; | ||
|
||
switch (header) { | ||
case 'description': | ||
case 'name': | ||
if (locale) { | ||
if (!script._locales[locale]) | ||
script._locales[locale] = {}; | ||
|
||
script._locales[locale][header] = value; | ||
break; | ||
} | ||
// fall-through if no locale given | ||
case 'namespace': | ||
case 'version': | ||
case 'updateMetaStatus': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Components.utils.import("resource://gre/modules/Services.jsm"); | ||
Components.utils.import('resource://greasemonkey/util.js'); | ||
|
||
const EXPORTED_SYMBOLS = ['getBestLocaleMatch']; | ||
|
||
// This function tries to find the best matching locale. | ||
// Locales should be given in the form "lang[-COUNTRY]". | ||
// If an exact match (i.e. both lang and country match) can be found, it is | ||
// returned. Otherwise, a partial match based on the lang part is attempted. | ||
// Partial matches without country are preferred over lang matches with | ||
// non-matching country. | ||
// If no locale matches, null is returned. | ||
function getBestLocaleMatch(aPreferred, aAvailable) { | ||
This comment has been minimized.
Sorry, something went wrong.
JasonBarnabe
|
||
var preferredLang = aPreferred.split("-")[0]; | ||
|
||
var langMatch, partialMatch = null; | ||
for (var i = 0, current; current = aAvailable[i]; i++) { | ||
// Both lang and country match | ||
if (current == aPreferred) | ||
return current; | ||
|
||
if (current == preferredLang) { | ||
// Only lang matches, no country | ||
langMatch = current; | ||
} else if (current.split("-")[0] == preferredLang) { | ||
// Only lang matches, non-matching country | ||
partialMatch = current; | ||
} | ||
} | ||
|
||
return langMatch || partialMatch; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Components.utils.import("resource://gre/modules/Services.jsm"); | ||
Components.utils.import('resource://greasemonkey/util.js'); | ||
|
||
const EXPORTED_SYMBOLS = ['getPreferredLocale']; | ||
|
||
var preferredLocale = (function() { | ||
var matchOS = Services.prefs.getBoolPref("intl.locale.matchOS"); | ||
|
||
if (matchOS) | ||
return Services.locale.getLocaleComponentForUserAgent(); | ||
|
||
return Services.prefs.getCharPref("general.useragent.locale") || "en-US"; | ||
})(); | ||
|
||
function getPreferredLocale() { | ||
return preferredLocale; | ||
} |
decription→description