From fa55f54e3249c8960b6930b936a2d36b2b5c458e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 15 Feb 2008 21:15:48 +0000 Subject: [PATCH] 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 --- lib/OpenLayers.js | 5 +- lib/OpenLayers/Ajax.js | 2 +- lib/OpenLayers/BaseTypes.js | 50 ++++----- lib/OpenLayers/BaseTypes/Bounds.js | 2 +- lib/OpenLayers/BaseTypes/LonLat.js | 3 +- lib/OpenLayers/BaseTypes/Pixel.js | 2 +- lib/OpenLayers/Control/LayerSwitcher.js | 4 +- lib/OpenLayers/Control/OverviewMap.js | 2 +- lib/OpenLayers/Control/Permalink.js | 2 +- lib/OpenLayers/Control/Scale.js | 2 +- lib/OpenLayers/Format.js | 4 +- lib/OpenLayers/Format/GML.js | 4 +- lib/OpenLayers/Format/KML.js | 4 +- lib/OpenLayers/Format/WFS.js | 4 +- lib/OpenLayers/Lang.js | 129 ++++++++++++++++++++++++ lib/OpenLayers/Lang/en-CA.js | 25 +++++ lib/OpenLayers/Lang/en.js | 120 ++++++++++++++++++++++ lib/OpenLayers/Lang/fr.js | 19 ++++ lib/OpenLayers/Layer/GML.js | 2 +- lib/OpenLayers/Layer/Google.js | 19 +--- lib/OpenLayers/Layer/MultiMap.js | 20 +--- lib/OpenLayers/Layer/Vector.js | 18 ++-- lib/OpenLayers/Layer/VirtualEarth.js | 20 +--- lib/OpenLayers/Layer/WFS.js | 16 +-- lib/OpenLayers/Layer/Yahoo.js | 20 +--- lib/OpenLayers/Map.js | 4 +- lib/OpenLayers/Tile.js | 9 +- lib/OpenLayers/Util.js | 23 +++-- tests/list-tests.html | 1 + tests/test_Lang.html | 106 +++++++++++++++++++ 30 files changed, 479 insertions(+), 162 deletions(-) create mode 100644 lib/OpenLayers/Lang.js create mode 100644 lib/OpenLayers/Lang/en-CA.js create mode 100644 lib/OpenLayers/Lang/en.js create mode 100644 lib/OpenLayers/Lang/fr.js create mode 100644 tests/test_Lang.html diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index ebc8f120bb..66835d6cb9 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -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; diff --git a/lib/OpenLayers/Ajax.js b/lib/OpenLayers/Ajax.js index 8eee0b9742..e31ef4b484 100644 --- a/lib/OpenLayers/Ajax.js +++ b/lib/OpenLayers/Ajax.js @@ -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})); }; /** diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 72bd20f607..b0fdfaea93 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -9,9 +9,10 @@ * @requires OpenLayers/BaseTypes/Pixel.js * @requires OpenLayers/BaseTypes/Bounds.js * @requires OpenLayers/BaseTypes/Element.js + * @requires OpenLayers/Lang/en.js */ - -/** + +/** * Header: OpenLayers Base Types * OpenLayers custom string, number and function functions are described here. */ @@ -23,6 +24,7 @@ *********************/ OpenLayers.String = { + /** * APIFunction: OpenLayers.String.startsWith * Test whether a string starts with another string. @@ -90,7 +92,7 @@ OpenLayers.String = { } return camelizedString; }, - + /** * APIFunction: OpenLayers.String.format * 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. */ 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); }; } diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 8adb0d99b0..f474a45d61 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -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; } diff --git a/lib/OpenLayers/BaseTypes/LonLat.js b/lib/OpenLayers/BaseTypes/LonLat.js index e76e3d8e97..4c78af43cf 100644 --- a/lib/OpenLayers/BaseTypes/LonLat.js +++ b/lib/OpenLayers/BaseTypes/LonLat.js @@ -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; } diff --git a/lib/OpenLayers/BaseTypes/Pixel.js b/lib/OpenLayers/BaseTypes/Pixel.js index cbe6685c18..5d111198a1 100644 --- a/lib/OpenLayers/BaseTypes/Pixel.js +++ b/lib/OpenLayers/BaseTypes/Pixel.js @@ -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; } diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index d90e30ec7c..73c4b17852 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -504,7 +504,7 @@ OpenLayers.Control.LayerSwitcher = this.baseLbl = document.createElement("div"); - this.baseLbl.innerHTML = "Base Layer"; + 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 = "Overlays"; + this.dataLbl.innerHTML = OpenLayers.i18n("overlays"); this.dataLbl.style.marginTop = "3px"; this.dataLbl.style.marginLeft = "3px"; this.dataLbl.style.marginBottom = "3px"; diff --git a/lib/OpenLayers/Control/OverviewMap.js b/lib/OpenLayers/Control/OverviewMap.js index f63e1016c1..d1ef3efa32 100644 --- a/lib/OpenLayers/Control/OverviewMap.js +++ b/lib/OpenLayers/Control/OverviewMap.js @@ -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()); diff --git a/lib/OpenLayers/Control/Permalink.js b/lib/OpenLayers/Control/Permalink.js index 8f2a727449..60d5dfd342 100644 --- a/lib/OpenLayers/Control/Permalink.js +++ b/lib/OpenLayers/Control/Permalink.js @@ -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); } diff --git a/lib/OpenLayers/Control/Scale.js b/lib/OpenLayers/Control/Scale.js index a9825ff586..f23beaddcf 100644 --- a/lib/OpenLayers/Control/Scale.js +++ b/lib/OpenLayers/Control/Scale.js @@ -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" diff --git a/lib/OpenLayers/Format.js b/lib/OpenLayers/Format.js index 9c47f57f43..c6f02d1edd 100644 --- a/lib/OpenLayers/Format.js +++ b/lib/OpenLayers/Format.js @@ -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" diff --git a/lib/OpenLayers/Format/GML.js b/lib/OpenLayers/Format/GML.js index f41f4bbefb..c0e5f1346a 100644 --- a/lib/OpenLayers/Format/GML.js +++ b/lib/OpenLayers/Format/GML.js @@ -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; diff --git a/lib/OpenLayers/Format/KML.js b/lib/OpenLayers/Format/KML.js index a99dbef6a9..225fe64304 100644 --- a/lib/OpenLayers/Format/KML.js +++ b/lib/OpenLayers/Format/KML.js @@ -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; diff --git a/lib/OpenLayers/Format/WFS.js b/lib/OpenLayers/Format/WFS.js index 8965a41c06..6c701f2bcb 100644 --- a/lib/OpenLayers/Format/WFS.js +++ b/lib/OpenLayers/Format/WFS.js @@ -129,7 +129,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, { * 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'); 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'); diff --git a/lib/OpenLayers/Lang.js b/lib/OpenLayers/Lang.js new file mode 100644 index 0000000000..567a50b241 --- /dev/null +++ b/lib/OpenLayers/Lang.js @@ -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 + * method to set this value and the 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 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 + * dictionary exists for the code, the + * 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 will be used to determine the appropriate + * dictionary. Dictionaries are stored in . + * + * Parameters: + * key - {String} The key for an i18n string value in the dictionary. + * context - {Object} Optional context to be used with + * . + * + * 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 . Looks up a key from a dictionary + * based on the current language string. The value of + * will be used to determine the appropriate + * dictionary. Dictionaries are stored in . + * + * Parameters: + * key - {String} The key for an i18n string value in the dictionary. + * context - {Object} Optional context to be used with + * . + * + * Returns: + * {String} A internationalized string. + */ +OpenLayers.i18n = OpenLayers.Lang.translate; \ No newline at end of file diff --git a/lib/OpenLayers/Lang/en-CA.js b/lib/OpenLayers/Lang/en-CA.js new file mode 100644 index 0000000000..437776ddf2 --- /dev/null +++ b/lib/OpenLayers/Lang/en-CA.js @@ -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 . Entry + * bodies are normal strings or strings formatted for use with + * 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"]); diff --git a/lib/OpenLayers/Lang/en.js b/lib/OpenLayers/Lang/en.js new file mode 100644 index 0000000000..f69597f2b3 --- /dev/null +++ b/lib/OpenLayers/Lang/en.js @@ -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 + * . Entry bodies are normal strings or + * strings formatted for use with 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.

" + + "To get rid of this message, select a new BaseLayer " + + "in the layer switcher in the upper-right corner.

" + + "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.

" + + "Developers: For help getting this working correctly, " + + "click here", + + 'getLayerWarning': + "The ${layerType} Layer was unable to load correctly.

" + + "To get rid of this message, select a new BaseLayer " + + "in the layer switcher in the upper-right corner.

" + + "Most likely, this is because the ${layerLib} library " + + "script was either not correctly included.

" + + "Developers: For help getting this working correctly, " + + "click here", + + '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': '' +}; diff --git a/lib/OpenLayers/Lang/fr.js b/lib/OpenLayers/Lang/fr.js new file mode 100644 index 0000000000..86094155b1 --- /dev/null +++ b/lib/OpenLayers/Lang/fr.js @@ -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 + * . Entry bodies are normal strings or + * strings formatted for use with calls. + */ +OpenLayers.Lang.fr = { + + 'overlays': "Couches de superposition" + +}; diff --git a/lib/OpenLayers/Layer/GML.js b/lib/OpenLayers/Layer/GML.js index 168fd1f471..2d5360fcc3 100644 --- a/lib/OpenLayers/Layer/GML.js +++ b/lib/OpenLayers/Layer/GML.js @@ -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"); }, diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index efe770b818..705dbdbf1c 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -309,24 +309,7 @@ OpenLayers.Layer.Google = OpenLayers.Class( * it working. */ getWarningHTML:function() { - - var html = ""; - html += "The Google Layer was unable to load correctly.
"; - html += "
"; - html += "To get rid of this message, select a new BaseLayer "; - html += "in the layer switcher in the upper-right corner.
"; - html += "
"; - 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.
"; - html += "
"; - html += "Developers: For help getting this working correctly, "; - html += "} */ 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; diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 0c98a87f1c..31d2c42d77 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -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; } } diff --git a/tests/list-tests.html b/tests/list-tests.html index 89bdc61e98..8200ffb170 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -49,6 +49,7 @@
  • Rule/test_Logical.html
  • test_Events.html
  • test_Util.html
  • +
  • test_Lang.html
  • test_Layer.html
  • test_Renderer.html
  • Layer/test_EventPane.html
  • diff --git a/tests/test_Lang.html b/tests/test_Lang.html new file mode 100644 index 0000000000..1842050df0 --- /dev/null +++ b/tests/test_Lang.html @@ -0,0 +1,106 @@ + + + + + + + + + +