Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

GetLocalizedAsset - ( ) attempted on non-function

Hello,

I am working on localizing my channel and I wanted to use the
GetLocalizedAsset
function as this is documented as the proper way to pull localized assets.

I am using an
roListScreen
and populating it with:
    contentList = [
{
Title: tr("Live Stream"),
ID: "1",
'SDSmallIconUrl: "pkg://locale/default/images/live_stream_small.png",
'HDSmallIconUrl: "pkg://locale/default/images/live_stream_small.png",
'HDBackgroundImageUrl: "pkg://locale/default/images/live_stream_poster_art_hd.png",
'SDBackgroundImageUrl: "pkg://locale/default/images/live_stream_poster_art_sd.png",
HDBackgroundImageUrl: GetLocalizedAsset("images", "live_stream_poster_art_hd.png"),
SDBackgroundImageUrl: GetLocalizedAsset("images", "live_stream_poster_art_sd.png"),
ShortDescriptionLine1: tr("Live Stream"),
ShortDescriptionLine2: tr("Broadcasting around the world"),
CallBack: LiveStream
},
{
Title: tr("Alternate Language Live Stream"),
ID: "2",
'SDSmallIconUrl: "pkg://locale/default/images/alt_stream_small.png",
'HDSmallIconUrl: "pkg://locale/default/images/alt_stream_small.png",
'HDBackgroundImageUrl: "pkg://locale/default/images/alt_stream_poster_art_hd.png",
'SDBackgroundImageUrl: "pkg://locale/default/images/alt_stream_poster_art_sd.png",
ShortDescriptionLine1: tr("Alternate Language Live Stream"),
ShortDescriptionLine2: tr("Alternate language of our live stream"),
CallBack: AltLangStream
},
{
Title: tr("About Us"),
ID: "3",
'SDSmallIconUrl: "pkg://locale/default/images/about_small.png",
'HDSmallIconUrl: "pkg://locale/default/images/about_small.png",
'HDBackgroundImageUrl: "pkg://locale/default/images/about_us_poster_art_hd.jpg",
'SDBackgroundImageUrl: "pkg://locale/default/images/about_us_poster_art_sd.png",
ShortDescriptionLine1: tr("About Us"),
ShortDescriptionLine2: tr("Some basic information about us"),
CallBack: AboutUs
}
]


As you can see I just commented out the code that works (absolute path) but when I use the
GetLocalizedAsset
function I get the following error in the debug console:
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in ...g:/source/mainContentList.brs(12)
012: HDBackgroundImageUrl: GetLocalizedAsset("images", "live_stream_poster_art_hd.png"),
Backtrace:
Function maincontentlist() As Object
file/line: /tmp/plugin/MHAAAAdaPRGG/pkg:/source/mainContentList.brs(12)
Function main() As Void
file/line: /tmp/plugin/MHAAAAdaPRGG/pkg:/source/main.brs(16)

Local Variables:
global &h0020 rotINTERFACE:ifGlobal
m &h0010 bsc:roAssociativeArray, refcnt=3
contentlist &h0000 <uninitialized> val:Uninitialized
getlocalizedasset &h0000 <uninitialized> val:Uninitialized


line 12 is:
HDBackgroundImageUrl: GetLocalizedAsset("images", "live_stream_poster_art_hd.png"),


Am I using this wrong? Can this not be using in the main.brs? My main.brs is:
' ******************************************************************
' * This is the main function, this is the channel's starting point
' ******************************************************************
Sub Main()
print "Channel Initialized - ";
' Initialize the theme
InitTheme()
' Create screen and event listener port (roMessagePort)
screen = CreateObject("roListScreen")
port = CreateObject("roMessagePort")
' Set lister port to screen
screen.SetMessagePort(port)
' Set screen content title
screen.SetHeader( tr("Welcome to the Sonlife Network") )
' Initialize content list (main page)
contentListOptions = MainContentList()
' Assign the content list to the screen
screen.SetContent(contentListOptions)
' Show the content list
screen.show()
' Keep channel open and monitor event listener
while (true)
' Define event
event = wait(0, port)
' Check if current screen event
if (type(event) = "roListScreenEvent")
print "----------------------[ Main Page | roListScreenEvent ]----------------------"
' Check for focused item
if (event.isListItemFocused())
print "Calling Title for index: " ; event.GetIndex()
' Update breadcrumb
screen.SetBreadcrumbText(tr("Menu"), contentListOptions[event.GetIndex()].Title)
print "Calling Title Complete"
else if (event.isListItemSelected())
print "Calling Callback for index: " ; event.GetIndex() ; " - " ; contentListOptions[event.GetIndex()].Title
' Do callback when selected
contentListOptions[event.GetIndex()].CallBack()
print "Callback Complete"
endif
endif ' End Check for events
end while ' End Keep channel open
End Sub

' Checks if display is HD
Function isHD() As Boolean
di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV"
print "HDTV"
return true
else
print "Regular TV"
return false
end if
End Function

' Gets the current locale
Function getLocale() As String
di = CreateObject("roDeviceInfo")
return di.GetCurrentLocale()
End Function


MainContentList()
returns the code I pasted above.

Any help/insight on why this is throwing an error would be much appreciated.

My file structure is:
locale
|--- default
|--- images
|--- en_US
|--- images
|--- es_ES
|--- images
source

Thanks
0 Kudos
4 Replies
Highlighted
Level 9

Re: GetLocalizedAsset - ( ) attempted on non-function

GetLocalizedAsset() is a method on the roLocalization component. You need to create that component to use it, per the example here: http://sdkdocs.roku.com/pages/viewpage. ... Id=3114130
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Highlighted
Level 7

Re: GetLocalizedAsset - ( ) attempted on non-function

Thanks!

I used this post on the dev blog but there was no reference for it.

Now I have an issue where I have to initiate

loc = CreateObject("roLocalization")

in all .brs files that use it... Seems like this would be better as a global. Are there any tricks I am missing?
0 Kudos
Level 10

Re: GetLocalizedAsset - ( ) attempted on non-function

"SoN9ne" wrote:
I used this post on the dev blog but there was no reference for it.
Yes, that blog post is wrong in saying
"Localizing Your Roku Channels" wrote:
... So you would call GetLocalizedAsset as follows:
path_to_image = GetLocalizedAsset(“images”, “playbutton.png”)

Apparently Mr.Burdick could not be bothered trying the code before posting it... yuck! And RokuCo could not get their act together for almost 2 years and properly add section on localization in the SDK documentation.


"SoN9ne" wrote:
Now I have an issue where I have to initiate loc = CreateObject("roLocalization") in all .brs files that use it... Seems like this would be better as a global. Are there any tricks I am missing?
"There is no different .brs files... only Zuul" Smiley Tongue - just saying, in case you think separating in different files creates different namespaces/packages; all functions from any file are global scope. But the spirit of your question is probably that you want to use get-ass-etc in multiple functions. Here is a trick, define it as your own (global) function in one of the files and in it use a singleton:

function getLocalizedAsset(dirName as String, fileName as String) as String:
loca = m.roLocalization
if loca = invalid:
loca = createObject("roLocalization")
m.roLocalization = loca
end if
return loca.getLocalizedAsset(dirName, fileName)
end function
0 Kudos
Highlighted
Level 7

Re: GetLocalizedAsset - ( ) attempted on non-function

"EnTerr" wrote:
"SoN9ne" wrote:
Now I have an issue where I have to initiate loc = CreateObject("roLocalization") in all .brs files that use it... Seems like this would be better as a global. Are there any tricks I am missing?
"There is no different .brs files... only Zuul" Smiley Tongue - just saying, in case you think separating in different files creates different namespaces/packages; all functions from any file are global scope. But the spirit of your question is probably that you want to use get-ass-etc in multiple functions. Here is a trick, define it as your own (global) function in one of the files and in it use a singleton:

function getLocalizedAsset(dirName as String, fileName as String) as String:
loca = m.roLocalization
if loca = invalid:
loca = createObject("roLocalization")
m.roLocalization = loca
end if
return loca.getLocalizedAsset(dirName, fileName)
end function


Works perfectly! Thanks a lot
0 Kudos