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/Lang/en.js
*/
(function() {
@@ -201,7 +202,9 @@
"OpenLayers/Layer/WFS.js",
"OpenLayers/Control/MouseToolbar.js",
"OpenLayers/Control/NavToolbar.js",
"OpenLayers/Control/EditingToolbar.js"
"OpenLayers/Control/EditingToolbar.js",
"OpenLayers/Lang.js",
"OpenLayers/Lang/en.js"
); // etc.
var agent = navigator.userAgent;

View File

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

View File

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

View File

@@ -232,7 +232,7 @@ OpenLayers.Bounds = OpenLayers.Class({
*/
add:function(x, y) {
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);
return null;
}

View File

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

View File

@@ -91,7 +91,7 @@ OpenLayers.Pixel = OpenLayers.Class({
*/
add:function(x, y) {
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);
return null;
}

View File

@@ -504,7 +504,7 @@ OpenLayers.Control.LayerSwitcher =
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.marginLeft = "3px";
this.baseLbl.style.marginBottom = "3px";
@@ -517,7 +517,7 @@ OpenLayers.Control.LayerSwitcher =
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.marginLeft = "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.
if(this.map.units != 'degrees') {
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());

View File

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

View File

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

View File

@@ -68,7 +68,7 @@ OpenLayers.Format = OpenLayers.Class({
* Depends on the subclass
*/
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.
*/
write: function(object) {
alert("Write not implemented.");
alert(OpenLayers.i18n("writeNotImplemented"));
},
CLASS_NAME: "OpenLayers.Format"

View File

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

View File

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

View File

@@ -129,7 +129,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
* feature - {<OpenLayers.Feature.Vector>}
*/
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');
updateNode.setAttribute("typeName", this.layerName);
@@ -186,7 +186,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
*/
remove: function(feature) {
if (!feature.fid) {
alert("Can't delete a feature for which there is no FID.");
alert(OpenLayers.i18n("noFID"));
return false;
}
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}
*/
requestFailure: function(request) {
alert("Error in loading GML file "+this.url);
alert(OpenLayers.i18n("errorLoadingGML", {'url':this.url}));
this.events.triggerEvent("loadend");
},

View File

@@ -309,24 +309,7 @@ OpenLayers.Layer.Google = OpenLayers.Class(
* it working.
*/
getWarningHTML:function() {
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;
return OpenLayers.i18n("googleWarning");
},

View File

@@ -97,23 +97,9 @@ OpenLayers.Layer.MultiMap = OpenLayers.Class(
* it working.
*/
getWarningHTML:function() {
var html = "";
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;
return OpenLayers.i18n(
"getLayerWarning", {'layerType':"MM", 'layerLib':"MultiMap"}
);
},

View File

@@ -214,10 +214,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
*/
displayError: function() {
if (this.reportError) {
var message = "Your browser does not support vector rendering. " +
"Currently supported renderers are:\n";
message += this.renderers.join("\n");
alert(message);
alert(OpenLayers.i18n("browserNotSupported",
{'renderers':this.renderers.join("\n")}));
}
},
@@ -310,8 +308,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
if (this.geometryType &&
!(feature.geometry instanceof this.geometryType)) {
var throwStr = "addFeatures : component should be an " +
this.geometryType.prototype.CLASS_NAME;
var throwStr = OpenLayers.i18n('componentShouldBe',
{'geomType':this.geometryType.prototype.CLASS_NAME});
throw throwStr;
}
@@ -450,7 +448,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
*/
getFeatureFromEvent: function(evt) {
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;
}
var featureId = this.renderer.getFeatureIdFromEvent(evt);

View File

@@ -137,23 +137,9 @@ OpenLayers.Layer.VirtualEarth = OpenLayers.Class(
* it working.
*/
getWarningHTML:function() {
var html = "";
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;
return OpenLayers.i18n(
"getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'}
);
},

View File

@@ -234,17 +234,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
//DEPRECATED - REMOVE IN 3.0
// don't load data if current zoom level doesn't match
if (this.options.minZoomLevel) {
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);
OpenLayers.Console.warn(OpenLayers.i18n('minZoomLevelError'));
if (this.map.getZoom() < this.options.minZoomLevel) {
return null;
@@ -481,7 +471,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
commitSuccess: function(request) {
var response = request.responseText;
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++) {
this.features[i].state = null;
@@ -490,7 +480,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
// foreach features: set state to null
} else if (response.indexOf('FAILED') != -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.
*/
getWarningHTML:function() {
var html = "";
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;
return OpenLayers.i18n(
"getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
);
},
/********************************************************/

View File

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

View File

@@ -213,12 +213,9 @@ OpenLayers.Tile = OpenLayers.Class({
* bounds - {<OpenLayers.Bounds>}
*/
getBoundsFromBaseLayer: function(position) {
OpenLayers.Console.warn("You are using the 'reproject' option " +
"on the " + this.layer.name + " 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.");
var msg = OpenLayers.i18n('reprojectDeprecated',
{'layerName':this.layer.name});
OpenLayers.Console.warn(msg);
var topLeft = this.layer.map.getLonLatFromLayerPx(position);
var bottomRightPx = position.clone();
bottomRightPx.x += this.size.w;

View File

@@ -100,9 +100,11 @@ OpenLayers.Util.removeItem = function(array, item) {
* array - {Array}
*/
OpenLayers.Util.clearArray = function(array) {
var msg = "OpenLayers.Util.clearArray() is Deprecated." +
" Please use 'array.length = 0' instead.";
OpenLayers.Console.warn(msg);
OpenLayers.Console.warn(
OpenLayers.i18n(
"methodDeprecated", {'newMethod': 'array = []'}
)
);
array.length = 0;
};
@@ -866,10 +868,11 @@ OpenLayers.Util.getParameters = function(url) {
* {Object} An object of key/value pairs from the query string.
*/
OpenLayers.Util.getArgs = function(url) {
var err = "The getArgs() function is deprecated and will be removed " +
"with the 3.0 version of OpenLayers. Please instead use " +
"OpenLayers.Util.getParameters().";
OpenLayers.Console.warn(err);
OpenLayers.Console.warn(
OpenLayers.i18n(
"methodDeprecated", {'newMethod': 'OpenLayers.Util.getParameters'}
)
);
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
element = element.offsetParent;
} catch(e) {
OpenLayers.Console.error(
"OpenLayers.Util.pagePosition failed: element with id " +
element.id + " may be misplaced."
);
OpenLayers.Console.error(OpenLayers.i18n(
"pagePositionFailed",{'elemId':element.id}));
break;
}
}

View File

@@ -49,6 +49,7 @@
<li>Rule/test_Logical.html</li>
<li>test_Events.html</li>
<li>test_Util.html</li>
<li>test_Lang.html</li>
<li>test_Layer.html</li>
<li>test_Renderer.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>