Osmarender/Localized maps with Osmarender

From OpenStreetMap Wiki
Jump to navigation Jump to search

This refers to means for selecting the language of the labels to display. For instance, a city might have names in the database in two or more languages such as name=Луцьк (this is also name:be=Луцьк) as well as name:en=Lutsk. When producing rendered maps, it may be necessary to select names with the correct tag to ensure readability for particular languages.

Simple substitution in the rules file

For a simple method, do a substitution in the Osmarender rules file (such as osm-map-features-z17.xml). For example, change each k="name" to k="name:be" for names in Belorussian and Cyrllic text. The resulting map then will only include names in the Belorussian. If the relevant language name has not been explicitly added, then no text at all will be shown. For instance, the following change for a town name will cause only names in Byelorussian to be shown in the rendered map.

    <rule e="node" k="place" v="town">
        <text k="name" class="town-caption"/>
    </rule>

to

    <rule e="node" k="place" v="town">
        <text k="name:be" class="town-caption"/>
    </rule>

Conditional change of tags

In order to get the system to substitute another name only if there is no text in the desired language, use can be made of the <else> markup. The standard rule for a town name shown above can be changed to the one below. This will look for a Belorussian name, and if one is not found, then it will instead use the default name.

    <rule e="node" k="place" v="town">
        <rule e="node" k="name:be" v="*">
	    <text k="name:be" class="town-caption"/>
	</rule>
	<else>
	    <text k="name" class="town-caption"/>
	</else>
    </rule>

Each instance of the use of 'name' in the rules file has to be separately changed and substituted.

If desired, then a name in another language can be used instead of the default name. For instance, it may be useful in the above instance to substitute k="name:ru" or k="name:ur" instead of k="name" to look for Russian and Ukrainian names if Byelorussian names are not found. The rules can also be nested further to select in sequence from more languages.