Fix up some issues with plural processing. Make loadDomain handle both loads if there are any. Fix up Math Processing Error snippets to use new snippet code.

This commit is contained in:
Davide P. Cervone 2013-04-06 10:47:47 -04:00
parent 535c033e24
commit 9ee925dfbb
5 changed files with 24 additions and 27 deletions

View File

@ -1066,7 +1066,7 @@ MathJax.Localization = {
// The pattern for substitution escapes: // The pattern for substitution escapes:
// %n or %{n} or %{plural:%n|option1|option1|...} or %c // %n or %{n} or %{plural:%n|option1|option1|...} or %c
// //
pattern: /%(\d+|\{\d+\}|\{[a-z]+:\%\d+(?:\|(?:%(?:\d+|\{\d+\}|.)|[^\}])*)+\}|.)/g, pattern: /%(\d+|\{\d+\}|\{[a-z]+:\%\d+(?:\|(?:%\{\d+\}|%.|[^\}])*)+\}|.)/g,
_: function (id,phrase) { _: function (id,phrase) {
if (phrase instanceof Array) {return this.processSnippet(id,phrase)} if (phrase instanceof Array) {return this.processSnippet(id,phrase)}
@ -1098,13 +1098,14 @@ MathJax.Localization = {
if (typeof parts[i] === "number") parts[i] = this.number(parts[i]); if (typeof parts[i] === "number") parts[i] = this.number(parts[i]);
} else { // %{plural:%n|...} } else { // %{plural:%n|...}
var match = parts[i].match(/^\{([a-z]+):%(\d+)\|(.*)\}$/); var match = parts[i].match(/^\{([a-z]+):%(\d+)\|(.*)\}$/);
if (match) {
if (match[1] === "plural") { if (match[1] === "plural") {
var n = args[match[2]-1]; var n = args[match[2]-1];
if (typeof n === "undefined") { if (typeof n === "undefined") {
parts[i] = "???"; // argument doesn't exist parts[i] = "???"; // argument doesn't exist
} else { } else {
n = this.plural(n) - 1; // index of the form to use n = this.plural(n) - 1; // index of the form to use
var plurals = match[3].replace(/%\|/g,"%\uEFEF").split(/\|/); // the parts (replacing %| with a special character) var plurals = match[3].replace(/(^|[^%])(%%)*%\|/g,"$1$2%\uEFEF").split(/\|/); // the parts (replacing %| with a special character)
if (n >= 0 && n < plurals.length) { if (n >= 0 && n < plurals.length) {
parts[i] = this.processString(plurals[n].replace(/\uEFEF/g,"|"),args,domain); parts[i] = this.processString(plurals[n].replace(/\uEFEF/g,"|"),args,domain);
} else { } else {
@ -1115,6 +1116,7 @@ MathJax.Localization = {
} }
} }
} }
}
// //
// If we are not forming a snippet, return the completed string // If we are not forming a snippet, return the completed string
// //
@ -1244,7 +1246,8 @@ MathJax.Localization = {
if (localeData) { if (localeData) {
if (!localeData.isLoaded) { if (!localeData.isLoaded) {
load = this.loadFile(this.locale,localeData); load = this.loadFile(this.locale,localeData);
if (load) {return load} // if the main file must be loaded, call us again to load domain
if (load) {return MathJax.Callback.After(["loadDomain",this,domain],load)}
} }
if (localeData.domains && domain in localeData.domains) { if (localeData.domains && domain in localeData.domains) {
var domainData = localeData.domains[domain]; var domainData = localeData.domains[domain];
@ -1637,8 +1640,8 @@ MathJax.Hub = {
}, },
errorSettings: { errorSettings: {
message: ["[Math Processing Error]"], // HTML snippet structure for message to use // localized HTML snippet structure for message to use
messageId: "MathProcessingErrorHTML", // ID of snippet for localization message: ["[",["MathProcessingError","Math Processing Error"],"]"],
style: {color: "#CC0000", "font-style":"italic"} // style for message style: {color: "#CC0000", "font-style":"italic"} // style for message
} }
}, },

View File

@ -24,8 +24,7 @@ MathJax.Hub.Config({
mpMouse: true mpMouse: true
}, },
errorSettings: { errorSettings: {
message: ["[Math Error]"], message: ["[",["MathError","Math Error],"]"]
messageId: "MathErrorHTML"
} }
}); });

View File

@ -24,8 +24,7 @@ MathJax.Hub.Config({
mpMouse: true mpMouse: true
}, },
errorSettings: { errorSettings: {
message: ["[Math Error]"], message: ["[",["MathError","Math Error],"]"]
messageId: "MathErrorHTML"
} }
}); });

View File

@ -308,8 +308,7 @@
else if (message.match(/- no valid font/)) {MSG = "noFonts"} else if (message.match(/- no valid font/)) {MSG = "noFonts"}
if (MSG && CONFIG.Message[MSG]) { if (MSG && CONFIG.Message[MSG]) {
MathJax.Callback.Queue( MathJax.Callback.Queue(
["loadDomain",MathJax.Localization,"FontWarnings"], // load locale ["loadDomain",MathJax.Localization,"FontWarnings"], // make sure these are available
["loadDomain",MathJax.Localization,"FontWarnings"], // load domain
[CREATEMESSAGE,CONFIG.Message[MSG]] [CREATEMESSAGE,CONFIG.Message[MSG]]
); );
} }

View File

@ -13,11 +13,8 @@ MathJax.Hub.Insert(MathJax.Localization.strings.fr,{
MathProcessingError: MathProcessingError:
"Erreur de traitement de la formule mathématique", "Erreur de traitement de la formule mathématique",
MathProcessingErrorHTML: MathError:
["[Erreur de traitement de la formule mathématique]"], "Erreur dans la formule mathématique",
MathErrorHTML:
["[Erreur dans la formule mathématique]"],
LoadFile: "Téléchargement %1", LoadFile: "Téléchargement %1",