language.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .. _sld_language:
  2. i18N in SLD
  3. ================
  4. This section describes how to specify metadata (titles and abstracts) in different languages in SLD documents.
  5. Metadata in different languages
  6. -------------------------------
  7. GeoServer extends Title and Abstract sections, so that text in different languages can be included.
  8. This is an example of the syntax to use:
  9. .. code-block:: xml
  10. <Title>This is the default title
  11. <Localized lang="en">English title</Localized>
  12. <Localized lang="it">Titolo in italiano</Localized>
  13. </Title>
  14. A default text (``This is the default title`` in the example) and a set of Localized sections, one for each language that you want to support.
  15. Each ``Localized`` section specifies the language (using a two letter abbreviation in the ``lang`` attribute) and the related text.
  16. Currently, GeoServer supports localized text in SLD in WMS GetLegendGraphic requests (legends that contain labels are rendered using the
  17. requested language, if a ``LANGUAGE`` parameter is added to the request, e.g. ``LANGUAGE=it``).
  18. Using the language function
  19. ---------------------------
  20. GeoServer provides a ``language`` function that can be used to get the ``LANGUAGE`` requested in ``GetMap`` or ``GetFeatureInfo`` request. The function can be used to generate maps whose symbology is language dependent.
  21. Here is an example providing **labels in multiple languages**, integrating the ``language`` function with ``Recode`` e.g:
  22. .. code-block:: xml
  23. <TextSymbolizer>
  24. <Label>
  25. <ogc:Function name="Recode">
  26. <ogc:Function name="language"/>
  27. <ogc:Literal/>
  28. <ogc:PropertyName>name_default</ogc:PropertyName>
  29. <ogc:Literal>en</ogc:Literal>
  30. <ogc:PropertyName>name_en</ogc:PropertyName>
  31. <ogc:Literal>it</ogc:Literal>
  32. <ogc:PropertyName>name_it</ogc:PropertyName>
  33. <ogc:Literal>fr</ogc:Literal>
  34. <ogc:PropertyName>name_fr</ogc:PropertyName>
  35. </ogc:Function>
  36. </Label>
  37. <Fill>
  38. <CssParameter name="fill">#000000</CssParameter>
  39. </Fill>
  40. </TextSymbolizer>
  41. The empty ``<ogc:Literal/>`` elements acts as the default language, matching a value with a missing language parameter. If there is no default value,the default language will be returned. See :ref:`internationalization` for details on ``Default Language``.
  42. It is also possible to use the ``language`` function in a rule filter, **filtering rules
  43. for both rendering and legend production** purposes. This one shows how to refer to different symbols
  44. based on the current language:
  45. .. code-block:: xml
  46. <Rule>
  47. <ogc:Filter>
  48. <ogc:PropertyIsEqualTo>
  49. <ogc:Function name="language"/>
  50. <ogc:Literal>it</ogc:Literal>
  51. </ogc:PropertyIsEqualTo>
  52. </ogc:Filter>
  53. <PointSymbolizer>
  54. <Graphic>
  55. <ExternalGraphic>
  56. <OnlineResource xlink:type="simple" xlink:href="it_symbol.png"/>
  57. <Format>image/png</Format>
  58. </ExternalGraphic>
  59. <Size>32</Size>
  60. </Graphic>
  61. </PointSymbolizer>
  62. </Rule>
  63. <Rule>
  64. <ogc:Filter>
  65. <ogc:PropertyIsEqualTo>
  66. <ogc:Function name="language"/>
  67. <ogc:Literal>de</ogc:Literal>
  68. </ogc:PropertyIsEqualTo>
  69. </ogc:Filter>
  70. <PointSymbolizer>
  71. <Graphic>
  72. <ExternalGraphic>
  73. <OnlineResource xlink:type="simple" xlink:href="de_symbol.png"/>
  74. <Format>image/png</Format>
  75. </ExternalGraphic>
  76. <Size>32</Size>
  77. </Graphic>
  78. </PointSymbolizer>
  79. </Rule>
  80. Specifically for the external graphics, if the external symbols are all co-located, and follow
  81. a naming convention including the language identifier, then it's also possible to **embed the
  82. language in the symbol URL**:
  83. .. code-block:: xml
  84. <Rule>
  85. <PointSymbolizer>
  86. <Graphic>
  87. <ExternalGraphic>
  88. <OnlineResource xlink:type="simple" xlink:href="${language()}_symbol.png"/>
  89. <Format>image/png</Format>
  90. </ExternalGraphic>
  91. <Size>32</Size>
  92. </Graphic>
  93. </PointSymbolizer>
  94. </Rule>