Skip to content

Commit

Permalink
Localize strings in parseScript module.
Browse files Browse the repository at this point in the history
Refs #1695
  • Loading branch information
arantius committed Jan 24, 2013
1 parent d787614 commit 7395e7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions locale/en-US/greasemonkey.properties
Expand Up @@ -12,6 +12,11 @@ notification.neveragain.label=Never show this again
notification.neveragain.accesskey=N
notification.ok.label=Ok
notification.ok.accesskey=O
parse.ignoring-match=Ignoring @match pattern %1 because:\n%2
parse.require-failed=Failed to @require URL: %1
parse.resource-syntax=Invalid syntax for @resource declaration "%1". Resources are declared like "@resource <name> <url>".
parse.resource-duplicate=Duplicate resource name "%s" detected. Each resource must have a unique name.
parse.resource-failed=Failed to get @resource %1 from %2
return-not-in-func-deprecated=Warning: use of return outside of functions is deprecated and may cause failures in future versions of Greasemonkey.
warning.scripts-should-grant=Warning: All scripts should specify @grant metadata.
warning.scripts-should-grant.read-docs=Read documentation
Expand Down
30 changes: 20 additions & 10 deletions modules/parseScript.js
Expand Up @@ -14,6 +14,10 @@ var gLineSplitRegexp = /.+/g;
var gAllMetaRegexp = new RegExp(
'^// ==UserScript==([\\s\\S]*?)^// ==/UserScript==', 'm');
var gMetaLineRegexp = new RegExp('// @(\\S+)(?:\\s+(.*))?');
var gStringBundle = Components
.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/greasemonkey.properties");

/** Get just the stuff between ==UserScript== lines. */
function extractMeta(aSource) {
Expand Down Expand Up @@ -95,9 +99,10 @@ function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) {
var match = new MatchPattern(value);
script._matches.push(match);
} catch (e) {
// TODO: Localize.
script.parseErrors.push(
'Ignoring @match pattern ' + value + ' because:\n' + e);
gStringBundle.GetStringFromName('parse.ignoring-match')
.replace('%1', value).replace('%2', e)
);
}
break;
case 'require':
Expand All @@ -108,25 +113,28 @@ function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) {
script._requires.push(scriptRequire);
script._rawMeta += header + '\0' + value + '\0';
} catch (e) {
// TODO: Localize.
script.parseErrors.push('Failed to @require URL: '+ value);
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.require-failed')
.replace('%1', value)
);
}
break;
case 'resource':
var res = value.match(/(\S+)\s+(.*)/);
if (res === null) {
// TODO: Localize.
script.parseErrors.push(
'Invalid syntax for @resource declaration "' + value
+ '". Resources are declared like "@resource <name> <url>".');
gStringBundle.GetStringFromName('parse.resource-syntax')
.replace('%1', value)
);
break;
}

var resName = res[1];
if (resourceNames[resName]) {
script.parseErrors.push(
'Duplicate resource name "' + resName + '" detected. '
+ 'Each resource must have a unique name.');
gStringBundle.GetStringFromName('parse.resource-duplicate')
.replace('%1', resName)
);
break;
}
resourceNames[resName] = true;
Expand All @@ -140,7 +148,9 @@ function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) {
script._rawMeta += header + '\0' + resName + '\0' + resUri.spec + '\0';
} catch (e) {
script.parseErrors.push(
'Failed to get @resource '+ resName +' from ' + res[2]);
gStringBundle.GetStringFromName('parse.resource-failed')
.replace('%1', resName).replace('%2', res[2])
);
}
break;
case 'run-at':
Expand Down

0 comments on commit 7395e7c

Please sign in to comment.