OpenLayers OpenLayers

Changeset 6313

Show
Ignore:
Timestamp:
02/15/08 16:15:48 (1 year ago)
Author:
tschaub
Message:

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)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers.js

    r6240 r6313  
    55/*  
    66 * @requires OpenLayers/BaseTypes.js 
     7 * @requires OpenLayers/Lang/en.js 
    78 */  
    89 
     
    202203            "OpenLayers/Control/MouseToolbar.js", 
    203204            "OpenLayers/Control/NavToolbar.js", 
    204             "OpenLayers/Control/EditingToolbar.js" 
     205            "OpenLayers/Control/EditingToolbar.js", 
     206            "OpenLayers/Lang.js", 
     207            "OpenLayers/Lang/en.js" 
    205208        ); // etc. 
    206209 
  • trunk/openlayers/lib/OpenLayers/Ajax.js

    r6190 r6313  
    3535*/ 
    3636OpenLayers.nullHandler = function(request) { 
    37     alert("Unhandled request return " + request.statusText); 
     37    alert(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText})); 
    3838}; 
    3939 
  • trunk/openlayers/lib/OpenLayers/BaseTypes.js

    r5686 r6313  
    1010 * @requires OpenLayers/BaseTypes/Bounds.js 
    1111 * @requires OpenLayers/BaseTypes/Element.js 
     12 * @requires OpenLayers/Lang/en.js 
    1213 */ 
    13  
    14 /** 
     14  
     15/**  
    1516 * Header: OpenLayers Base Types 
    1617 * OpenLayers custom string, number and function functions are described here. 
     
    2425 
    2526OpenLayers.String = { 
     27 
    2628    /** 
    2729     * APIFunction: OpenLayers.String.startsWith 
     
    9193        return camelizedString; 
    9294    }, 
    93  
     95     
    9496    /** 
    9597     * APIFunction: OpenLayers.String.format 
     
    142144     */ 
    143145    String.prototype.startsWith = function(sStart) { 
    144         OpenLayers.Console.warn( 
    145             "This method has been deprecated and will be removed in 3.0. " + 
    146             "Please use OpenLayers.String.startsWith instead" 
    147         ); 
     146        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     147                                {'newMethod':'OpenLayers.String.startsWith'})); 
    148148        return OpenLayers.String.startsWith(this, sStart); 
    149149    }; 
     
    162162     */ 
    163163    String.prototype.contains = function(str) { 
    164         OpenLayers.Console.warn( 
    165             "This method has been deprecated and will be removed in 3.0. " + 
    166             "Please use OpenLayers.String.contains instead" 
    167         ); 
     164        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     165                                  {'newMethod':'OpenLayers.String.contains'})); 
    168166        return OpenLayers.String.contains(this, str); 
    169167    }; 
     
    180178     */ 
    181179    String.prototype.trim = function() { 
    182         OpenLayers.Console.warn( 
    183             "This method has been deprecated and will be removed in 3.0. " + 
    184             "Please use OpenLayers.String.trim instead" 
    185         ); 
     180        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     181                                      {'newMethod':'OpenLayers.String.trim'})); 
    186182        return OpenLayers.String.trim(this); 
    187183    }; 
     
    199195     */ 
    200196    String.prototype.camelize = function() { 
    201         OpenLayers.Console.warn( 
    202             "This method has been deprecated and will be removed in 3.0. " + 
    203             "Please use OpenLayers.String.camelize instead" 
    204         ); 
     197        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     198                                  {'newMethod':'OpenLayers.String.camelize'})); 
    205199        return OpenLayers.String.camelize(this); 
    206200    }; 
     
    316310     */ 
    317311    Number.prototype.limitSigDigs = function(sig) { 
    318         OpenLayers.Console.warn( 
    319             "This method has been deprecated and will be removed in 3.0. " + 
    320             "Please use OpenLayers.Number.limitSigDigs instead" 
    321         ); 
     312        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     313                              {'newMethod':'OpenLayers.String.limitSigDigs'})); 
    322314        return OpenLayers.Number.limitSigDigs(this, sig); 
    323315    }; 
     
    389381     */ 
    390382    Function.prototype.bind = function() { 
    391         OpenLayers.Console.warn( 
    392             "This method has been deprecated and will be removed in 3.0. " + 
    393             "Please use OpenLayers.Function.bind instead" 
    394         ); 
     383        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     384                                {'newMethod':'OpenLayers.String.bind'})); 
    395385        // new function takes the same arguments with this function up front 
    396386        Array.prototype.unshift.apply(arguments, [this]); 
     
    412402     */ 
    413403    Function.prototype.bindAsEventListener = function(object) { 
    414         OpenLayers.Console.warn( 
    415             "This method has been deprecated and will be removed in 3.0. " + 
    416             "Please use OpenLayers.Function.bindAsEventListener instead" 
    417         ); 
     404        OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", 
     405                        {'newMethod':'OpenLayers.String.bindAsEventListener'})); 
    418406        return OpenLayers.Function.bindAsEventListener(this, object); 
    419407    }; 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js

    r6131 r6313  
    233233    add:function(x, y) { 
    234234        if ( (x == null) || (y == null) ) { 
    235             var msg = "You must pass both x and y values to the add function."
     235            var msg = OpenLayers.i18n("boundsAddError")
    236236            OpenLayers.Console.error(msg); 
    237237            return null; 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/LonLat.js

    r6131 r6313  
    8585    add:function(lon, lat) { 
    8686        if ( (lon == null) || (lat == null) ) { 
    87             var msg = "You must pass both lon and lat values " + 
    88                       "to the add function."; 
     87            var msg = OpenLayers.i18n("lonlatAddError"); 
    8988            OpenLayers.Console.error(msg); 
    9089            return null; 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Pixel.js

    r6131 r6313  
    9292    add:function(x, y) { 
    9393        if ( (x == null) || (y == null) ) { 
    94             var msg = "You must pass both x and y values to the add function."
     94            var msg = OpenLayers.i18n("pixelAddError")
    9595            OpenLayers.Console.error(msg); 
    9696            return null; 
  • trunk/openlayers/lib/OpenLayers/Control/LayerSwitcher.js

    r6149 r6313  
    505505 
    506506        this.baseLbl = document.createElement("div"); 
    507         this.baseLbl.innerHTML = "<u>Base Layer</u>"
     507        this.baseLbl.innerHTML = OpenLayers.i18n("baseLayer")
    508508        this.baseLbl.style.marginTop = "3px"; 
    509509        this.baseLbl.style.marginLeft = "3px"; 
     
    518518 
    519519        this.dataLbl = document.createElement("div"); 
    520         this.dataLbl.innerHTML = "<u>Overlays</u>"
     520        this.dataLbl.innerHTML = OpenLayers.i18n("overlays")
    521521        this.dataLbl.style.marginTop = "3px"; 
    522522        this.dataLbl.style.marginLeft = "3px"; 
  • trunk/openlayers/lib/OpenLayers/Control/OverviewMap.js

    r6149 r6313  
    499499        if(this.map.units != 'degrees') { 
    500500            if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { 
    501                 alert('The overview map only works when it is in the same projection as the main map'); 
     501                alert(OpenLayers.i18n("sameProjection")); 
    502502            } 
    503503        } 
  • trunk/openlayers/lib/OpenLayers/Control/Permalink.js

    r6149 r6313  
    112112            this.div.className = this.displayClass; 
    113113            this.element = document.createElement("a"); 
    114             this.element.innerHTML = "Permalink"
     114            this.element.innerHTML = OpenLayers.i18n("permalink")
    115115            this.element.href=""; 
    116116            this.div.appendChild(this.element); 
  • trunk/openlayers/lib/OpenLayers/Control/Scale.js

    r5614 r6313  
    6969        }     
    7070         
    71         this.element.innerHTML = "Scale = 1 : " + scale
     71        this.element.innerHTML = OpenLayers.i18n("scale", {'scaleDenom':scale})
    7272    },  
    7373 
  • trunk/openlayers/lib/OpenLayers/Format.js

    r5614 r6313  
    6969     */ 
    7070    read: function(data) { 
    71         alert("Read not implemented."); 
     71        alert(OpenLayers.i18n("readNotImplemented")); 
    7272    }, 
    7373     
     
    8383     */ 
    8484    write: function(object) { 
    85         alert("Write not implemented."); 
     85        alert(OpenLayers.i18n("writeNotImplemented")); 
    8686    }, 
    8787 
  • trunk/openlayers/lib/OpenLayers/Format/GML.js

    r5614 r6313  
    155155                    }                        
    156156                } else { 
    157                     OpenLayers.Console.error("Unsupported geometry type: " + 
    158                                              type); 
     157                    OpenLayers.Console.error(OpenLayers.i18n( 
     158                                "unsupportedGeometryType", {'geomType':type})); 
    159159                } 
    160160                // stop looking for different geometry types 
  • trunk/openlayers/lib/OpenLayers/Format/KML.js

    r6195 r6313  
    581581                    }                        
    582582                } else { 
    583                     OpenLayers.Console.error("Unsupported geometry type: " + 
    584                                              type); 
     583                    OpenLayers.Console.error(OpenLayers.i18n( 
     584                                "unsupportedGeometryType", {'geomType':type})); 
    585585                } 
    586586                // stop looking for different geometry types 
  • trunk/openlayers/lib/OpenLayers/Format/WFS.js

    r6150 r6313  
    130130     */ 
    131131    update: function(feature) { 
    132         if (!feature.fid) { alert("Can't update a feature for which there is no FID."); } 
     132        if (!feature.fid) { alert(OpenLayers.i18n("noFID")); } 
    133133        var updateNode = this.createElementNS(this.wfsns, 'wfs:Update'); 
    134134        updateNode.setAttribute("typeName", this.layerName); 
     
    187187    remove: function(feature) { 
    188188        if (!feature.fid) {  
    189             alert("Can't delete a feature for which there is no FID.");  
     189            alert(OpenLayers.i18n("noFID"));  
    190190            return false;  
    191191        } 
  • trunk/openlayers/lib/OpenLayers/Layer/GML.js

    r5828 r6313  
    158158     */ 
    159159    requestFailure: function(request) { 
    160         alert("Error in loading GML file "+this.url); 
     160        alert(OpenLayers.i18n("errorLoadingGML", {'url':this.url})); 
    161161        this.events.triggerEvent("loadend"); 
    162162    }, 
  • trunk/openlayers/lib/OpenLayers/Layer/Google.js

    r5614 r6313  
    310310     */ 
    311311    getWarningHTML:function() { 
    312  
    313         var html = ""; 
    314         html += "The Google Layer was unable to load correctly.<br>"; 
    315         html += "<br>"; 
    316         html += "To get rid of this message, select a new BaseLayer "; 
    317         html += "in the layer switcher in the upper-right corner.<br>"; 
    318         html += "<br>"; 
    319         html += "Most likely, this is because the Google Maps library"; 
    320         html += " script was either not included, or does not contain the"; 
    321         html += " correct API key for your site.<br>"; 
    322         html += "<br>"; 
    323         html += "Developers: For help getting this working correctly, "; 
    324         html += "<a href='http://trac.openlayers.org/wiki/Google' "; 
    325         html +=  "target='_blank'>"; 
    326         html +=     "click here"; 
    327         html += "</a>"; 
    328          
    329         return html; 
     312        return OpenLayers.i18n("googleWarning"); 
    330313    }, 
    331314 
  • trunk/openlayers/lib/OpenLayers/Layer/MultiMap.js

    r5614 r6313  
    9898     */ 
    9999    getWarningHTML:function() { 
    100  
    101         var html = ""; 
    102         html += "The MM Layer was unable to load correctly.<br>"; 
    103         html += "<br>"; 
    104         html += "To get rid of this message, select a new BaseLayer "; 
    105         html += "in the layer switcher in the upper-right corner.<br>"; 
    106         html += "<br>"; 
    107         html += "Most likely, this is because the MM library"; 
    108         html += " script was either not correctly included.<br>"; 
    109         html += "<br>"; 
    110         html += "Demmlopers: For help getting this working correctly, "; 
    111         html += "<a href='http://trac.openlayers.org/wiki/MultiMap' "; 
    112         html +=  "target='_blank'>"; 
    113         html +=     "click here"; 
    114         html += "</a>"; 
    115  
    116         return html; 
     100        return OpenLayers.i18n( 
     101            "getLayerWarning", {'layerType':"MM", 'layerLib':"MultiMap"} 
     102        ); 
    117103    }, 
    118104 
  • trunk/openlayers/lib/OpenLayers/Layer/Vector.js

    r6247 r6313  
    215215    displayError: function() { 
    216216        if (this.reportError) { 
    217             var message = "Your browser does not support vector rendering. " +  
    218                             "Currently supported renderers are:\n"; 
    219             message += this.renderers.join("\n"); 
    220             alert(message); 
     217            alert(OpenLayers.i18n("browserNotSupported",  
     218                                     {'renderers':this.renderers.join("\n")})); 
    221219        }     
    222220    }, 
     
    310308             
    311309            if (this.geometryType && 
    312                 !(feature.geometry instanceof this.geometryType)) { 
    313                     var throwStr = "addFeatures : component should be an " +  
    314                                     this.geometryType.prototype.CLASS_NAME
    315                     throw throwStr; 
    316                
     310              !(feature.geometry instanceof this.geometryType)) { 
     311                var throwStr = OpenLayers.i18n('componentShouldBe', 
     312                          {'geomType':this.geometryType.prototype.CLASS_NAME})
     313                throw throwStr; 
     314             
    317315 
    318316            this.features.push(feature); 
     
    451449    getFeatureFromEvent: function(evt) { 
    452450        if (!this.renderer) { 
    453             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.");  
     451            OpenLayers.Console.error(OpenLayers.i18n("getFeatureError"));  
    454452            return null; 
    455453        }     
  • trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js

    r5614 r6313  
    138138     */ 
    139139    getWarningHTML:function() { 
    140  
    141         var html = ""; 
    142         html += "The VE Layer was unable to load correctly.<br>"; 
    143         html += "<br>"; 
    144         html += "To get rid of this message, select a new BaseLayer "; 
    145         html += "in the layer switcher in the upper-right corner.<br>"; 
    146         html += "<br>"; 
    147         html += "Most likely, this is because the VE library"; 
    148         html += " script was either not correctly included.<br>"; 
    149         html += "<br>"; 
    150         html += "Developers: For help getting this working correctly, "; 
    151         html += "<a href='http://trac.openlayers.org/wiki/VirtualEarth' "; 
    152         html +=  "target='_blank'>"; 
    153         html +=     "click here"; 
    154         html += "</a>"; 
    155  
    156         return html; 
     140        return OpenLayers.i18n( 
     141            "getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'} 
     142        ); 
    157143    }, 
    158144 
  • trunk/openlayers/lib/OpenLayers/Layer/WFS.js

    r6171 r6313  
    235235        // don't load data if current zoom level doesn't match 
    236236        if (this.options.minZoomLevel) { 
    237              
    238             var err = "The minZoomLevel property is only intended for use " + 
    239                     "with the FixedZoomLevels-descendent layers. That this " + 
    240                     "wfs layer checks for minZoomLevel is a relic of the" + 
    241                     "past. We cannot, however, remove it without possibly " + 
    242                     "breaking OL based applications that may depend on it." + 
    243                     " Therefore we are deprecating it -- the minZoomLevel " + 
    244                     "check below will be removed at 3.0. Please instead " + 
    245                     "use min/max resolution setting as described here: " + 
    246                     "http://trac.openlayers.org/wiki/SettingZoomLevels"; 
    247             OpenLayers.Console.warn(err); 
     237            OpenLayers.Console.warn(OpenLayers.i18n('minZoomLevelError')); 
    248238             
    249239            if (this.map.getZoom() < this.options.minZoomLevel) { 
     
    482472        var response = request.responseText; 
    483473        if (response.indexOf('SUCCESS') != -1) { 
    484             this.commitReport('WFS Transaction: SUCCESS', response); 
     474            this.commitReport(OpenLayers.i18n("commitSuccess", {'response':response})); 
    485475             
    486476            for(var i = 0; i < this.features.length; i++) { 
     
    491481        } else if (response.indexOf('FAILED') != -1 || 
    492482            response.indexOf('Exception') != -1) { 
    493             this.commitReport('WFS Transaction: FAILED', response); 
     483            this.commitReport(OpenLayers.i18n("commitFailed", {'response':response})); 
    494484        } 
    495485    }, 
  • trunk/openlayers/lib/OpenLayers/Layer/Yahoo.js

    r5614 r6313  
    156156     */ 
    157157    getWarningHTML:function() { 
    158  
    159         var html = ""; 
    160         html += "The Yahoo Layer was unable to load correctly.<br>"; 
    161         html += "<br>"; 
    162         html += "To get rid of this message, select a new BaseLayer "; 
    163         html += "in the layer switcher in the upper-right corner.<br>"; 
    164         html += "<br>"; 
    165         html += "Most likely, this is because the Yahoo library"; 
    166         html += " script was either not correctly included.<br>"; 
    167         html += "<br>"; 
    168         html += "Developers: For help getting this working correctly, "; 
    169         html += "<a href='http://trac.openlayers.org/wiki/Yahoo' "; 
    170         html +=  "target='_blank'>"; 
    171         html +=     "click here"; 
    172         html += "</a>"; 
    173  
    174         return html; 
     158        return OpenLayers.i18n( 
     159            "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'} 
     160        ); 
    175161    }, 
    176162 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r6204 r6313  
    727727        for(var i=0; i < this.layers.length; i++) { 
    728728            if (this.layers[i] == layer) { 
    729                 var msg = "You tried to add the layer: " + layer.name +  
    730                           " to the map, but it has already been added"
     729                var msg = OpenLayers.i18n('layerAlreadyAdded',  
     730                                                      {'layerName':layer.name})
    731731                OpenLayers.Console.warn(msg); 
    732732                return false; 
  • trunk/openlayers/lib/OpenLayers/Tile.js

    r5854 r6313  
    214214     */ 
    215215    getBoundsFromBaseLayer: function(position) { 
    216         OpenLayers.Console.warn("You are using the 'reproject' option " + 
    217           "on the " + this.layer.name + " layer. This option is deprecated: " + 
    218           "its use was designed to support displaying data over commercial " +  
    219           "basemaps, but that functionality should now be achieved by using " + 
    220           "Spherical Mercator support. More information is available from " + 
    221           "http://trac.openlayers.org/wiki/SphericalMercator.");  
     216        var msg = OpenLayers.i18n('reprojectDeprecated', 
     217                                              {'layerName':this.layer.name}); 
     218        OpenLayers.Console.warn(msg); 
    222219        var topLeft = this.layer.map.getLonLatFromLayerPx(position);  
    223220        var bottomRightPx = position.clone(); 
  • trunk/openlayers/lib/OpenLayers/Util.js

    r5941 r6313  
    101101 */ 
    102102OpenLayers.Util.clearArray = function(array) { 
    103     var msg = "OpenLayers.Util.clearArray() is Deprecated." + 
    104               " Please use 'array.length = 0' instead."; 
    105     OpenLayers.Console.warn(msg); 
     103    OpenLayers.Console.warn( 
     104        OpenLayers.i18n( 
     105            "methodDeprecated", {'newMethod': 'array = []'} 
     106        ) 
     107    ); 
    106108    array.length = 0; 
    107109}; 
     
    867869 */ 
    868870OpenLayers.Util.getArgs = function(url) { 
    869     var err = "The getArgs() function is deprecated and will be removed " + 
    870             "with the 3.0 version of OpenLayers. Please instead use " + 
    871             "OpenLayers.Util.getParameters()."; 
    872     OpenLayers.Console.warn(err); 
     871    OpenLayers.Console.warn( 
     872        OpenLayers.i18n( 
     873            "methodDeprecated", {'newMethod': 'OpenLayers.Util.getParameters'} 
     874        ) 
     875    ); 
    873876    return OpenLayers.Util.getParameters(url); 
    874877}; 
     
    10431046            element = element.offsetParent; 
    10441047        } catch(e) { 
    1045             OpenLayers.Console.error( 
    1046                 "OpenLayers.Util.pagePosition failed: element with id " + 
    1047                 element.id + " may be misplaced." 
    1048             ); 
     1048            OpenLayers.Console.error(OpenLayers.i18n( 
     1049                                  "pagePositionFailed",{'elemId':element.id})); 
    10491050            break; 
    10501051        } 
  • trunk/openlayers/tests/list-tests.html

    r6240 r6313  
    5050    <li>test_Events.html</li> 
    5151    <li>test_Util.html</li> 
     52    <li>test_Lang.html</li> 
    5253    <li>test_Layer.html</li> 
    5354    <li>test_Renderer.html</li>