Your Digital Media Has Never Looked So Good

 
rrobinson
Topic Author
Posts: 12
Joined: Sun May 23, 2010 7:55 pm

Adding Translations <solved>

Sun May 23, 2010 8:24 pm

I was wanting to add translations through an http request returning xml.
I have the bright script code working and the backend server code written.
I'm using a mysql database with utf8_general_ci encoding.

On some translations, the simple ones, french, spanish etc. (haven't even tried chinese yet ) If I hardcode the translation
in the bright script it displays properly. But if I try sending it through the xml the parser ( xml.Parse )
fails.

1. Translation is coming out of database in utf8 format
2. I've tried converting to utf8 coming out of the database, this
lets the parser work but the chars are wrong, of course.
3. I've tried decoding the utf8 coming out of the database and
the parser works but again, of course again, the chars are wrong

Note: I tried 2 and 3 just in case bright script was doing some conversion with the text

4. I've tried with and without a CDATA wrapper
5. I've read through the documentation and found nothing useful.
Kinda feel like I'm programming Basic again.
I was going to try to serialize or json encode the transfer but
nothing short of writing a decoder would let me test this and I'm
still not sure it would work. ( unless I missed something in the docs )
I still may try it though.
6. I'm using a utf8 header in the xml
7. I've tried looping through the string and converting it to char codes

Was wondering if anyone here had any suggestions or knowledge that this won't work
before I go further.

I just designed and coded an app translated to 13 languages, thought I had
a pretty good handle on it ;)

I'm hoping to learn something new today!
Last edited by rrobinson on Sun May 23, 2010 11:51 pm, edited 1 time in total.
 
rrobinson
Topic Author
Posts: 12
Joined: Sun May 23, 2010 7:55 pm

Re: Adding Translations

Sun May 23, 2010 8:35 pm

Just in case anyone wanted a sample of xml that fails parsing for me.
This is a google translate so please excuse my spanish ;)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<translations>
   <translation>
      <from><![CDATA[This player is already registered]]></from>
      <to><![CDATA[Este reproductor ya está registrado]]></to>
   </translation>
   <translation>
      <from><![CDATA[Registered to]]></from>
      <to><![CDATA[Registrado a]]></to>
   </translation>
   <translation>
      <from><![CDATA[Player can only be registered to one account at a time]]></from>
      <to><![CDATA[El jugador solo puede ser registrado para una cuenta a la vez]]></to>
   </translation>
   <translation>
      <from><![CDATA[If you would like to connect it to another account it has to be removed from the above account first]]></from>
      <to><![CDATA[Si desea que la una a otra cuenta que tiene que ser removido de la cuenta por encima de primera está]]></to>
   </translation>
   <translation>
      <from><![CDATA[Select 'ok' to exit this screen.]]></from>
      <to><![CDATA[Seleccione "Aceptar" para salir de esta pantalla.]]></to>
   </translation>
</translations>
 
rrobinson
Topic Author
Posts: 12
Joined: Sun May 23, 2010 7:55 pm

Re: Adding Translations <solved>

Sun May 23, 2010 11:59 pm

Just in case anyone comes across this.
I converted the string to it's ord numbers, ';' seperated, before packaging in the xml

for example in php
        $ord_string = "";
        for( $i = 0; $i < strlen( $translation['t_translated'] ); $i++ ) {
            $ord_string .= ord( $translation['t_translated'][$i] ) . ";";
        }


gave me something like this:
101;99;99;105;111;110;101;32;34;65;99;101;112;116;97; (and on, and on, and on)

then i wrote a britescript function to convert it back to a string
I kept searching for a strtok function, oh well...
Function convertOrdToChar( in_string as String ) as String
      ' create a copy to work with
      tmp_string = in_string
      out_string = ""
      while true
         if tmp_string = "" then
            return out_string
         endif
         cutoff = instr( 1, tmp_string, ";" )
         print "cutoff: " + itostr( cutoff )
         ord = val( left( tmp_string, cutoff ) )
         print "ord: " + itostr( ord )
         out_string = out_string + chr( ord )
         print "out_string: " + out_string
         tmp_string = mid( tmp_string, cutoff + 1 )
         print "tmp_string: " + tmp_string
      end while

End Function


Any one want to take a shot at making that function cleaner, be my guest
Be interesting to see what others come up with.
 
User avatar
RokuKevin
Roku Engineering
Posts: 796
Joined: Tue Sep 22, 2009 2:29 pm

Re: Adding Translations <solved>

Mon May 24, 2010 9:48 am

We have not added unicode (utf-8 or utf-16) support to BrightScript yet... There may be a few places where BrightScript assumes utf-8 (like in the manifest file), but the parser is not one of them.

Displaying multi-byte characters like chinese in BrightScript strings is not possible on the Roku box at this time.

--Kevin
 
rrobinson
Topic Author
Posts: 12
Joined: Sun May 23, 2010 7:55 pm

Re: Adding Translations <solved>

Mon May 24, 2010 9:56 am

Thanks for the fast reply!
Saved me a ton of time on testing.
 
rcelestino
Posts: 10
Joined: Fri May 28, 2010 10:35 am

Re: Adding Translations <solved>

Sat May 29, 2010 4:48 pm

RokuKevin wrote:
We have not added unicode (utf-8 or utf-16) support to BrightScript yet... There may be a few places where BrightScript assumes utf-8 (like in the manifest file), but the parser is not one of them.

Displaying multi-byte characters like chinese in BrightScript strings is not possible on the Roku box at this time.

--Kevin


Hi, i had recently posted a question about charsets, and rrobinson replied to me about this post.Then i read this post, and Kevin:
-Where is utf-8 supported?
-When you say "parser", told about BrightScript parser or roXMLElement Parser? because when i am using a string with tilde's for example "hélló fróm árgéñtina" this is working correctly, but when i am reading from an XML (inside the standalone package zip or remotely got from a request to a REST api [encoded in UTF-8]) it doesnt work in ifParagraphScreen.AddHeaderText but work OK if i use in a content list for example ifPosterScreen setContentList.

Thanks and regards.

roberto.
 
jlfreund
Posts: 24
Joined: Sat Dec 15, 2012 10:53 am
Location: Cupertino, CA

Re: Adding Translations <solved>

Thu Sep 12, 2013 11:14 am

RokuKevin wrote:
We have not added unicode (utf-8 or utf-16) support to BrightScript yet... There may be a few places where BrightScript assumes utf-8 (like in the manifest file), but the parser is not one of them.

Displaying multi-byte characters like chinese in BrightScript strings is not possible on the Roku box at this time.

--Kevin


It sounds like it's only possible to use single byte languages with Brightscript, which limits to EFIGS -- is that correct? If so, does the default font have glyphs for all the accented characters up to U+00FF (y with 2 dots)?

I'm wondering if you know if any parts of Brightscript support multibyte now (ie XML parsing, Brightscript string handling, DrawText, etc)? Or do you know if there are any plans to fully support multi-byte in the future? If not, I guess the only way to do it would be to do something like what rrobinson suggested which is to pre-convert UTF-8 to some kind of intermediate format, then when it comes time to render the string, you can compute the position and render one character at a time.

Thanks
 
destruk
Posts: 2720
Joined: Sat Dec 18, 2010 4:58 pm

Re: Adding Translations <solved>

Thu Sep 12, 2013 1:43 pm

and this thread is only 3 years old, yippee.

Who is online

Users browsing this forum: No registered users and 9 guests