WindowXML: is this a bug, a feature or what?
#1
Hi dear developers!

I just wanted to write a script with localized labels, something like this:

scriptname/default.py
Code:
import xbmc,xbmcgui
import os

CWD = os.getcwd()
print CWD
__language__ = xbmc.Language(CWD).getLocalizedString
print xbmc.getLanguage()
ACTION_EXIT_SCRIPT      = (9, 10)

class MainGUI(xbmcgui.WindowXML):
        def __init__(self,*args,**kwargs):
                xbmcgui.WindowXML.__init__(self)
        def onInit(self):
                pass
        def onAction(self,action):
                if (action in ACTION_EXIT_SCRIPT):
                        self.close()
        def onClick(self,controlId):
                pass
        def onFocus(self,controlId):
                pass

if __name__ == '__main__':
        ui = MainGUI("main.xml",CWD)
        ui.doModal()
        del ui

scriptname/resources/skins/Default/PAL/main.xml
Code:
<window>
        <controls>
                <control type="label">
                        <description>XBMC PBX Addon</description>
                        <posx>150</posx>
                        <posy>40</posy>
                        <align>right</align>
                        <label>This: $LOCALIZE[32000]</label>
                        <font>special14</font>
                </control>
        </controls>
</window>

scriptanme/resources/language/English/strings.xml
Code:
<strings>
        <string id="32000">Hello world!</string>
</strings>

scriptname/resources/settings.xml
Code:
<settings>
</settings>

For some reason, first time I run this script I just get a label with "This:" when I expected to see "This: Hello world!".
However, if you access script settings (via context menu) and just click ok (as there is nothing to configure), next time you run the script you will get a label with "This: Hello world!".

If you happen to modify strings.xml (without restarting XBMC), let's say you change "Hello world!" with "XBMC!", and run the script again, you will get a label with "This: Hello world!".
Now, if you access the script settings (via context menu) again, and then run the script, you will now get "This: XBMC!".

So, in conclusion, Labels are not localized as I understand it should work.
I've been reading the online manual (wiki), searching on some others code (from xbmc-addon, etc), and I can't still figure out if this is a bug, a feature or just me doing something wrong.

Hope someone can guide me here!

Thanks a lot!
Hernan.-
Reply
#2
This has changed anyway - the language module is no longer. It's all accessed via the xbmcaddon module.

If there's issues with that we need to fix it, but I suspect it'll be a bit better.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
I'm running into the same problems. I'm having problems with no localized strings being displayed in the script's skin. Tried using $LOCALIZE[32000] with having:

__settings__ = xbmcaddon.Addon(__scriptID__)
__language__ = __settings__.getLocalizedString

in the default.py.

I'm not sure how to display localized strings inside a localized script's skin.
Reply
#4
You need to use $ADDON IIRC.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
I figured out how to do it.. Thanks...
Reply
#6
giftie Wrote:I figured out how to do it.. Thanks...

could you please elaborate?

Thanks!
Hernán.-
Reply
#7
Not a problem... This is how I was able to get them to show up...

from the skin's xml file:
Code:
<control type="label" id="109">
            <description>Local Artist Count</description>
            <posx>10</posx>
            <posy>470</posy>
            <width>240</width>
            <height>30</height>
            <font>font18</font>
            <textcolor>white</textcolor>
            <aligny>center</aligny>
            <align>center</align>
        </control>
        
        <control type="label" id="110">
            <description>Local Album Count</description>
            <posx>10</posx>
            <posy>500</posy>
            <width>240</width>
            <height>30</height>
            <font>font18</font>
            <textcolor>white</textcolor>
            <aligny>center</aligny>
            <align>center</align>
        </control>
        
        <control type="label" id="112">
            <description>Local CDArt Count</description>
            <posx>10</posx>
            <posy>530</posy>
            <width>240</width>
            <height>30</height>
            <font>font18</font>
            <textcolor>white</textcolor>
            <aligny>center</aligny>
            <align>center</align>
        </control>

You will notice the <control type="label" id="109"> and no actual <label></label> set


From the script:
Code:
self.getControl( 109 ).setLabel( _(32007) % local_artist_count)
        self.getControl( 110 ).setLabel( _(32010) % local_album_count)
        self.getControl( 112 ).setLabel( _(32008) % local_cdart_count)

I have set my language code as:
Code:
_              = sys.modules[ "__main__" ].__language__

which is the equivalent to this (my default.py calls gui.py so I need to have a call back to the default.py):
Code:
__settings__ = xbmcaddon.Addon(__scriptID__)
__language__ = __settings__.getLocalizedString

Does this help?

I believe this will work for what you supplied:

-> main.xml
Code:
<window>
        <controls>
                [b]<control type="label" id="100">[/b]
                        <description>XBMC PBX Addon</description>
                        <posx>150</posx>
                        <posy>40</posy>
                        <align>right</align>
                        <font>special14</font>
                </control>
        </controls>
</window>

-> script
Code:
[b]__script__    = "XBMC PBX Addon"
__scriptID__ = "script.pbxaddon"      #folder name of the script[/b]

import xbmc,xbmcgui
import os
[b]import xbmcaddon[/b]

[b]__settings__ = xbmcaddon.Addon(__scriptID__)
__language__ = __settings__.getLocalizedString[/b]

ACTION_EXIT_SCRIPT      = (9, 10)

class MainGUI(xbmcgui.WindowXML):
        def __init__(self,*args,**kwargs):
                xbmcgui.WindowXML.__init__(self)
        def onInit(self):
                setup_labels()

        [b]def setup_labels(self)
                self.getControl( 100 ).setLabel( __language__(32000) )[/b]

        def onAction(self,action):
                if (action in ACTION_EXIT_SCRIPT):
                        self.close()
        def onClick(self,controlId):
                pass
        def onFocus(self,controlId):
                pass

if __name__ == '__main__':
        ui = MainGUI("main.xml",CWD)
        ui.doModal()
        del ui

The items in bold are the changes...
Reply
#8
Thanks, that helped!, I'm now doing something like what you have described.

However, that's exactly what I wanted to avoid, because having $LOCALIZE available on skin side there should be no reason to localize strings on script side.

I mean, I wanted the skin code (presentation layer) to be as much independent from script code (logic layer) as possible, as in a three-tier model: http://en.wikipedia.org/wiki/Multitier_architecture

I hope this is addressed with the new xbmcaddon module. Otherwise I would be more than glad to open a ticket.

Regards,
Hernan.-
Reply
#9
This is what $ADDON does for you, doesn't it?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#10
Do you mean that we should set the label as:
Code:
<label>$ADDON[32000]</label>
Reply
#11
$ADDON[addon.id stringid]
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#12
understood... now my script can shrink...
Reply
#13
The space between the scriptID and the string # is very important... I missed it the first time around and could not figure out why XBMC was restarting..
Reply

Logout Mark Read Team Forum Stats Members Help
WindowXML: is this a bug, a feature or what?0