How to add Japanese text?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bicobalt
Posts: 8
Joined: Mon Jun 11, 2012 3:13 am

How to add Japanese text?

Post by bicobalt » Mon Jun 11, 2012 3:26 am

I want to create an iOS game that is able to be played in English and Japanese (and possibly another language or two, but that's beside the point of this post). Whenever I've tried to type in Japanese or paste Japanese text into anything displayed to the user, the characters (the kana as well as the kanji) have come up as question marks. Is there any way I can add Japanese text to the game, or will I have to just create tiny images of each character and import them into the game?

Also, haha, how do I bring images into LiveCode? I'm completely new to the software, as in I haven't done anything beyond creating cards, buttons, and text fields with little to no function. Basically, I have to get good at the software really quickly. Luckily, I'm only in high school, so I have few obligations during the day, but I only have - at the most - a couple of months to have my game done.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Mon Jun 11, 2012 9:40 am

Hi,

Where do you get the Japanese text from? Do you have the Japanese language pack installed (on Mac it is called something like Asian Language Support and you have to install it from your OSX installation disk).

You can add images in several way. For example, copy an image and paste it into LiveCode or drag an image object from the tools palette and use the properties inspector to set its filename or import an image using he Import As Control or the Import As Referenced Control submenus in the File menu.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to add Japanese text?

Post by Klaus » Mon Jun 11, 2012 2:11 pm

Hi bicobalt,

welcome to the forum! :D

Please check these stacks, great learning resources:
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

bicobalt
Posts: 8
Joined: Mon Jun 11, 2012 3:13 am

Re: How to add Japanese text?

Post by bicobalt » Mon Jun 11, 2012 4:50 pm

Mark wrote:Hi,

Where do you get the Japanese text from? Do you have the Japanese language pack installed (on Mac it is called something like Asian Language Support and you have to install it from your OSX installation disk).

You can add images in several way. For example, copy an image and paste it into LiveCode or drag an image object from the tools palette and use the properties inspector to set its filename or import an image using he Import As Control or the Import As Referenced Control submenus in the File menu.

Kind regards,

Mark
Actually, now that I think about it, I don't have it on the Mac I use. I do have the setup necessary to type in Japanese on the Windows PC I use; so far I've just used Google Translate for the bulk of the text I've tried to incorporate and fudged in the rest using copied-and-pasted characters from Japanese Wikipedia. Yes, I do speak Japanese well enough not to need Google Translate, but it's a quick way to get the bulk of each sentence down before fine-tuning it.

Since I have no idea where the installation disk is, I think from now on I'll just write out everything I want to on my Windows PC in a Word document and then export it. All of this is a stilted and crude system, but someday I'll have something better.

...That is, if the Japanese text won't just come in as question marks anyway...

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Mon Jun 11, 2012 5:13 pm

Hi,

You can't display Japanese text in LiveCode on OSX if the Japanese language pack isn't installed, evenif you write it in a Word file on Windows first. If you're using Lion, then your "install disk" is the Lion installer in the applications folder.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Mon Apr 22, 2013 7:42 am

Hello!

I am also having trouble displaying Japanese text on the toast messages of my iPad app.

I can display Spanish and French texts, but when I try Japanese, it displays correctly on the screen, but not on toasts messages. What could be the problem?


Thanks,
Genie

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Mon Apr 22, 2013 9:35 am

Hi Genie,

What are toasts messages?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Mon Apr 22, 2013 9:43 am

genie wrote:Hello!

I am also having trouble displaying Japanese text on the toast messages of my iPad app.

I can display Spanish and French texts, but when I try Japanese, it displays correctly on the screen, but not on toasts messages. What could be the problem?


Thanks,
Genie
Oh sorry, toast is probably for android. I mean, popup messages / answer dialog boxes.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Mon Apr 22, 2013 9:54 am

Hi Genie,

A possible way is to set the unicodeText of a hidden field to a variable containing UTF16 and get the htmlText of that field:

Code: Select all

put the htmlText of fld "Unicode" into myHtml
answer warning myHtml with "OK"
The dialog should display your Japanese text now.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Mon Apr 22, 2013 10:26 am

Mark wrote:Hi Genie,

A possible way is to set the unicodeText of a hidden field to a variable containing UTF16 and get the htmlText of that field:

Code: Select all

put the htmlText of fld "Unicode" into myHtml
answer warning myHtml with "OK"
The dialog should display your Japanese text now.

Kind regards,

Mark
Thanks Mark! I'm gonna try that out.

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Mon Apr 22, 2013 10:48 am

genie wrote:Thanks Mark! I'm gonna try that out.
Hello Mark,

My strings are actually in a database. To get the strings, I do...

Code: Select all

function getErrorMessage tErrorID
   databaseConnect
   put getDatabaseID() into tDatabaseID   
   revExecuteSQL tDatabaseID, "SET NAMES 'utf8'"
   put "SELECT dictionaryDefinition"&thelanguage&" FROM dictionaryContents WHERE dictionaryID='"&tErrorID&"'" into tSQL
   put revDataFromQuery("|",return,tDatabaseID,tSQL) into tRecords
   if length(tRecords) > 0 then
      put uniencode(tRecords,"UTF8") into tData
      set the unicodeText of field "errorfield" of card "topcard" of stack "Genie" to tData
      return field "errorField" of card "topcard" of stack "Genie"
   end if
end getErrorMessage
^This works well for Spanish and French... but not for Japanese.

Tried what you said...
I replaced

Code: Select all

return field "errorField" of card "topcard" of stack "Genie"
with...

Code: Select all

return the htmlText of field "errorfield" of card "topcard" of stack "Genie"
But I am getting some unicode characters on popup.
e.g. <p>&#12461;&#12515&#12531</p>

These lines are probably causing some conflicts?

Code: Select all

   revExecuteSQL tDatabaseID, "SET NAMES 'utf8'"
      put uniencode(tRecords,"UTF8") into tData

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Mon Apr 22, 2013 11:31 am

Hi Genie,

Do the Japanese characters show up corectly in a database manager like SQL Workbench or PhpMyAdmin?

What exactly do you use to display the message in the dialog? Please post the syntax.

Is this MySQL or SQLite?

You can't use the SET NAMES command with UTF8, because LiveCode always sends queries in plain text. I'm not sure it helps, but you could try setting the query encoding to the default encoding of your platform, either Latin1 or MacRoman. Otherwise, use DEFAULT.

Probably, the problem is that LiveCode can't communicate in anything other than the client computer's default encoding if using the built-in database driver. I tried to find more info about this in the latest release notes, but couldn't find any. I have a php-based commercial custom solution, which solves this. It works with MySQL and if necessary I can adjust it for SQLite. Go to http://qery.us/3fk for an example. The command line window is a LiveCode stack.

Kind regards,

Mark

P.S. Please don´t quote a message if the quoted text is from only 1 message earlier.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Tue Apr 23, 2013 2:43 am

Hi Mark!

This is SQLite, and yeah, Japanese texts appear correctly on 'SQLite Database Browser'.

Thanks,
Genie

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to add Japanese text?

Post by Mark » Tue Apr 23, 2013 3:09 am

Hi Genie,

Tim Selander recently posted the follow script to the mailing list. He does use SET NAMES and this might help you.

Code: Select all

on mouseUp
   global vDatabaseID --database ID

   --magic command for UTF8/mySQL, from forum user "bancock
   --without this I cannot send or receive UTF8 from mySQL
   revExecuteSQL vDatabaseID, "SET NAMES 'utf8'"

   --fld "query" contains SQL query, English & Japanese text
   put the unicodeText of field "query" into locSQLParams
   put uniDecode(locSQLParams, "UTF8") into locSQLParams

   put revDataFromQuery(, , vDatabaseID, locSQLParams) into myResult

   --fld "queryresults" holds data returned by mySQL
   --works great; get a field that shows the returned English and Japanese
   set the unicodetext of fld queryresults to uniEncode(myResult, "UTF8")

   --adding "unicodetext" to any part of "dgtext of group results causes error
   --following line does NOT work. Japanese text is broken in datagrid
   set the dgText of group "results" to uniEncode(myResult, "UTF8")
end mouseUp 
For testing, you might want to change the last line into

Code: Select all

set the unicodeText of fld 1 to uniEncode(myResult,"UTF8")
Let me know if this works for you.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: How to add Japanese text?

Post by genie » Thu Apr 25, 2013 10:00 am

I'm gonna look into this, Mark. Thanks much!

Post Reply