Multi-language

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
xor
Posts: 9
Joined: Mon Dec 13, 2010 9:24 pm

Multi-language

Post by xor » Mon Dec 13, 2010 10:32 pm

Hi all,

I am a complete newbie to LiveCode and this is my very first post.

My programming experience started in the 80’s on an Atari 800XL. I started developing software professionally in 2001 as a FileMaker developer and later I have extended my skills with HTML, ASP, VBS, JS, VBA, VB.NET, SQL Server and MySQL. At this moment I am trying to learn Visual C++, but that is a complete different story. :)
An acquaintance of my mine told me about LiveCode and it directly caught my attention. Why? Cross-platform and the programming language.
OK, enough about me. ;)

My first challenge is to create an multi-language application and this forum learned me that it can be done with Custom Property Sets. But... it is quite laborious to enter and maintain all the data. Is it possible to import or refer to an external language file (columns Name and Content) directly (in)to an Custom Property Set? Or is there another way to solve this issue?

Thanks in advance,
Mark
Last edited by xor on Tue Dec 14, 2010 4:14 pm, edited 2 times in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Multi-language

Post by jmburnod » Mon Dec 13, 2010 11:02 pm

Hi Xor,
Welcome on this forum.
But... it is quite laborious to enter and maintain all the data
You're right
Yes, you can import data from a file and set the customproperties of objects by script on preopencard for example

And You can count on the participants in this forum to help you

All the best

Jean-Marc
https://alternatic.ch

xor
Posts: 9
Joined: Mon Dec 13, 2010 9:24 pm

Re: Multi-language

Post by xor » Thu Dec 16, 2010 5:57 pm

Thanks Jean-Marc for your welcome and response.

OK. I have created a file called Dutch.lng with the following data (tab separated):

uName Naam
uAge Leeftijd

I found out how to import this data into a field:

Code: Select all

put URL "file:C:/Users/Mark/Desktop/Dutch.lng" into field "txtField"
But my goal was to import this data into a custom property set, so I tried:

Code: Select all

set the customProperties of this stack to URL "file:C:/Users/Mark/Desktop/Dutch.lng"
and

Code: Select all

put URL "file:C:/Users/Mark/Desktop/Dutch.lng" into customKeys
But these attempts did not work. What am I doing wrong?

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

Re: Multi-language

Post by Klaus » Thu Dec 16, 2010 6:18 pm

Dag Mark,

"custom properties" is just the "describing term" for this mechanism, although this is a allowed keyword.
Check the dictionary for "customproperties", which is a bit different than what you are looking for!

You need to supply a (meaningful) name like:

Code: Select all

set the cLanguageFileDutch of this stack to URL "file:C:/Users/Mark/Desktop/Dutch.lng"
This way a custom property with this name will be created in your stack and filled with the content of that file.


Groetjes uit duitsland

Klaus

qberty
Posts: 14
Joined: Thu Dec 16, 2010 8:08 pm

Re: Multi-language

Post by qberty » Thu Dec 16, 2010 8:18 pm

Due keep in mind, some languages have certain symbols and are not really rendered correctly if your simply using the 'URL "file:C:/language.lng"' as simple text might not do it. If your willing with languages that add more symbols that cannot be read properly remember to use 'URL "binfile:C:/language.lng"' which treats the file as a binary type which wouldn't corrupt anything.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Multi-language

Post by mwieder » Thu Dec 16, 2010 8:19 pm

And given what you're trying to do, I'd try something like this:

Code: Select all

on mouseUp pMouseBtnNo
    local tLanguage
    local tLanguageData
    local tProperty
    local tValue
    
    put "Dutch" into tLanguage
    
    put url ("file:" & tLanguage & ".lng") into tLanguageData
    set the custompropertyset of this stack to tLanguage
    repeat for each line tLine in tLanguageData
        if tLine is not empty then
            put word 1 of tLine into tProperty
            put word 2 of tLine into tValue
            set the tProperty of this stack to tValue
        end if
    end repeat
    set the custompropertyset of this stack to empty
end mouseUp
Then when you want to retrieve the values use

Code: Select all

put the Dutch["uName"] of this stack into tName
...and actually for ease of use I'd name the file "uDutch.lng" and then use "name" instead of "uName" in the file...



...and welcome to LiveCode.

xor
Posts: 9
Joined: Mon Dec 13, 2010 9:24 pm

Re: Multi-language

Post by xor » Fri Dec 17, 2010 8:11 pm

Thanks everybody for your comments. I really appreciate it. :)

@Klaus: Groetjes terug uit Nederland.

@qberty: good suggestion about using binfile

@mwieder: your solution does 99% what I had in mind! Apparently I overestimated LiveCode, because I thought it was possible with one line of code. ;) And thanks for your welcome.

I have read an article about naming conventions (published by Fourth World). If I have understood the contents of this article correctly, then you should use an u as a prefix for a custom property. For instance: uName, uAge, etc.
Is this the way to name them?
And should Custom Property Sets be named with a cps prefix? For instance: cpsLanguage.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Multi-language

Post by mwieder » Sat Dec 18, 2010 3:07 am

One line? Well, I did make things a bit verbose to make it clear what's going on in the handler. Could have stripped it down a bit at the expense of readability, but there's really nothing to gain by doing that. However...

How about

Code: Select all

-- assuming a "Dutch.lng" file
-- and a resulting "uDutch" custompropertyset
on doLanguage pLanguage
  --all the stuff above in the mouseUp handler
    local tLanguageData
    local tProperty
    local tValue
   
    put url ("file:" & pLanguage & ".lng") into tLanguageData
    set the custompropertyset of this stack to "u" & pLanguage
    repeat for each line tLine in tLanguageData
        if tLine is not empty then
            put word 1 of tLine into tProperty
            put word 2 of tLine into tValue
            set the tProperty of this stack to tValue
        end if
    end repeat
    set the custompropertyset of this stack to empty
end doLanguage

on doDutch
    doLanguage "Dutch"
end doDutch

on doFrench
    doLanguage "French"
end doFrench

-- etc.
I think that's about as close to one line of code as you'll get <g>.

And Richard's document on naming conventions is a great read. I do use the "u" prefix for custom properties, others may use "c" for "custom". But I think the important thing is to have a convention and stick to it, no matter what it is. For custompropertysets I also use "u", as in

Code: Select all

get the uRIP["version"] of this stack
or, as in the above code snippet:

Code: Select all

get the uDutch["name"] of this stack

xor
Posts: 9
Joined: Mon Dec 13, 2010 9:24 pm

Re: Multi-language

Post by xor » Wed Jan 05, 2011 7:06 pm

First of all: Happy new year everybody!

@mwieder: you are right about "to have a convention and stick to it". Thanks for your response. It was very clarifying.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Multi-language

Post by mwieder » Thu Jan 06, 2011 2:47 am

<g> Now I have to get used to writing 2011 on checks. I was just getting used to 2010...

Post Reply