Trying to translate more dialogs ; Implement localization of numbers ; Handle arg substitution for arrays.

This commit is contained in:
Frédéric Wang 2013-02-20 15:42:12 +01:00
parent 4ced117e05
commit ca2f87ad7c
5 changed files with 204 additions and 80 deletions

View File

@ -2481,7 +2481,7 @@ MathJax.Hub.Startup = {
MathJax.Localization = { MathJax.Localization = {
locale: "fr", locale: "en",
directory: "[MathJax]/localization", directory: "[MathJax]/localization",
strings: { strings: {
fr: { fr: {
@ -2491,24 +2491,61 @@ MathJax.Localization = {
strings: { strings: {
} }
}, },
// FontWarnings: { FontWarnings: {
// isLoaded: true, isLoaded: true,
// strings: { strings: {
// fonts: webFont:
// [ "MathJax utilise les polices Web pour afficher les expressions " +
// ["p"], "mathématiques sur cette page. Celles-ci mettent du temps à être "+
// "MathJax peut utiliser soit les ", "téléchargées et la page serait affichée plus rapidement si vous "+
// ["a",{href:"http://www.stixfonts.org/",target:"_blank"},"polices STIX"], "installiez les polices mathématiques directement dans le dossier "+
// " soit les ", "des polices de votre système.",
// ["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},["polices TeX de MathJax"]],
// ". Téléchargez et installez une de ces familles pour rendre plus confortable votre utilisation de MathJax." imageFonts:
// ] "MathJax utilise des images de caractères plutôt que les polices "+
// } "Web ou locales. Ceci rend le rendu plus lent que la normale et "+
// }, "les expressions mathématiques peuvent ne pas s'imprimer à la "+
"résolution maximale de votre imprimante",
noFonts:
"MathJax n'est pas parvenu à localiser une police pour afficher "+
"les expressions mathématiques et les images de caractères ne "+
"sont pas disponibles. Comme solution de dernier recours, il "+
"utilise des caractères Unicode génériques en espérant que votre "+
"navigateur sera capable de les afficher. Certains pourront ne "+
"être rendus de façon incorrect voire pas du tout.",
webFonts:
"La plupart des navigateurs modernes permettent de télécharger "+
"des polices à partir du Web. En mettant à jour pour une version "+
"plus récente de votre navigateur (ou en changeant de navigateur) "+
"la qualité des expressions mathématiques sur cette page pourrait "+
"être améliorée.",
fonts:
"%1 MathJax peut utiliser les %2 ou bien les %3. Téléchargez et"+
"installez l'une de ces familles de polices pour améliorer votre"+
"expérience avec MathJax.",
PageDesigned:
"%1 Cette page est conçue pour utiliser les %2. Téléchargez "+
" et installez ces polices pour améliorer votre expérience "+
"avec MathJax",
STIXfonts:
"Polices STIX",
TeXfonts:
"Polices TeX de MathJax",
}
},
Menu: { Menu: {
isLoaded: true, isLoaded: true,
strings: { strings: {
AboutBox:
"%1 utilisant %2",
WebkitNativeMMLWarning: WebkitNativeMMLWarning:
"Votre navigateur ne semble pas comporter de support MathML, " + "Votre navigateur ne semble pas comporter de support MathML, " +
@ -2564,7 +2601,7 @@ MathJax.Localization = {
"en utilisant la commande Alt-Clic sur une expression.", "en utilisant la commande Alt-Clic sur une expression.",
NoOriginalForm: NoOriginalForm:
"Aucune forme originelle", "Aucune forme d'origine disponible.",
Close: Close:
"Fermer", "Fermer",
@ -2572,17 +2609,46 @@ MathJax.Localization = {
EqSource: EqSource:
"Source de l'équation MathJax" "Source de l'équation MathJax"
} }
},
ConfigWarning: {
isLoaded: true,
strings: {
MissingConfig:
"%1 MathJax ne charge plus de fichier de configuration par défaut"+
" ; vous devez spécifier ces fichiers de façons explicites. Cette"+
" page semble utiliser l'ancien fichier de configuration par "+
"défaut %2 and doit donc être mise à jour. Ceci est expliqué "+
"en détails à l'addresse suivante: %3"
}
},
Message: {
isLoaded: true,
strings: {
LoadFailed: "Échec du chargement du fichier %1"
} }
} }
},
plural: function(n) {
if (0 <= n && n < 2) return 1; // one
return 2; // other
},
number: function(n) {
return n.replace(".", ","); // replace dot by comma
}
} }
}, },
_: function (messageId, englishPhrase) { _: function (messageId, englishPhrase) {
// These variables are used in string parsing // These variables are used in string parsing
var plural = this.plural; var locale = this;
var args = arguments; var args = arguments;
var i, s, result; var i, s, resultString, resultArray;
function parseNextUnicodePoint(appendToResult) function parseNextUnicodePoint(appendToResult)
{ {
@ -2590,13 +2656,13 @@ MathJax.Localization = {
if (n <= 0xD7FF || 0xE000 <= n) { if (n <= 0xD7FF || 0xE000 <= n) {
// Code points U+0000 to U+D7FF and U+E000 to U+FFFF. // Code points U+0000 to U+D7FF and U+E000 to U+FFFF.
// Append the character. // Append the character.
if (appendToResult) result += s[i] if (appendToResult) resultString += s[i]
i++; i++;
return; return;
} else if (i+1 < m) { } else if (i+1 < m) {
// Code points U+10000 to U+10FFFF // Code points U+10000 to U+10FFFF
// Append the surrogate pairs. // Append the surrogate pairs.
if (appendToResult) { result += s[i]; result += s[i+1]; } if (appendToResult) { resultString += s[i]; resultString += s[i+1]; }
i+=2 i+=2
return; return;
} }
@ -2614,12 +2680,26 @@ MathJax.Localization = {
i += argIndex.length; i += argIndex.length;
var key = +argIndex+1; var key = +argIndex+1;
if (key in args) { if (key in args) {
if (appendToResult) { result += args[key]; } if (appendToResult) {
var e = args[key];
if (Array.isArray(e)) {
// if that's an array, concatenate it to the result array
resultArray.push(resultString);
resultArray = resultArray.concat(e);
resultString = "";
} else if (typeof e === "number") {
// if that's a number, append a localized version.
resultString += locale.number(e.toString())
} else {
// otherwise, just concatenate it to the result string
resultString += e;
}
}
return true; return true;
} }
// invalid index: just %INTEGER and continue // invalid index: just %INTEGER and continue
if (appendToResult) { result += "%" + argIndex; } if (appendToResult) { resultString += "%" + argIndex; }
i++; i++;
return true; return true;
} }
@ -2630,7 +2710,7 @@ MathJax.Localization = {
if (!number) return false; if (!number) return false;
// %{INTEGER} escaped integer // %{INTEGER} escaped integer
if (appendToResult) { result += number[1]; } if (appendToResult) { resultString += number[1]; }
i += number[0].length; i += number[0].length;
return true; return true;
} }
@ -2697,7 +2777,8 @@ MathJax.Localization = {
s = string; s = string;
i = 0; i = 0;
m = s.length; m = s.length;
result = ""; resultString = "";
resultArray = [];
while (i < m) { while (i < m) {
if (s[i] != "%" || i+1 == m) { if (s[i] != "%" || i+1 == m) {
@ -2716,14 +2797,16 @@ MathJax.Localization = {
if (parseInteger(true)) continue; if (parseInteger(true)) continue;
// %\{plural:%INTEGER|form1|form2 ... \} plural forms // %\{plural:%INTEGER|form1|form2 ... \} plural forms
if (parseChoiceBlock("plural", plural)) continue; if (parseChoiceBlock("plural", locale.plural)) continue;
// %CHAR: escaped character // %CHAR: escaped character
parseNextUnicodePoint(true); parseNextUnicodePoint(true);
continue; continue;
} }
return result; if (resultArray.length == 0) return resultString;
return resultArray;
} }
function transformHTMLSnippet(snippet) function transformHTMLSnippet(snippet)
@ -2772,6 +2855,8 @@ MathJax.Localization = {
setLocale: function(locale) { setLocale: function(locale) {
this.locale = locale; this.locale = locale;
this.plural = this.strings[locale].plural;
this.number = this.strings[locale].number;
// TODO // TODO
}, },
@ -2784,7 +2869,11 @@ MathJax.Localization = {
}, },
plural: function(n) { plural: function(n) {
if (n == 1) return 1; if (n == 1) return 1; // one
return 2; return 2; // other
},
number: function(n) {
return n;
} }
}; };

View File

@ -1,3 +1,5 @@
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/************************************************************* /*************************************************************
* *
* MathJax/extensions/FontWarnings.js * MathJax/extensions/FontWarnings.js
@ -85,6 +87,12 @@
(function (HUB,HTML) { (function (HUB,HTML) {
var VERSION = "2.1"; var VERSION = "2.1";
var _ = function (id) {
return MathJax.Localization._.apply(MathJax.Localization,
[ ["FontWarnings",id] ].concat([].slice.call(arguments,1))
);
}
var CONFIG = HUB.CombineConfig("FontWarnings",{ var CONFIG = HUB.CombineConfig("FontWarnings",{
// //
// The CSS for the message window // The CSS for the message window
@ -112,29 +120,33 @@
Message: { Message: {
webFont: [ webFont: [
["closeBox"], ["closeBox"],
"MathJax is using web-based fonts to display the mathematics ", _("webFont",
"on this page. These take time to download, so the page would ", "MathJax is using web-based fonts to display the mathematics "+
"render faster if you installed math fonts directly in your ", "on this page. These take time to download, so the page would "+
"system's font folder.", "render faster if you installed math fonts directly in your "+
"system's font folder."),
["fonts"] ["fonts"]
], ],
imageFonts: [ imageFonts: [
["closeBox"], ["closeBox"],
"MathJax is using its image fonts rather than local or web-based fonts. ", _("imageFonts",
"This will render slower than usual, and the mathematics may not print ", "MathJax is using its image fonts rather than local or web-based fonts. "+
"at the full resolution of your printer.", "This will render slower than usual, and the mathematics may not print "+
"at the full resolution of your printer."),
["fonts"], ["fonts"],
["webfonts"] ["webfonts"]
], ],
noFonts: [ noFonts: [
["closeBox"], ["closeBox"],
"MathJax is unable to locate a font to use to display ", _("noFonts",
"its mathematics, and image fonts are not available, so it ", "MathJax is unable to locate a font to use to display "+
"is falling back on generic unicode characters in hopes that ", "its mathematics, and image fonts are not available, so it "+
"your browser will be able to display them. Some characters ", "is falling back on generic unicode characters in hopes that "+
"may not show up properly, or possibly not at all.", "your browser will be able to display them. Some characters "+
"may not show up properly, or possibly not at all."),
["fonts"], ["fonts"],
["webfonts"] ["webfonts"]
] ]
@ -168,35 +180,37 @@
[["span",{style:{position:"relative", bottom:".2em"}},["x"]]] [["span",{style:{position:"relative", bottom:".2em"}},["x"]]]
]], ]],
webfonts: [ webFonts: [
["p"], ["p"],
"Most modern browsers allow for fonts to be downloaded over the web. ", _("webFonts",
"Updating to a more recent version of your browser (or changing browsers) ", "Most modern browsers allow for fonts to be downloaded over the web. "+
"could improve the quality of the mathematics on this page." "Updating to a more recent version of your browser (or changing"+
"browsers) could improve the quality of the mathematics on this page.")
], ],
fonts: [ fonts: _("fonts",
["p"], "%1 MathJax can use either the %2 or the % "+
"MathJax can use either the ", ". Download and install either one to improve your MathJax experience.",
["a",{href:"http://www.stixfonts.org/",target:"_blank"},"STIX fonts"], [["p"]],
" or the ", [["a",{href:"http://www.stixfonts.org/",target:"_blank"},
["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},["MathJax TeX fonts"]], _("STIXfonts", "STIX fonts")]],
". Download and install either one to improve your MathJax experience." [["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},
], [_("TeXfonts", "MathJax TeX fonts")]]]
),
STIXfonts: [ STIXfonts: _("PageDesigned",
["p"], "%1 This page is designed to use the %2."+
"This page is designed to use the ", " Download and install those fonts to improve your MathJax experience.",
["a",{href:"http://www.stixfonts.org/",target:"_blank"},"STIX fonts"], [["p"]],
". Download and install those fonts to improve your MathJax experience." [["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},
], [_("STIXfonts", "STIX fonts")]]]),
TeXfonts: [ TeXfonts: _("PageDesigned",
["p"], "%1 This page is designed to use the %2."+
"This page is designed to use the ", " Download and install those fonts to improve your MathJax experience.",
["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},["MathJax TeX fonts"]], [["p"]],
". Download and install those fonts to improve your MathJax experience." [["a",{href:"http://www.mathjax.org/help-v2/fonts/",target:"_blank"},
] [_("TeXfonts", "MathJax TeX fonts")]]])
}, },

View File

@ -622,9 +622,11 @@
MENU.About.div = MENU.Background(MENU.About); MENU.About.div = MENU.Background(MENU.About);
var about = HTML.addElement(MENU.About.div,"div",{ var about = HTML.addElement(MENU.About.div,"div",{
id: "MathJax_About" id: "MathJax_About"
},[ },
["b",{style:{fontSize:"120%"}},["MathJax"]]," v"+MathJax.version,["br"], _("AboutBox", "%1 using %2",
"using "+font,["br"],["br"], [["b",{style:{fontSize:"120%"}},["MathJax"]],
" v"+MathJax.version,["br"]],
[font,["br"],["br"],
["span",{style:{ ["span",{style:{
display:"inline-block", "text-align":"left", "font-size":"80%", display:"inline-block", "text-align":"left", "font-size":"80%",
"max-height":"20em", overflow:"auto", "max-height":"20em", overflow:"auto",
@ -635,8 +637,8 @@
src: CONFIG.closeImg, src: CONFIG.closeImg,
style: {width:"21px", height:"21px", position:"absolute", top:".2em", right:".2em"}, style: {width:"21px", height:"21px", position:"absolute", top:".2em", right:".2em"},
onclick: MENU.About.Remove onclick: MENU.About.Remove
}] }]])
]); );
var doc = (document.documentElement||{}); var doc = (document.documentElement||{});
var H = window.innerHeight || doc.clientHeight || doc.scrollHeight || 0; var H = window.innerHeight || doc.clientHeight || doc.scrollHeight || 0;
if (MENU.prototype.msieAboutBug) { if (MENU.prototype.msieAboutBug) {

View File

@ -26,6 +26,13 @@
(function (HUB,HTML) { (function (HUB,HTML) {
var VERSION = "2.1"; var VERSION = "2.1";
var _ = function (id) {
return MathJax.Localization._.apply(
MathJax.Localization,
[ ["ConfigWarning", id] ].concat([].slice.call(arguments,1))
);
};
var CONFIG = { var CONFIG = {
style: { style: {
position:"fixed", bottom:"4em", left:"3em", width:"40em", position:"fixed", bottom:"4em", left:"3em", width:"40em",
@ -56,8 +63,13 @@
CONFIG.style.position = "absolute"; CONFIG.style.position = "absolute";
} else {delete CONFIG.style.filter} } else {delete CONFIG.style.filter}
CONFIG.style.maxWidth = (document.body.clientWidth-75) + "px"; CONFIG.style.maxWidth = (document.body.clientWidth-75) + "px";
DIV = HTML.addElement(frame,"div",{id:"MathJax_ConfigWarning",style:CONFIG.style},[ DIV = HTML.addElement(frame,"div",{id:"MathJax_ConfigWarning",style:CONFIG.style},
[ _("MissingConfig",
"%1 MathJax no longer loads a default configuration file; " +
"you must specify such files explicitly. " +
"This page seems to use the older default %2 file"+
", and so needs to be updated. This is explained further at %3",
[[
"div",{ "div",{
style: { style: {
position:"absolute", overflow:"hidden", top:".1em", right:".1em", position:"absolute", overflow:"hidden", top:".1em", right:".1em",
@ -73,18 +85,14 @@
onclick: function () {DIV.style.display = "none"} onclick: function () {DIV.style.display = "none"}
}, },
[["span",{style:{position:"relative", bottom:".2em"}},["x"]]] [["span",{style:{position:"relative", bottom:".2em"}},["x"]]]
], ]],
"MathJax no longer loads a default configuration file; " + [["code",{},["config/MathJax.js"]]],
"you must specify such files explicitly. " + [["p",{style:{"text-align":"center"}},[
"This page seems to use the older default ",["code",{},["config/MathJax.js"]],
" file, and so needs to be updated. This is explained further at",
["p",{style:{"text-align":"center"}},[
["a", ["a",
{href:"http://www.mathjax.org/help/configuration"}, {href:"http://www.mathjax.org/help/configuration"},
["http://www.mathjax.org/help/configuration"] ["http://www.mathjax.org/help/configuration"]
] ]
]] ]]]))
]);
}); });
})(MathJax.Hub,MathJax.HTML); })(MathJax.Hub,MathJax.HTML);

View File

@ -0,0 +1,11 @@
["Do this",
["b", null,
["now!", ["img", {src: url}]]
]
]
_("dothis", "Do this %1",
["b", null,
_("now", "now! %1", ["img", {src: url}])
]
)