Label Parsing: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
In label controls, fadelabel controls, built-in functions as well as in the LCD label definition files you can specify more than one piece of information to be displayed in a single line of text (or across multiple lines of text) by using the $INFO, $ESCINFO[] and $LOCALIZE keywords in a <label> tag. In addition to this, you can use the [[Label Formatting]] syntax to specify color and style information for the text | In label controls, fadelabel controls, built-in functions as well as in the LCD label definition files you can specify more than one piece of information to be displayed in a single line of text (or across multiple lines of text) by using the <code>$INFO[]</code>, <code>$ESCINFO[]</code>, <code>$MAP[]</code>, <code>$ESCMAP[]</code> and <code>$LOCALIZE[]</code> keywords in a <code><label></code> tag. In addition to this, you can use the [[Label Formatting]] syntax to specify color and style information for the text, changeable within a single label. | ||
=== Example === | === Example === | ||
| Line 11: | Line 11: | ||
<syntaxhighlight lang="xml" enclose="div"> | <syntaxhighlight lang="xml" enclose="div"> | ||
<label>The following will be localized from an | <label>The following will be localized from an addon strings - $ADDON[addon.id.here 32001]</label> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== How the parsing works === | === How the parsing works === | ||
# Kodi runs through and replaces any $LOCALIZE[number] blocks with the real string from strings.po. | # Kodi runs through and replaces any <code>$LOCALIZE[number]</code> blocks with the real string from <code>strings.po</code>. | ||
# Kodi then runs through and translates the $INFO[infolabel,prefix,postfix] blocks from left to right. | # Kodi then runs through and translates the <code>$INFO[infolabel,prefix,postfix]</code> blocks from left to right. | ||
# If the Info manager returns an empty string from the infolabel, then nothing is rendered for that block. | # If the Info manager returns an empty string from the infolabel, then nothing is rendered for that block. | ||
# If the Info manager returns a non-empty string from the infolabel, then Kodi prints the prefix string, then the returned infolabel information, then the postfix string. Note that any $COMMA fields are replaced by real commas, and $$ is replaced by $. | # If the Info manager returns a non-empty string from the infolabel, then Kodi prints the prefix string, then the returned infolabel information, then the postfix string. Note that any <code>$COMMA</code> fields are replaced by real commas, and <code>$$</code> is replaced by <code>$</code>. | ||
# Any pieces of information outside of the $INFO blocks are rendered unchanged. | # Any pieces of information outside of the <code>$INFO[]</code> blocks are rendered unchanged. | ||
So, in the above example, if nothing is playing then the label will print: | So, in the above example, if nothing is playing then the label will print: | ||
A good example of a<br /><br /> | <code>A good example of a</code><br /><br /> | ||
If a song is playing but it has no Title | If a song is playing but it has no Title, i.e. <code>MusicPlayer.Title</code> returns an empty string, but does have an artist, it will return: | ||
A good example of a song artist: < | <code>A good example of a song artist: <Artist></code><br /><br /> | ||
If a song is playing that has title and artist information, it will return: | If a song is playing that has title and artist information, it will return: | ||
A good example of a song title: | <code>A good example of a song title: <Title>, and a song artist: <Artist></code> | ||
<code>$ESCINFO[]</code> should be used when passing an infolabel to a built-in function, when this infolabel is likely to contain commas, <code>,</code>, and/or quotes, <code>"</code>. | |||
$ | eg: <code>PlayMedia($INFO[ListItem.Path])</code> might return: <code>PlayMedia(/some/path/with_a_file_that_includes,a_comma.avi)</code> | ||
This will be read by the built-in function generator as <code>PlayMedia</code> called with 2 parameters: <code>"/some/path/with_a_file_that_includes"</code> and <code>"a_comma.avi"</code>. | |||
If you use <code>PlayMedia($ESCINFO[ListItem.Path])</code> however, it will make sure that whatever is returned by the infolabel is sent on to the built-in as a single parameter. | |||
=== Map labels === | |||
Skins can use <code>$MAP[]</code> to translate the runtime value of an infolabel through a map defined in an includes file. | |||
<syntaxhighlight lang="xml" enclose="div"> | |||
$MAP[MapName, infolabel] | |||
</syntaxhighlight> | |||
Example: | |||
<syntaxhighlight lang="xml" enclose="div"> | |||
<label>$MAP[DefaultCodecMap, ListItem.AudioCodec]</label> | |||
</syntaxhighlight> | |||
If the map or key is not found, the raw infolabel value is returned unchanged. | |||
Prefix and postfix arguments are supported: | |||
<syntaxhighlight lang="xml" enclose="div"> | |||
<label>$MAP[DefaultCodecMap, ListItem.AudioCodec, (, )]</label> | |||
</syntaxhighlight> | |||
The escaped form <code>$ESCMAP[]</code> is also supported and behaves like <code>$ESCINFO[]</code>. See [[Skinning Manual#Maps|Maps]] for defining maps in includes files. | |||
== See also == | == See also == | ||
Latest revision as of 11:11, 1 September 2026
In label controls, fadelabel controls, built-in functions as well as in the LCD label definition files you can specify more than one piece of information to be displayed in a single line of text (or across multiple lines of text) by using the $INFO[], $ESCINFO[], $MAP[], $ESCMAP[] and $LOCALIZE[] keywords in a <label> tag. In addition to this, you can use the Label Formatting syntax to specify color and style information for the text, changeable within a single label.
Example
<label>A good example of a $INFO[MusicPlayer.Title,song title: , $COMMA and a]$INFO[MusicPlayer.Artist, song artist:]</label>
<label>$LOCALIZE[31005]</label>
<label>The following will be localized from an addon strings - $ADDON[addon.id.here 32001]</label>
How the parsing works
- Kodi runs through and replaces any
$LOCALIZE[number]blocks with the real string fromstrings.po. - Kodi then runs through and translates the
$INFO[infolabel,prefix,postfix]blocks from left to right. - If the Info manager returns an empty string from the infolabel, then nothing is rendered for that block.
- If the Info manager returns a non-empty string from the infolabel, then Kodi prints the prefix string, then the returned infolabel information, then the postfix string. Note that any
$COMMAfields are replaced by real commas, and$$is replaced by$. - Any pieces of information outside of the
$INFO[]blocks are rendered unchanged.
So, in the above example, if nothing is playing then the label will print:
A good example of a
If a song is playing but it has no Title, i.e. MusicPlayer.Title returns an empty string, but does have an artist, it will return:
A good example of a song artist: <Artist>
If a song is playing that has title and artist information, it will return:
A good example of a song title: <Title>, and a song artist: <Artist>
$ESCINFO[] should be used when passing an infolabel to a built-in function, when this infolabel is likely to contain commas, ,, and/or quotes, ".
eg: PlayMedia($INFO[ListItem.Path]) might return: PlayMedia(/some/path/with_a_file_that_includes,a_comma.avi)
This will be read by the built-in function generator as PlayMedia called with 2 parameters: "/some/path/with_a_file_that_includes" and "a_comma.avi".
If you use PlayMedia($ESCINFO[ListItem.Path]) however, it will make sure that whatever is returned by the infolabel is sent on to the built-in as a single parameter.
Map labels
Skins can use $MAP[] to translate the runtime value of an infolabel through a map defined in an includes file.
$MAP[MapName, infolabel]
Example:
<label>$MAP[DefaultCodecMap, ListItem.AudioCodec]</label>
If the map or key is not found, the raw infolabel value is returned unchanged.
Prefix and postfix arguments are supported:
<label>$MAP[DefaultCodecMap, ListItem.AudioCodec, (, )]</label>
The escaped form $ESCMAP[] is also supported and behaves like $ESCINFO[]. See Maps for defining maps in includes files.
See also
Development: