3

I'm working on my python script as I would like to store the strings in the language file called strings.po which it would allow me to change the texts in the label.

I want to know how do you write the code to input the strings in the label control using the id that I store in strings.po?

1 Answers1

2

First, for XBMC Frodo and above its suggested to use the string-ID range 32000-32999 for script add-ons.

Also, its still no requirement to use the .po format for translations, you still are allowed to use the .xml format.

Anayway, here is an example for both:

YOUR_ADDON_DIR/resources/language/english/strings.po

# XBMC Media Center language file
# Addon Provider: Tristan Fischer (sphere@dersphere.de)
msgid ""
msgstr ""
"Project-Id-Version: XBMC Addons\n"
"Report-Msgid-Bugs-To: alanwww1@xbmc.org\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: XBMC Translation Team\n"
"Language-Team: English (http://www.transifex.com/projects/p/xbmc-addons/language/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"

msgctxt "#32000"
msgid "Hello"
msgstr ""

YOUR_ADDON_DIR/resources/language/english/strings.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
    <string id="32000">Hello</string>
</strings>

Again, you don't need both, one of them is fine.

To use the "Hello"-string (with ID=32000) in the skin xml files:

<control type="label">
    <description>My hello label</description>
    <posx>0</posx>
    <posy>0</posy>
    <width>80</width>
    <height>36</height>
    <align>left</align>
    <font>font12</font>
    <textcolor>white</textcolor>
    <visible>true</visible>
    <label>$LOCALIZE[SCRIPT32000]</label>
</control>

And if you need the translation in python:

import xbmcaddon
addon = xbmcaddon.Addon()

my_hello_string = addon.getLocalizedString(32000)
sphere
  • 1,330
  • 13
  • 24
  • Thanks for this sphere. Do I have to use the same ID for other languages? if so how do xbmc will know what language i'm looking for if i want to read for french language that have the same ID as the english one? –  Jan 20 '14 at 03:01
  • @user3179027: Yes, of course the IDs need to be the same. XBMC will automatically look for the strings in the language the user has set in the xbmc locale settings. Please consider accepting my answer if it was helpful. – sphere Jan 20 '14 at 10:30
  • oh ok I got it now thanks for your help. I have accepted your answer as it was very helpful. Thank you!!! –  Jan 20 '14 at 20:11
  • I have forgot to ask you a question. I want to know how do you create the variable to allow me to load the strings from one language folder, e.g. french and how do you get the id from the strings.xml to put it on the control when you create the variable name? –  Jan 26 '14 at 03:05