Kodi 19: Using language labels in addon settings
#1
Just upgrading an addon I have for Kodi 19.  The old strings.xml file is no longer supported and a strings.po is. The documentation is incomplete however:

https://kodi.wiki/view/Language_support

And I see a possible opportunity to improve readability of settings.xml.

Traditionally settings.xml references labels with an id. a number from 32001 up. Really poor readability in the definition files alas.

The .po format defines a label with three properties like:

msgctxt "#32001"
msgid "Recommended"
msgstr ""

Some clear confusion here. For starters the old id seems encoded in ctxt not in id and the id is now a string.

Does this mean we can improve horrid settings like:

<string id="32001">Recommended</string>

to read:

<string id="Recommended">Recommended</string>

Now that would rock!

It also fails to document what msgstr is. There's a sample on that page above:

msgid ""
msgstr ""
"Project-Id-Version: Kodi Addons\n"
"Report-Msgid-Bugs-To: alanwww1@kodi.org\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: English (http://www.transifex.com/projects/p/xbmc...age/en/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

Wholly unexplained but seems to suggest that:
  • msgstr can be multline with a string per line?
  • A blank id is used to define the properties of the addon?
Sort of wishing the doc was better. Happy to do the learning and update it if a) you can help me learn and b) I can write to the Wiki.
Reply
#2
(2020-07-01, 12:43)ThumbOne Wrote: Just upgrading an addon I have for Kodi 19.  The old strings.xml file is no longer supported and a strings.po is. The documentation is incomplete however:

https://kodi.wiki/view/Language_support

And I see a possible opportunity to improve readability of settings.xml.

Traditionally settings.xml references labels with an id. a number from 32001 up. Really poor readability in the definition files alas.

The .po format defines a label with three properties like:

msgctxt "#32001"
msgid "Recommended"
msgstr ""

Some clear confusion here. For starters the old id seems encoded in ctxt not in id and the id is now a string.

Does this mean we can improve horrid settings like:

<string id="32001">Recommended</string>

to read:

<string id="Recommended">Recommended</string>

Now that would rock!

It also fails to document what msgstr is. There's a sample on that page above:

msgid ""
msgstr ""
"Project-Id-Version: Kodi Addons\n"
"Report-Msgid-Bugs-To: alanwww1@kodi.org\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: English (http://www.transifex.com/projects/p/xbmc...age/en/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

Wholly unexplained but seems to suggest that:
  • msgstr can be multline with a string per line?
  • A blank id is used to define the properties of the addon?
Sort of wishing the doc was better. Happy to do the learning and update it if a) you can help me learn and b) I can write to the Wiki.

Don't know much about strings.po, but you can get a .po editor and see how the format is on the entries.

But the goal is to move to the new settings format and all strings must be in the strings.po
Code:
<setting help="" id="search_embedded" label="32152" type="boolean">

scott s.
.
Reply
#3
Quote:<setting help="" id="search_embedded" label="32152" type="boolean">
Indeed. The docs are clear about the intent to move to the new settings format. Just not clear on whether the .po id can be used, as in:

<setting help="" id="search_embedded" label="search_embedded" type="boolean">

I can experiment of course, but I have to get the addon working at all first ;-).
Reply
#4
Have tested this a little. And it seems it's implemented in a weird and not so wonderful way. Each label has three components in the .po file: msgctxt, msgid, msgstr

And as hard as it is to believe, msgid encodes the text of the label, and msgctxt encodes the numeric ID of the label and msgstr appears to unused and consistently blank.

I wait with baited breath for better documentation on this, and even some elucidation as to why it is so bizarrely implemented. How sweet it would be to be be able to refer to labels with string ids rather than numeric ones.  But t seems not to be ...
Reply
#5
Thread moved to addon development
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#6
The "new" language files format is actually GNU Gettext adapted for Kodi. Just to be clear: Kodi does not actually use Gettext localization system but language files in Gettext-compatible format. In Gettext msgid stores a source string (that is also a string ID in real Gettext), msgstr stores a translated string and msgctxt directive was adapted to store Kodi's numeric string IDs. msgstr can be blank only in the source language file (en-GB) and in translation files it is blank only if the string is not translated.
Reply
#7
And in the new settings format, the "label" must be the string id msgctxt number or it will be ignored.  So as a side effect, any text you want in your settings that is shown to the user must be in your strings.po file.

As I mentioned, you can find gettext / po editors with gui front-ends, though tbh for addons just doing it by hand I find sufficient.

scott s.
.
Reply
#8
You can also use this script: https://gitlab.com/ronie/script.language-convert . It will convert both the strings.xml and the language folder layout to the new system.
Reply
#9
Thanks enormously for the hints. In summary it sounds like (from the gettext page), each label is encoded using three properties:

msgctxt context
msgid untranslated-string
msgstr translated-string

And Kodi requires that the context is in format #n where n is a number with ranges reserved as follows:
  • strings 30000 thru 30999 reserved for plugins and plugin settings
  • strings 31000 thru 31999 reserved for skins
  • strings 32000 thru 32999 reserved for scripts
  • strings 33000 thru 33999 reserved for common strings used in add-ons
The untranslated-string is always needed.

The translated-string is only needed for languages other than en-GB

There is currently no way in settings files to refer to a label using its msgid. Labels are referred to by the number encoded in msgctxt.

Unless someone corrects me here, the above I will add to the wiki page:

https://kodi.wiki/view/Add-on_settings_conversion

to aid people converting. As well as a link to: https://gitlab.com/ronie/script.language-convert

which would have been nice to know about before I converted on manually ;-).
Reply
#10
(2020-07-05, 01:42)enen92 Wrote: You can also use this script: https://gitlab.com/ronie/script.language-convert . It will convert both the strings.xml and the language folder layout to the new system.
I've used this several times.  You need to look out for xml reserved characters will cause the conversion to fail (for example & needs to be &amp;  ).

scott s.
.
Reply

Logout Mark Read Team Forum Stats Members Help
Kodi 19: Using language labels in addon settings0