Adding framework for internationalization support. The new OpenLayers.Lang.translate method takes a key and looks for a value in a dictionary based on the current language setting. Set a new language code with OpenLayers.Lang.setCode. Get the current code with OpenLayers.Lang.getCode. Thanks to Mike Adair for the lead on this one. r=ahocevar,me (closes #109)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6313 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-15 21:15:48 +00:00
parent bafc8b758b
commit fa55f54e32
30 changed files with 479 additions and 162 deletions

View File

@@ -4,6 +4,7 @@
/* /*
* @requires OpenLayers/BaseTypes.js * @requires OpenLayers/BaseTypes.js
* @requires OpenLayers/Lang/en.js
*/ */
(function() { (function() {
@@ -201,7 +202,9 @@
"OpenLayers/Layer/WFS.js", "OpenLayers/Layer/WFS.js",
"OpenLayers/Control/MouseToolbar.js", "OpenLayers/Control/MouseToolbar.js",
"OpenLayers/Control/NavToolbar.js", "OpenLayers/Control/NavToolbar.js",
"OpenLayers/Control/EditingToolbar.js" "OpenLayers/Control/EditingToolbar.js",
"OpenLayers/Lang.js",
"OpenLayers/Lang/en.js"
); // etc. ); // etc.
var agent = navigator.userAgent; var agent = navigator.userAgent;

View File

@@ -34,7 +34,7 @@ OpenLayers.ProxyHost = "";
* @param {} request * @param {} request
*/ */
OpenLayers.nullHandler = function(request) { OpenLayers.nullHandler = function(request) {
alert("Unhandled request return " + request.statusText); alert(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText}));
}; };
/** /**

View File

@@ -9,9 +9,10 @@
* @requires OpenLayers/BaseTypes/Pixel.js * @requires OpenLayers/BaseTypes/Pixel.js
* @requires OpenLayers/BaseTypes/Bounds.js * @requires OpenLayers/BaseTypes/Bounds.js
* @requires OpenLayers/BaseTypes/Element.js * @requires OpenLayers/BaseTypes/Element.js
* @requires OpenLayers/Lang/en.js
*/ */
/** /**
* Header: OpenLayers Base Types * Header: OpenLayers Base Types
* OpenLayers custom string, number and function functions are described here. * OpenLayers custom string, number and function functions are described here.
*/ */
@@ -23,6 +24,7 @@
*********************/ *********************/
OpenLayers.String = { OpenLayers.String = {
/** /**
* APIFunction: OpenLayers.String.startsWith * APIFunction: OpenLayers.String.startsWith
* Test whether a string starts with another string. * Test whether a string starts with another string.
@@ -90,7 +92,7 @@ OpenLayers.String = {
} }
return camelizedString; return camelizedString;
}, },
/** /**
* APIFunction: OpenLayers.String.format * APIFunction: OpenLayers.String.format
* Given a string with tokens in the form ${token}, return a string * Given a string with tokens in the form ${token}, return a string
@@ -141,10 +143,8 @@ if (!String.prototype.startsWith) {
* {Boolean} Whether or not this string starts with the string passed in. * {Boolean} Whether or not this string starts with the string passed in.
*/ */
String.prototype.startsWith = function(sStart) { String.prototype.startsWith = function(sStart) {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.startsWith'}));
"Please use OpenLayers.String.startsWith instead"
);
return OpenLayers.String.startsWith(this, sStart); return OpenLayers.String.startsWith(this, sStart);
}; };
} }
@@ -161,10 +161,8 @@ if (!String.prototype.contains) {
* {Boolean} Whether or not this string contains with the string passed in. * {Boolean} Whether or not this string contains with the string passed in.
*/ */
String.prototype.contains = function(str) { String.prototype.contains = function(str) {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.contains'}));
"Please use OpenLayers.String.contains instead"
);
return OpenLayers.String.contains(this, str); return OpenLayers.String.contains(this, str);
}; };
} }
@@ -179,10 +177,8 @@ if (!String.prototype.trim) {
* trailing spaces removed * trailing spaces removed
*/ */
String.prototype.trim = function() { String.prototype.trim = function() {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.trim'}));
"Please use OpenLayers.String.trim instead"
);
return OpenLayers.String.trim(this); return OpenLayers.String.trim(this);
}; };
} }
@@ -198,10 +194,8 @@ if (!String.prototype.camelize) {
* {String} The string, camelized * {String} The string, camelized
*/ */
String.prototype.camelize = function() { String.prototype.camelize = function() {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.camelize'}));
"Please use OpenLayers.String.camelize instead"
);
return OpenLayers.String.camelize(this); return OpenLayers.String.camelize(this);
}; };
} }
@@ -315,10 +309,8 @@ if (!Number.prototype.limitSigDigs) {
* If null, 0, or negative value passed in, returns 0 * If null, 0, or negative value passed in, returns 0
*/ */
Number.prototype.limitSigDigs = function(sig) { Number.prototype.limitSigDigs = function(sig) {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.limitSigDigs'}));
"Please use OpenLayers.Number.limitSigDigs instead"
);
return OpenLayers.Number.limitSigDigs(this, sig); return OpenLayers.Number.limitSigDigs(this, sig);
}; };
} }
@@ -388,10 +380,8 @@ if (!Function.prototype.bind) {
* argument. * argument.
*/ */
Function.prototype.bind = function() { Function.prototype.bind = function() {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.bind'}));
"Please use OpenLayers.Function.bind instead"
);
// new function takes the same arguments with this function up front // new function takes the same arguments with this function up front
Array.prototype.unshift.apply(arguments, [this]); Array.prototype.unshift.apply(arguments, [this]);
return OpenLayers.Function.bind.apply(null, arguments); return OpenLayers.Function.bind.apply(null, arguments);
@@ -411,10 +401,8 @@ if (!Function.prototype.bindAsEventListener) {
* {Function} * {Function}
*/ */
Function.prototype.bindAsEventListener = function(object) { Function.prototype.bindAsEventListener = function(object) {
OpenLayers.Console.warn( OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
"This method has been deprecated and will be removed in 3.0. " + {'newMethod':'OpenLayers.String.bindAsEventListener'}));
"Please use OpenLayers.Function.bindAsEventListener instead"
);
return OpenLayers.Function.bindAsEventListener(this, object); return OpenLayers.Function.bindAsEventListener(this, object);
}; };
} }

View File

@@ -232,7 +232,7 @@ OpenLayers.Bounds = OpenLayers.Class({
*/ */
add:function(x, y) { add:function(x, y) {
if ( (x == null) || (y == null) ) { if ( (x == null) || (y == null) ) {
var msg = "You must pass both x and y values to the add function."; var msg = OpenLayers.i18n("boundsAddError");
OpenLayers.Console.error(msg); OpenLayers.Console.error(msg);
return null; return null;
} }

View File

@@ -84,8 +84,7 @@ OpenLayers.LonLat = OpenLayers.Class({
*/ */
add:function(lon, lat) { add:function(lon, lat) {
if ( (lon == null) || (lat == null) ) { if ( (lon == null) || (lat == null) ) {
var msg = "You must pass both lon and lat values " + var msg = OpenLayers.i18n("lonlatAddError");
"to the add function.";
OpenLayers.Console.error(msg); OpenLayers.Console.error(msg);
return null; return null;
} }

View File

@@ -91,7 +91,7 @@ OpenLayers.Pixel = OpenLayers.Class({
*/ */
add:function(x, y) { add:function(x, y) {
if ( (x == null) || (y == null) ) { if ( (x == null) || (y == null) ) {
var msg = "You must pass both x and y values to the add function."; var msg = OpenLayers.i18n("pixelAddError");
OpenLayers.Console.error(msg); OpenLayers.Console.error(msg);
return null; return null;
} }

View File

@@ -504,7 +504,7 @@ OpenLayers.Control.LayerSwitcher =
this.baseLbl = document.createElement("div"); this.baseLbl = document.createElement("div");
this.baseLbl.innerHTML = "<u>Base Layer</u>"; this.baseLbl.innerHTML = OpenLayers.i18n("baseLayer");
this.baseLbl.style.marginTop = "3px"; this.baseLbl.style.marginTop = "3px";
this.baseLbl.style.marginLeft = "3px"; this.baseLbl.style.marginLeft = "3px";
this.baseLbl.style.marginBottom = "3px"; this.baseLbl.style.marginBottom = "3px";
@@ -517,7 +517,7 @@ OpenLayers.Control.LayerSwitcher =
this.dataLbl = document.createElement("div"); this.dataLbl = document.createElement("div");
this.dataLbl.innerHTML = "<u>Overlays</u>"; this.dataLbl.innerHTML = OpenLayers.i18n("overlays");
this.dataLbl.style.marginTop = "3px"; this.dataLbl.style.marginTop = "3px";
this.dataLbl.style.marginLeft = "3px"; this.dataLbl.style.marginLeft = "3px";
this.dataLbl.style.marginBottom = "3px"; this.dataLbl.style.marginBottom = "3px";

View File

@@ -498,7 +498,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
// as the base layer for the main map. This should be made more robust. // as the base layer for the main map. This should be made more robust.
if(this.map.units != 'degrees') { if(this.map.units != 'degrees') {
if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) {
alert('The overview map only works when it is in the same projection as the main map'); alert(OpenLayers.i18n("sameProjection"));
} }
} }
var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent()); var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent());

View File

@@ -111,7 +111,7 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
if (!this.element) { if (!this.element) {
this.div.className = this.displayClass; this.div.className = this.displayClass;
this.element = document.createElement("a"); this.element = document.createElement("a");
this.element.innerHTML = "Permalink"; this.element.innerHTML = OpenLayers.i18n("permalink");
this.element.href=""; this.element.href="";
this.div.appendChild(this.element); this.div.appendChild(this.element);
} }

View File

@@ -68,7 +68,7 @@ OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, {
scale = Math.round(scale); scale = Math.round(scale);
} }
this.element.innerHTML = "Scale = 1 : " + scale; this.element.innerHTML = OpenLayers.i18n("scale", {'scaleDenom':scale});
}, },
CLASS_NAME: "OpenLayers.Control.Scale" CLASS_NAME: "OpenLayers.Control.Scale"

View File

@@ -68,7 +68,7 @@ OpenLayers.Format = OpenLayers.Class({
* Depends on the subclass * Depends on the subclass
*/ */
read: function(data) { read: function(data) {
alert("Read not implemented."); alert(OpenLayers.i18n("readNotImplemented"));
}, },
/** /**
@@ -82,7 +82,7 @@ OpenLayers.Format = OpenLayers.Class({
* {String} A string representation of the object. * {String} A string representation of the object.
*/ */
write: function(object) { write: function(object) {
alert("Write not implemented."); alert(OpenLayers.i18n("writeNotImplemented"));
}, },
CLASS_NAME: "OpenLayers.Format" CLASS_NAME: "OpenLayers.Format"

View File

@@ -154,8 +154,8 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
this.internalProjection); this.internalProjection);
} }
} else { } else {
OpenLayers.Console.error("Unsupported geometry type: " + OpenLayers.Console.error(OpenLayers.i18n(
type); "unsupportedGeometryType", {'geomType':type}));
} }
// stop looking for different geometry types // stop looking for different geometry types
break; break;

View File

@@ -580,8 +580,8 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
this.internalProjection); this.internalProjection);
} }
} else { } else {
OpenLayers.Console.error("Unsupported geometry type: " + OpenLayers.Console.error(OpenLayers.i18n(
type); "unsupportedGeometryType", {'geomType':type}));
} }
// stop looking for different geometry types // stop looking for different geometry types
break; break;

View File

@@ -129,7 +129,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
* feature - {<OpenLayers.Feature.Vector>} * feature - {<OpenLayers.Feature.Vector>}
*/ */
update: function(feature) { update: function(feature) {
if (!feature.fid) { alert("Can't update a feature for which there is no FID."); } if (!feature.fid) { alert(OpenLayers.i18n("noFID")); }
var updateNode = this.createElementNS(this.wfsns, 'wfs:Update'); var updateNode = this.createElementNS(this.wfsns, 'wfs:Update');
updateNode.setAttribute("typeName", this.layerName); updateNode.setAttribute("typeName", this.layerName);
@@ -186,7 +186,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
*/ */
remove: function(feature) { remove: function(feature) {
if (!feature.fid) { if (!feature.fid) {
alert("Can't delete a feature for which there is no FID."); alert(OpenLayers.i18n("noFID"));
return false; return false;
} }
var deleteNode = this.createElementNS(this.featureNS, 'wfs:Delete'); var deleteNode = this.createElementNS(this.featureNS, 'wfs:Delete');

129
lib/OpenLayers/Lang.js Normal file
View File

@@ -0,0 +1,129 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* Namespace: OpenLayers.Lang
* Internationalization namespace. Contains dictionaries in various languages
* and methods to set and get the current language.
*/
OpenLayers.Lang = {
/**
* Property: code
* {String} Current language code to use in OpenLayers. Use the
* <setCode> method to set this value and the <getCode> method to
* retrieve it.
*/
code: null,
/**
* APIProperty: defaultCode
* {String} Default language to use when a specific language can't be
* found. Default is "en".
*/
defaultCode: "en",
/**
* APIFunction: getCode
* Get the current language code.
*
* Returns:
* The current language code.
*/
getCode: function() {
if(!OpenLayers.Lang.code) {
OpenLayers.Lang.setCode();
}
return OpenLayers.Lang.code;
},
/**
* APIFunction: setCode
* Set the language code for string translation. This code is used by
* the <OpenLayers.Lang.translate> method.
*
* Parameters-
* code - {String} These codes follow the IETF recommendations at
* http://www.ietf.org/rfc/rfc3066.txt. If no value is set, the
* browser's language setting will be tested. If no <OpenLayers.Lang>
* dictionary exists for the code, the <OpenLayers.String.defaultLang>
* will be used.
*/
setCode: function(code) {
var lang;
if(!code) {
code = (OpenLayers.Util.getBrowserName() == "msie") ?
navigator.userLanguage : navigator.language;
}
var parts = code.split('-');
parts[0] = parts[0].toLowerCase();
if(typeof OpenLayers.Lang[parts[0]] == "object") {
lang = parts[0];
}
// check for regional extensions
if(parts[1]) {
var testLang = parts[0] + '-' + parts[1].toUpperCase();
if(typeof OpenLayers.Lang[testLang] == "object") {
lang = testLang;
}
}
if(!lang) {
OpenLayers.Console.warn(
'Failed to find OpenLayers.Lang.' + parts.join("-") +
' dictionary, falling back to default language'
);
lang = OpenLayers.Lang.defaultCode
}
OpenLayers.Lang.code = lang;
},
/**
* APIMethod: translate
* Looks up a key from a dictionary based on the current language string.
* The value of <getCode> will be used to determine the appropriate
* dictionary. Dictionaries are stored in <OpenLayers.Lang>.
*
* Parameters:
* key - {String} The key for an i18n string value in the dictionary.
* context - {Object} Optional context to be used with
* <OpenLayers.String.format>.
*
* Returns:
* {String} A internationalized string.
*/
translate: function(key, context) {
var dictionary = OpenLayers.Lang[OpenLayers.Lang.getCode()];
var message = dictionary[key];
if(!message) {
// Message not found, fall back to message key
message = key;
}
if(context) {
message = OpenLayers.String.format(message, context);
}
return message;
}
};
/**
* APIMethod: OpenLayers.i18n
* Alias for <OpenLayers.Lang.translate>. Looks up a key from a dictionary
* based on the current language string. The value of
* <OpenLayers.Lang.getCode> will be used to determine the appropriate
* dictionary. Dictionaries are stored in <OpenLayers.Lang>.
*
* Parameters:
* key - {String} The key for an i18n string value in the dictionary.
* context - {Object} Optional context to be used with
* <OpenLayers.String.format>.
*
* Returns:
* {String} A internationalized string.
*/
OpenLayers.i18n = OpenLayers.Lang.translate;

View File

@@ -0,0 +1,25 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Lang/en.js
*/
/**
* Namespace: OpenLayers.Lang["en-CA"]
* Dictionary for English-CA. This dictionary inherits from the standard
* English dictionary. Override only those entries with language specific
* to the CA region.
*
* Keys for entries are used in calls to <OpenLayers.Lang.translate>. Entry
* bodies are normal strings or strings formatted for use with
* <OpenLayers.String.format> calls.
*/
OpenLayers.Lang['en-CA'] = OpenLayers.Util.applyDefaults({
// add any entries specific for this region here
// e.g.
// "someKey": "Some regionally specific value"
}, OpenLayers.Lang["en"]);

120
lib/OpenLayers/Lang/en.js Normal file
View File

@@ -0,0 +1,120 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Lang.js
*/
/**
* Namespace: OpenLayers.Lang["en"]
* Dictionary for English. Keys for entries are used in calls to
* <OpenLayers.Lang.translate>. Entry bodies are normal strings or
* strings formatted for use with <OpenLayers.String.format> calls.
*/
OpenLayers.Lang.en = {
'unhandledRequest': "Unhandled request return ${statusText}",
'permalink': "Permalink",
'overlays': "Overlays",
'baseLayer': "Base Layer",
'sameProjection':
"The overview map only works when it is in the same projection as the main map",
'readNotImplemented': "Read not implemented.",
'writeNotImplemented': "Write not implemented.",
'noFID': "Can't update a feature for which there is no FID.",
'errorLoadingGML': "Error in loading GML file ${url}",
'browserNotSupported':
"Your browser does not support vector rendering. Currently supported renderers are:\n${renderers}",
'componentShouldBe': "addFeatures : component should be an ${geomType}",
// console message
'getFeatureError':
"getFeatureFromEvent called on layer with no renderer. This usually means you " +
"destroyed a layer, but not some handler which is associated with it.",
// console message
'minZoomLevelError':
"The minZoomLevel property is only intended for use " +
"with the FixedZoomLevels-descendent layers. That this " +
"wfs layer checks for minZoomLevel is a relic of the" +
"past. We cannot, however, remove it without possibly " +
"breaking OL based applications that may depend on it." +
" Therefore we are deprecating it -- the minZoomLevel " +
"check below will be removed at 3.0. Please instead " +
"use min/max resolution setting as described here: " +
"http://trac.openlayers.org/wiki/SettingZoomLevels",
'commitSuccess': "WFS Transaction: SUCCESS ${response}",
'commitFailed': "WFS Transaction: FAILED ${response}",
'googleWarning':
"The Google Layer was unable to load correctly.<br><br>" +
"To get rid of this message, select a new BaseLayer " +
"in the layer switcher in the upper-right corner.<br><br>" +
"Most likely, this is because the Google Maps library " +
"script was either not included, or does not contain the " +
"correct API key for your site.<br><br>" +
"Developers: For help getting this working correctly, " +
"<a href='http://trac.openlayers.org/wiki/Google' " +
"target='_blank'>click here</a>",
'getLayerWarning':
"The ${layerType} Layer was unable to load correctly.<br><br>" +
"To get rid of this message, select a new BaseLayer " +
"in the layer switcher in the upper-right corner.<br><br>" +
"Most likely, this is because the ${layerLib} library " +
"script was either not correctly included.<br><br>" +
"Developers: For help getting this working correctly, " +
"<a href='http://trac.openlayers.org/wiki/${layerLib}' " +
"target='_blank'>click here</a>",
'scale': "Scale = 1 : ${scaleDenom}",
// console message
'layerAlreadyAdded':
"You tried to add the layer: ${layerName} to the map, but it has already been added",
// console message
'reprojectDeprecated':
"You are using the 'reproject' option " +
"on the ${layerName} layer. This option is deprecated: " +
"its use was designed to support displaying data over commercial " +
"basemaps, but that functionality should now be achieved by using " +
"Spherical Mercator support. More information is available from " +
"http://trac.openlayers.org/wiki/SphericalMercator.",
// console message
'methodDeprecated':
"This method has been deprecated and will be removed in 3.0. " +
"Please use ${newMethod} instead.",
// console message
'boundsAddError': "You must pass both x and y values to the add function.",
// console message
'lonlatAddError': "You must pass both lon and lat values to the add function.",
// console message
'pixelAddError': "You must pass both x and y values to the add function.",
// console message
'unsupportedGeometryType': "Unsupported geometry type: ${geomType}",
// console message
'pagePositionFailed':
"OpenLayers.Util.pagePosition failed: element with id ${elemId} may be misplaced.",
'end': ''
};

19
lib/OpenLayers/Lang/fr.js Normal file
View File

@@ -0,0 +1,19 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Lang.js
*/
/**
* Namespace: OpenLayers.Lang["fr"]
* Dictionary for French. Keys for entries are used in calls to
* <OpenLayers.Lang.translate>. Entry bodies are normal strings or
* strings formatted for use with <OpenLayers.String.format> calls.
*/
OpenLayers.Lang.fr = {
'overlays': "Couches de superposition"
};

View File

@@ -157,7 +157,7 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
* request - {String} * request - {String}
*/ */
requestFailure: function(request) { requestFailure: function(request) {
alert("Error in loading GML file "+this.url); alert(OpenLayers.i18n("errorLoadingGML", {'url':this.url}));
this.events.triggerEvent("loadend"); this.events.triggerEvent("loadend");
}, },

View File

@@ -309,24 +309,7 @@ OpenLayers.Layer.Google = OpenLayers.Class(
* it working. * it working.
*/ */
getWarningHTML:function() { getWarningHTML:function() {
return OpenLayers.i18n("googleWarning");
var html = "";
html += "The Google Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, select a new BaseLayer ";
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the Google Maps library";
html += " script was either not included, or does not contain the";
html += " correct API key for your site.<br>";
html += "<br>";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/Google' ";
html += "target='_blank'>";
html += "click here";
html += "</a>";
return html;
}, },

View File

@@ -97,23 +97,9 @@ OpenLayers.Layer.MultiMap = OpenLayers.Class(
* it working. * it working.
*/ */
getWarningHTML:function() { getWarningHTML:function() {
return OpenLayers.i18n(
var html = ""; "getLayerWarning", {'layerType':"MM", 'layerLib':"MultiMap"}
html += "The MM Layer was unable to load correctly.<br>"; );
html += "<br>";
html += "To get rid of this message, select a new BaseLayer ";
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the MM library";
html += " script was either not correctly included.<br>";
html += "<br>";
html += "Demmlopers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/MultiMap' ";
html += "target='_blank'>";
html += "click here";
html += "</a>";
return html;
}, },

View File

@@ -214,10 +214,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
*/ */
displayError: function() { displayError: function() {
if (this.reportError) { if (this.reportError) {
var message = "Your browser does not support vector rendering. " + alert(OpenLayers.i18n("browserNotSupported",
"Currently supported renderers are:\n"; {'renderers':this.renderers.join("\n")}));
message += this.renderers.join("\n");
alert(message);
} }
}, },
@@ -309,11 +307,11 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
var feature = features[i]; var feature = features[i];
if (this.geometryType && if (this.geometryType &&
!(feature.geometry instanceof this.geometryType)) { !(feature.geometry instanceof this.geometryType)) {
var throwStr = "addFeatures : component should be an " + var throwStr = OpenLayers.i18n('componentShouldBe',
this.geometryType.prototype.CLASS_NAME; {'geomType':this.geometryType.prototype.CLASS_NAME});
throw throwStr; throw throwStr;
} }
this.features.push(feature); this.features.push(feature);
@@ -450,7 +448,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
*/ */
getFeatureFromEvent: function(evt) { getFeatureFromEvent: function(evt) {
if (!this.renderer) { if (!this.renderer) {
OpenLayers.Console.error("getFeatureFromEvent called on layer with no renderer. This usually means you destroyed a layer, but not some handler which is associated with it."); OpenLayers.Console.error(OpenLayers.i18n("getFeatureError"));
return null; return null;
} }
var featureId = this.renderer.getFeatureIdFromEvent(evt); var featureId = this.renderer.getFeatureIdFromEvent(evt);

View File

@@ -137,23 +137,9 @@ OpenLayers.Layer.VirtualEarth = OpenLayers.Class(
* it working. * it working.
*/ */
getWarningHTML:function() { getWarningHTML:function() {
return OpenLayers.i18n(
var html = ""; "getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'}
html += "The VE Layer was unable to load correctly.<br>"; );
html += "<br>";
html += "To get rid of this message, select a new BaseLayer ";
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the VE library";
html += " script was either not correctly included.<br>";
html += "<br>";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/VirtualEarth' ";
html += "target='_blank'>";
html += "click here";
html += "</a>";
return html;
}, },

View File

@@ -234,17 +234,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
//DEPRECATED - REMOVE IN 3.0 //DEPRECATED - REMOVE IN 3.0
// don't load data if current zoom level doesn't match // don't load data if current zoom level doesn't match
if (this.options.minZoomLevel) { if (this.options.minZoomLevel) {
OpenLayers.Console.warn(OpenLayers.i18n('minZoomLevelError'));
var err = "The minZoomLevel property is only intended for use " +
"with the FixedZoomLevels-descendent layers. That this " +
"wfs layer checks for minZoomLevel is a relic of the" +
"past. We cannot, however, remove it without possibly " +
"breaking OL based applications that may depend on it." +
" Therefore we are deprecating it -- the minZoomLevel " +
"check below will be removed at 3.0. Please instead " +
"use min/max resolution setting as described here: " +
"http://trac.openlayers.org/wiki/SettingZoomLevels";
OpenLayers.Console.warn(err);
if (this.map.getZoom() < this.options.minZoomLevel) { if (this.map.getZoom() < this.options.minZoomLevel) {
return null; return null;
@@ -481,7 +471,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
commitSuccess: function(request) { commitSuccess: function(request) {
var response = request.responseText; var response = request.responseText;
if (response.indexOf('SUCCESS') != -1) { if (response.indexOf('SUCCESS') != -1) {
this.commitReport('WFS Transaction: SUCCESS', response); this.commitReport(OpenLayers.i18n("commitSuccess", {'response':response}));
for(var i = 0; i < this.features.length; i++) { for(var i = 0; i < this.features.length; i++) {
this.features[i].state = null; this.features[i].state = null;
@@ -490,7 +480,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
// foreach features: set state to null // foreach features: set state to null
} else if (response.indexOf('FAILED') != -1 || } else if (response.indexOf('FAILED') != -1 ||
response.indexOf('Exception') != -1) { response.indexOf('Exception') != -1) {
this.commitReport('WFS Transaction: FAILED', response); this.commitReport(OpenLayers.i18n("commitFailed", {'response':response}));
} }
}, },

View File

@@ -155,23 +155,9 @@ OpenLayers.Layer.Yahoo = OpenLayers.Class(
* it working. * it working.
*/ */
getWarningHTML:function() { getWarningHTML:function() {
return OpenLayers.i18n(
var html = ""; "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
html += "The Yahoo Layer was unable to load correctly.<br>"; );
html += "<br>";
html += "To get rid of this message, select a new BaseLayer ";
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the Yahoo library";
html += " script was either not correctly included.<br>";
html += "<br>";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/Yahoo' ";
html += "target='_blank'>";
html += "click here";
html += "</a>";
return html;
}, },
/********************************************************/ /********************************************************/

View File

@@ -726,8 +726,8 @@ OpenLayers.Map = OpenLayers.Class({
addLayer: function (layer) { addLayer: function (layer) {
for(var i=0; i < this.layers.length; i++) { for(var i=0; i < this.layers.length; i++) {
if (this.layers[i] == layer) { if (this.layers[i] == layer) {
var msg = "You tried to add the layer: " + layer.name + var msg = OpenLayers.i18n('layerAlreadyAdded',
" to the map, but it has already been added"; {'layerName':layer.name});
OpenLayers.Console.warn(msg); OpenLayers.Console.warn(msg);
return false; return false;
} }

View File

@@ -213,12 +213,9 @@ OpenLayers.Tile = OpenLayers.Class({
* bounds - {<OpenLayers.Bounds>} * bounds - {<OpenLayers.Bounds>}
*/ */
getBoundsFromBaseLayer: function(position) { getBoundsFromBaseLayer: function(position) {
OpenLayers.Console.warn("You are using the 'reproject' option " + var msg = OpenLayers.i18n('reprojectDeprecated',
"on the " + this.layer.name + " layer. This option is deprecated: " + {'layerName':this.layer.name});
"its use was designed to support displaying data over commercial " + OpenLayers.Console.warn(msg);
"basemaps, but that functionality should now be achieved by using " +
"Spherical Mercator support. More information is available from " +
"http://trac.openlayers.org/wiki/SphericalMercator.");
var topLeft = this.layer.map.getLonLatFromLayerPx(position); var topLeft = this.layer.map.getLonLatFromLayerPx(position);
var bottomRightPx = position.clone(); var bottomRightPx = position.clone();
bottomRightPx.x += this.size.w; bottomRightPx.x += this.size.w;

View File

@@ -100,9 +100,11 @@ OpenLayers.Util.removeItem = function(array, item) {
* array - {Array} * array - {Array}
*/ */
OpenLayers.Util.clearArray = function(array) { OpenLayers.Util.clearArray = function(array) {
var msg = "OpenLayers.Util.clearArray() is Deprecated." + OpenLayers.Console.warn(
" Please use 'array.length = 0' instead."; OpenLayers.i18n(
OpenLayers.Console.warn(msg); "methodDeprecated", {'newMethod': 'array = []'}
)
);
array.length = 0; array.length = 0;
}; };
@@ -866,10 +868,11 @@ OpenLayers.Util.getParameters = function(url) {
* {Object} An object of key/value pairs from the query string. * {Object} An object of key/value pairs from the query string.
*/ */
OpenLayers.Util.getArgs = function(url) { OpenLayers.Util.getArgs = function(url) {
var err = "The getArgs() function is deprecated and will be removed " + OpenLayers.Console.warn(
"with the 3.0 version of OpenLayers. Please instead use " + OpenLayers.i18n(
"OpenLayers.Util.getParameters()."; "methodDeprecated", {'newMethod': 'OpenLayers.Util.getParameters'}
OpenLayers.Console.warn(err); )
);
return OpenLayers.Util.getParameters(url); return OpenLayers.Util.getParameters(url);
}; };
@@ -1042,10 +1045,8 @@ OpenLayers.Util.pagePosition = function(forElement) {
// wrapping this in a try/catch because IE chokes on the offsetParent // wrapping this in a try/catch because IE chokes on the offsetParent
element = element.offsetParent; element = element.offsetParent;
} catch(e) { } catch(e) {
OpenLayers.Console.error( OpenLayers.Console.error(OpenLayers.i18n(
"OpenLayers.Util.pagePosition failed: element with id " + "pagePositionFailed",{'elemId':element.id}));
element.id + " may be misplaced."
);
break; break;
} }
} }

View File

@@ -49,6 +49,7 @@
<li>Rule/test_Logical.html</li> <li>Rule/test_Logical.html</li>
<li>test_Events.html</li> <li>test_Events.html</li>
<li>test_Util.html</li> <li>test_Util.html</li>
<li>test_Lang.html</li>
<li>test_Layer.html</li> <li>test_Layer.html</li>
<li>test_Renderer.html</li> <li>test_Renderer.html</li>
<li>Layer/test_EventPane.html</li> <li>Layer/test_EventPane.html</li>

106
tests/test_Lang.html Normal file
View File

@@ -0,0 +1,106 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script src="../lib/OpenLayers/Lang/en-CA.js" type="text/javascript"></script>
<script src="../lib/OpenLayers/Lang/fr.js" type="text/javascript"></script>
<script type="text/javascript">
function test_setCode(t) {
t.plan(4);
OpenLayers.Lang.code = null;
// test with no argument - this could result in the default or the
// browser language if a dictionary exists
OpenLayers.Lang.setCode();
t.ok(OpenLayers.Lang.code != null,
"code set when no argument is sent");
var primary = "xx";
var subtag = "XX";
var code = primary + "-" + subtag;
OpenLayers.Lang[code] = {};
// test code for dictionary that exists
OpenLayers.Lang.setCode(code);
t.eq(OpenLayers.Lang.code, code,
"code properly set for existing dictionary");
// test code for dictionary that doesn't exist
OpenLayers.Lang.setCode(primary + "-YY");
t.eq(OpenLayers.Lang.code, OpenLayers.Lang.defaultCode,
"code set to default for non-existing dictionary");
// test code for existing primary but missing subtag
OpenLayers.Lang[primary] = {};
OpenLayers.Lang.setCode(primary + "-YY");
t.eq(OpenLayers.Lang.code, primary,
"code set to primary when subtag dictionary is missing");
// clean up
delete OpenLayers.Lang[code];
delete OpenLayers.Lang[primary];
OpenLayers.Lang.code = null;
}
function test_getCode(t) {
t.plan(3);
OpenLayers.Lang.code = null;
// test that a non-null value is retrieved - could be browser language
// or defaultCode
var code = OpenLayers.Lang.getCode();
t.ok(code != null, "returns a non-null code");
t.ok(OpenLayers.Lang.code != null, "sets the code to a non-null value");
// test that the code is returned if non-null
OpenLayers.Lang.code = "foo";
t.eq(OpenLayers.Lang.getCode(), "foo", "returns the code if non-null");
// clean up
OpenLayers.Lang.code = null;
}
function test_i18n(t) {
t.plan(1);
t.ok(OpenLayers.i18n === OpenLayers.Lang.translate,
"i18n is an alias for OpenLayers.Lang.translate");
}
function test_translate(t) {
var keys = ['test1', 'test3', 'noKey'];
var codes = ['en', 'en-CA', 'fr', 'fr-CA', 'sw'];
var result = {
'en': {'overlays':'Overlays',
'unhandledRequest':'Unhandled request return foo',
'noKey':'noKey'},
'en-CA': {'overlays':'Overlays',
'unhandledRequest':'Unhandled request return foo',
'noKey':'noKey'},
'fr': {'overlays':'Couches de superposition',
'unhandledRequest':'unhandledRequest', // not translated
'noKey':'noKey'},
'fr-CA': {'overlays':'Couches de superposition', //this should result in 'fr'
'unhandledRequest':'unhandledRequest', // not translated
'noKey':'noKey'},
'sw': {'overlays':'Overlays', //this should result in 'en'
'unhandledRequest':'Unhandled request return foo',
'noKey':'noKey'}
};
t.plan(keys.length*codes.length);
for (var i=0; i<codes.length; ++i) {
var code = codes[i];
OpenLayers.Lang.setCode(code);
t.eq(OpenLayers.Lang.translate('overlays'), result[code]['overlays'], "simple key lookup in "+code);
t.eq(OpenLayers.Lang.translate('unhandledRequest',{'statusText':'foo'}),
result[code]['unhandledRequest'], "lookup with argument substitution in "+code);
t.eq(OpenLayers.Lang.translate('noKey'), result[code]['noKey'], "invalid key returns the key in "+code);
}
}
</script>
</head>
<body>
</body>
</html>