mIRC Home    About    Download    Register    News    Help

Print Thread
language #132091 07/10/05 03:44 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
I like to have my script in more then 1 language.
What is the best and easyest way to make a language setup ?
Any help is welcome smile

Greetzz

Re: language #132092 07/10/05 04:06 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Well, you could use a text or ini file for it.

Example:

If your settings say English, you change dialog text by reading in the English text from either $readini(languages.ini,English,ID) or from $read(english.txt,%line) ... something like that.

Personally, I like the INI way. You can set it up with the dialog ID numbers like this:

[English]
1=Hello
2=Yes
3=No
[Spanish]
1=Hola
2=Si
3=No

Etc.

Then, on init, you do:

/did $dname 1 $readini(languages.ini,%language,1)
/did $dname 2 $readini(languages.ini,%language,2)
/did $dname 3 $readini(languages.ini,%language,3)

For non-dialog options, just use some identifier in the INI so you can find it...

loadedtxt=Script Loaded.

Something like that. Then, when you need that:

echo -a $readini(languages.ini,%language,loadedtxt)

Have your script set %language to a default language on load. Anyhow, like I said, you can use text files for each language instead of an INI file for all... but unless you need too much text (or too many languages) to fit into an INI, I think that's an easier way to do it.


Invision Support
#Invision on irc.irchighway.net
Re: language #132093 07/10/05 04:32 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
What is too much in a ini file ?

Re: language #132094 07/10/05 04:38 PM
Joined: Jan 2003
Posts: 249
C
ClickHeRe Offline
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
I'd go for a hash table as it's is absolutely faster than INI especially as the file grows in size. You can save and load your hash table into a file ON START and ON EXIT.

and the way I'd do it is load a default language file (probably english) which contains all the correct strings in it. Then you reload the second language file over it which will replace the already present strings and if some are missing, the default language ones will be there.

So in theory an auto-update script which doesn't have it's language files updated for the new modules can still have the basic language settings available for that module until the newest non-default language is ready.

This is a quick demo of how my multi-language script was doing it back in 2002 (yeah it's a relic today and doesn't work on mIRC > 6.03)

Re: language #132095 07/10/05 04:48 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
very nice i heard hash would be the best but i'm a rookie.
If you have the code and I only have to change some path to the right files I'll think I can get it running.
But to make the code all on my own ... that would be a year work for me smile
But feel free to make the code smile
If you need the script also you can download it here

Re: language #132096 07/10/05 05:05 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Too much for an INI file is 64kB. Unless you need a lot of text or have a lot of languages, you're not going to hit that mark.

And, yes, hash tables are faster since you don't have to keep reading the INI/text file when initializing a dialog. I didn't mention them simply because I felt it was easier to set the languages up in an INI file.

But, you could also set up a language-making dialog that will save it correctly for /hload as a hash table. If you took the time to do that, it would actually be much easier than setting it up in an INI file. You can create a dialog that shows the English words on one side and an edit box for the new words next to it. You fill in the words, hit ok and it saves it into a new hash table format that you can load.

Example Dialog:
Code:
******************************************************************
*  Language:  _______________                                    *
*                                                                *
* Yes                                       __________________   *
* No                                        __________________   *
* Would you like to play?                   __________________   *
* What is your password?                    __________________   *
******************************************************************


The idea is that you can then create multiple language files very quickly and easily.

Then, when you press OK (or after you go to however many NEXT pages you need to do all the words), it will /write the information to a text file (probably call it the name of the language you entered and maybe use an extension other than .txt so people aren't as likely to try messing with it) in the format of /hsave so that it can be loaded with /hload. Then, you can just use something like:

hload %language

did $dname 1 $hget(%language,1)
did $dname 2 $hget(%language,2)

Etc.


Invision Support
#Invision on irc.irchighway.net
Re: language #132097 07/10/05 05:19 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
It was not my intension to make two scripts sinds I'm still a rookie.
But your idea is great for scripters who also want multiple language in the script.
Maybe after my own script is ready i'll try do make something like that.

Re: language #132098 07/10/05 05:27 PM
Joined: Jan 2003
Posts: 249
C
ClickHeRe Offline
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
also to have your help files well organized, I would suggest you using unique IDs for each language linked with the module name as the key for the hash table item.

mod.away.001 data here1
mod.away.002 data here2
...
mod.mp3.001 data here3

that way, no possible conflicts between addons

Code:
ON *:START: {
  hmake lang 10 
  if ( $hget( lang ) && isfile( default.lan ) ) { .hload lang default.lan }

  ; add loading of other language here if it's not the default one 
  ; Like I explained earlier, the new loading will replace
  ; the items and leave the default ones if they are missing
}

alias lan.get {
  return $hget( lang, $$1 )
}

//echo -a $lan.get( mod.away.002 )


see the /hmake and /hadd commands to interact with hash tables. I would also advise you get a hash table viewer/manager addon to let you set, view and modify a hash table contents.

You can also use this kind of system to keep your script configurations (saving the file ON EXIT) and even make a profile system so many users can use the script with their own settings but this is out of scope of this example.

Play with hash tables, you will see that they are much better that ini files for about everything especially access time when you need to get lots of data quickly.

Re: language #132099 07/10/05 05:38 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
The only warning I'd give for hash tables is that if you crash or quit mIRC without first saving the table, it will be lost. Since languages aren't changing, that's okay because you'll just reload it. For settings or options or data, you should have your table saving at regular (short) intervals to prevent such data loss. That's the only thing to really be aware of when working with hash tables instead of writing to some form of file. Until you /hsave, the data in the hash table is just loaded in memory and not really saved anywhere.

Just wanted to put out the warning since you're just starting with hash tables.


Invision Support
#Invision on irc.irchighway.net
Re: language #132100 07/10/05 05:43 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
Thank you both for your help i'll will see what i can put together smile

Re: language #132101 07/10/05 05:55 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
It may not be the right time yet to try to make a full script, considering you're not very experienced yet. I'd try to make some snippets, later on addons, and who knows, maybe one day if you still have the perseverance for it, a nice full script.

Unless you are going to do like half the "scripters" out there, which is just package together a bunch of other people's addons/code, and call it your own script.

In any case, good luck.


Gone.
Re: language #132102 07/10/05 05:56 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
Question : the 10 in hmake why 10 ?

Re: language #132103 07/10/05 06:03 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
That has been answered all over. laugh

The idea is that you use 10% of the maximum size you expect the table to be. This makes the table faster to manage without using more memory than is necessary. If you use too low a number, it can slow access down. Too high a number and it doesn't really improve speed anymore and you're just wasting memory.


Invision Support
#Invision on irc.irchighway.net
Re: language #132104 07/10/05 06:04 PM
Joined: Jan 2003
Posts: 249
C
ClickHeRe Offline
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
It's the initial amount of items (divided by 10) sought to be needed to put all the data. The table will still grow if you go past the (100 items in this example : 10 * 10) but it will be doing memory operations to reallocate some new memory for the items instead of using the allocated empty space created when you use /hmake.

you can also use "/hadd -n item data" to add even if the table isn't created, as it will create the table with probably 1 item space. And then everytime you add to the table, the allocation process will take place, adding time to the adding of the item instead of using an empty space already defined. (I really don't think it's wery much time lost, we would need to benchmark it on a 100000+ items basis to see something)

Re: language #132105 07/10/05 06:07 PM
Joined: Feb 2005
Posts: 344
B
Bullseye Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
FiberOPtics you have to start somewhere and yes most of what i have in my script are addons simply because I want a script for my channel.
I'm starting to like scripting more and more and perhaps someday i'll make a script totaly of my own.
Untill then I have to do it by using someone else his/her work.
That way they didn't make the addon for nothing.
I do give credit to the ones who made the addons.