The problem:
The GeoServer documentation suggests that internationalized SLDs and thus internationalized legends can be supported using the ogc:language() function and rules. How do I configure an SLD to pass a raster legend in English or in French using the language parameter?
The example in the GeoServer documentation makes it look simple but I am only able to retrieve the first rule no matter the language parameter in the url GetLegendGraphic request. The documentation states:
It is also possible to use the language function in a rule filter, filtering rules for both rendering and legend production purposes. This one shows how to refer to different symbols based on the current language:
I’ve also seen that GEOS-10207 suggests that using hideEmptyRules can be used but the hideEmptyRules flag is not set by default in the GetLegendGraphic call included in the GetCapabilities and so this doesn’t seem like a great option.
I’m guessing I’m doing something wrong or interpreting something wrong but to me it seems like a language function in a filter with in a rule should let me return different legends depending on the legend parameter.
Example SLD
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0" xmlns:gml="http://www.opengis.net/gml">
<UserLayer>
<Name>User Layer Name</Name>
<LayerFeatureConstraints>
<FeatureTypeConstraint/>
</LayerFeatureConstraints>
<UserStyle>
<Name>User Style Name</Name>
<Title>User Style Title
<Localized lang="en">User Style Title</Localized>
<Localized lang="fr">User Style Title in French</Localized>
</Title>
<Abstract>User Style Abstract
<Localized lang="en">User Style Abstract</Localized>
<Localized lang="fr">User Style Abstract in French</Localized>
</Abstract>
<FeatureTypeStyle>
<Name>Feature Type Style Name</Name>
<Title>Feature Type Style Title
<Localized lang="en">Feature Type Style Title</Localized>
<Localized lang="fr">Feature Type Style Title in French</Localized>
</Title>
<Abstract>Feature Type Style Abstract
<Localized lang="en">Feature Type Style Abstract</Localized>
<Localized lang="fr">Feature Type Style Abstract in French</Localized>
</Abstract>
<Rule>
<Name>French Legend Rule</Name>
<Title>FRENCH Rule Title</Title>
<Abstract>FRENCH Rule Abstract</Abstract>
<ogc:Filter>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:Function name="language"/>
<ogc:Literal>fr</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:Function name="language"/>
<ogc:Literal>fr-CA</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:Filter>
<sld:RasterSymbolizer>
<ChannelSelection>
<GrayChannel>
<SourceChannelName>1</SourceChannelName>
</GrayChannel>
</ChannelSelection>
<ColorMap type="values">
<sld:ColorMapEntry quantity="1" color="#d1ff73" label="FRENCH Class 1 Label"/>
<sld:ColorMapEntry quantity="2" color="#226633" label="FRENCH Class 2 Label"/>
<sld:ColorMapEntry quantity="3" color="#83c795" label="FRENCH Class 3 Label"/>
<sld:ColorMapEntry quantity="4" color="#70a800" label="FRENCH Class 4 Label"/>
<sld:ColorMapEntry quantity="5" color="#dfb8e6" label="FRENCH Class 5 Label"/>
<sld:ColorMapEntry quantity="7" color="#700cf2" label="FRENCH Class 7 Label"/>
<sld:ColorMapEntry quantity="11" color="#c4bd97" label="FRENCH Class 11 Label"/>
<sld:ColorMapEntry quantity="13" color="#c4bd97" label="FRENCH Class 13 Label"/>
<sld:ColorMapEntry quantity="31" color="#ffffbe" label="FRENCH Class 31 Label"/>
<sld:ColorMapEntry quantity="101" color="#828282" label="FRENCH Class 101 Label"/>
<sld:ColorMapEntry quantity="102" color="#73dfff" label="FRENCH Class 102 Label"/>
<sld:ColorMapEntry quantity="105" color="#cccccc" label="FRENCH Class 105 Label"/>
<sld:ColorMapEntry quantity="415" color="#ffd37f" label="FRENCH Class 415 Label"/>
<sld:ColorMapEntry quantity="625" color="#ffd37f" label="FRENCH Class 625 Label"/>
<sld:ColorMapEntry quantity="650" color="#ffd37f" label="FRENCH Class 650 Label"/>
<sld:ColorMapEntry quantity="675" color="#ffd37f" label="FRENCH Class 675 Label"/>
</ColorMap>
</sld:RasterSymbolizer>
</Rule>
<Rule>
<Name>English Legend Rule Name</Name>
<Title>English Legend Rule Title</Title>
<Abstract>FEnglish Legend Rule Abstract</Abstract>
<ogc:Filter>
<ogc:Or><ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:Function name="language"/>
<ogc:Literal>en</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:Function name="language"/>
<ogc:Literal>en-CA</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:Function name="language"/>
<ogc:Literal/>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:Filter>
<sld:RasterSymbolizer>
<ChannelSelection>
<GrayChannel>
<SourceChannelName>1</SourceChannelName>
</GrayChannel>
</ChannelSelection>
<ColorMap type="values">
<sld:ColorMapEntry quantity="1" color="#d1ff73" label="ENGLISH Class 1 Label"/>
<sld:ColorMapEntry quantity="2" color="#226633" label="ENGLISH Class 2 Label"/>
<sld:ColorMapEntry quantity="3" color="#83c795" label="ENGLISH Class 3 Label"/>
<sld:ColorMapEntry quantity="4" color="#70a800" label="ENGLISH Class 4 Label"/>
<sld:ColorMapEntry quantity="5" color="#dfb8e6" label="ENGLISH Class 5 Label"/>
<sld:ColorMapEntry quantity="7" color="#700cf2" label="ENGLISH Class 7 Label"/>
<sld:ColorMapEntry quantity="11" color="#c4bd97" label="ENGLISH Class 11 Label"/>
<sld:ColorMapEntry quantity="13" color="#c4bd97" label="ENGLISH Class 13 Label"/>
<sld:ColorMapEntry quantity="31" color="#ffffbe" label="ENGLISH Class 31 Label"/>
<sld:ColorMapEntry quantity="101" color="#828282" label="ENGLISH Class 101 Label"/>
<sld:ColorMapEntry quantity="102" color="#73dfff" label="ENGLISH Class 102 Label"/>
<sld:ColorMapEntry quantity="105" color="#cccccc" label="ENGLISH Class 105 Label"/>
<sld:ColorMapEntry quantity="415" color="#ffd37f" label="ENGLISH Class 415 Label"/>
<sld:ColorMapEntry quantity="625" color="#ffd37f" label="ENGLISH Class 625 Label"/>
<sld:ColorMapEntry quantity="650" color="#ffd37f" label="ENGLISH Class 650 Label"/>
<sld:ColorMapEntry quantity="675" color="#ffd37f" label="ENGLISH Class 675 Label"/>
</ColorMap>
</sld:RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</UserLayer>
</StyledLayerDescriptor>
Example SLD returns.
Url: MYURL/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=public:mylayer&style=public:test&Language=fr
Url2: MMYURL/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=public:mylayer&style=public:test&Language=en
My geoserver version is 2.23.