Shoutbox

[Request] In / Out Text Replacer - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Request] In / Out Text Replacer (/showthread.php?tid=75592)

[Request] In / Out Text Replacer by Yukai on 06-24-2007 at 06:01 PM

Hi

I was playing around with the built in text replacer in Plus! and I got the funny idea of replacing Japanese Romaji with Kanji.

But to my suprise I could only edit the text that I write myself, which makes my idea a bit harder.

Here's the thing that I would like to do:

I write something in romaji   =  Becomes kanji
My friend writes something in kanji  = Becomes romaji


I do not request a dictionary, I will add the words myself if I could get my hands on a script like this.



Thank you..


RE: [Request] In / Out Text Replacer by toddy on 06-24-2007 at 06:07 PM

http://www.msgpluslive.net/scripts/browse/


RE: [Request] In / Out Text Replacer by Yukai on 06-24-2007 at 06:12 PM

There is no script in the database that fits my needs.


RE: [Request] In / Out Text Replacer by roflmao456 on 06-24-2007 at 07:32 PM

hmmm... (untested)

code:
var romaji = new Array(
"Just",
"Like",
"This",
"Separated by comma",
"unless if it's the last one."
);

var kanji = new Array(
"Same",
"Goes",
"Here"
);

function OnEvent_ChatWndSendMessage(Chatwnd, Message){
for(i=0;i<romaji.length;i++){
var Word = new RegExp(romaji[i], "gi");
Message = Message.replace(Word, kanji[i]);
}
return Message;
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Origin != Messenger.MyName && MessageKind == 1){
for(i=0;i<kanji.length;i++){
var Word = new RegExp(kanji[i], "gi");
Message = Message.replace(Word, romaji[i]);
}
return Message;
}
}

Paste that in a new script and ther you go (Y)

it might fail in some cases though...

* roflmao456 calls Cookie to explain :P
RE: RE: [Request] In / Out Text Replacer by Yukai on 06-24-2007 at 07:47 PM

quote:
Originally posted by roflmao456
hmmm... (untested)

code:
var romaji = new Array(
"Just",
"Like",
"This",
"Separated by comma",
"unless if it's the last one."
);

var kanji = new Array(
"Same",
"Goes",
"Here"
);

function OnEvent_ChatWndSendMessage(Chatwnd, Message){
for(i=0;i<romaji.length;i++){
var Word = new RegExp(romaji[i], "gi");
Message = Message.replace(Word, kanji[i]);
}
return Message;
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Origin != Messenger.MyName && MessageKind == 1){
for(i=0;i<kanji.length;i++){
var Word = new RegExp(kanji[i], "gi");
Message = Message.replace(Word, romaji[i]);
}
return Message;
}
}

Paste that in a new script and ther you go (Y)

it might fail in some cases though...

* roflmao456 calls Cookie to explain :P


Thank you so much for taking time to write that. But I feel kind of dumb since I don't understand what to replace and where.


RE: RE: RE: [Request] In / Out Text Replacer by Deco on 06-24-2007 at 09:46 PM

quote:
Originally posted by Yukai
quote:
Originally posted by roflmao456
hmmm... (untested)

code:
var romaji = new Array(
"Just",
"Like",
"This",
"Separated by comma",
"unless if it's the last one."
);

var kanji = new Array(
"Same",
"Goes",
"Here"
);

function OnEvent_ChatWndSendMessage(Chatwnd, Message){
for(i=0;i<romaji.length;i++){
var Word = new RegExp(romaji[i], "gi");
Message = Message.replace(Word, kanji[i]);
}
return Message;
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Origin != Messenger.MyName && MessageKind == 1){
for(i=0;i<kanji.length;i++){
var Word = new RegExp(kanji[i], "gi");
Message = Message.replace(Word, romaji[i]);
}
return Message;
}
}

Paste that in a new script and ther you go (Y)

it might fail in some cases though...

* roflmao456 calls Cookie to explain :P


Thank you so much for taking time to write that. But I feel kind of dumb since I don't understand what to replace and where.




In this part. Change "FirstWord" to the word in romaji you want.
Then Change "SecondWord" to another word you want in romaji.
and so on.

In the second part change "KanjiWord" to any kanji word you want.. like "feioso" or something (sorry I don't know kanji).

Hope you get it this time!

code:
var romaji = new Array(
"FirstWord",
"SecondWord",
"ThirdWord",
"FourthWord",
"FifthWord."
);

var kanji = new Array(
"KanjiWord",
"SecondKanjiWord",
"ThirdKanjiWord"
);


RE: [Request] In / Out Text Replacer by Yukai on 06-24-2007 at 10:36 PM

But why FirstWord and SecondWord? Are they linked with Kanjiword and SecondKanjiWord?

Let's say that:

FirstWord gets changed to A
KanjiWord gets changed to B

Will "A" then become "B" when i type and will an incoming "B" become "A"?


Again, sorry for being slow


RE: [Request] In / Out Text Replacer by roflmao456 on 06-25-2007 at 02:46 AM

quote:
Originally posted by Yukai
But why FirstWord and SecondWord? Are they linked with Kanjiword and SecondKanjiWord?

Let's say that:

FirstWord gets changed to A
KanjiWord gets changed to B

Will "A" then become "B" when i type and will an incoming "B" become "A"?


Again, sorry for being slow

no yes.. oops i just read it again

as you said in your previous post, you want to just replace romaji words with kanji.

so in the first list you put the romaji words (look after var) and in the second, you put the kanji words ;)

Let's see it like this:

code:
var romaji = new Array(
"testing",
"test123",
"tester"
);

var kanji = new Array(
"testo",
"testthis",
"roflmao456"
);

if you send 'testing' it will replace with 'testo'.
if your contact sends you 'testthis' it will replace to you with 'test123' (but it will fail if test123 is longer than testthis's length.
RE: RE: [Request] In / Out Text Replacer by CookieRevised on 06-25-2007 at 03:24 AM

quote:
Originally posted by roflmao456
* roflmao456 calls Cookie to explain :P
Whooosh..

For things like this many people use the Replace function. But the replace function will search for the stuff to replace from the beginning of the text you paste to it.

So, in a list if you have the letters A B C D E F G H and you're going to replace each letter respectivly with C D E F G H A B... Then you can (and will) come in the situation like this:

The next pseudo code is almost always used in scripts like this (you can verify this in the scripting database). But it will, in most cases, render wrong results:

var myword = "ABC"
myword = myword.replace("A", "C")
myword = myword.replace("B", "D")
myword = myword.replace("C", "E")
myword = myword.replace("D", "F")
myword = myword.replace("E", "G")
myword = myword.replace("F", "H")
myword = myword.replace("G", "A")
myword = myword.replace("H", "B")

myword is now "EBC"(1) or "ABA"(2) not "CDE" as it was intended!

This because:

(1) if Replace replaced the first letter it finds (like it does by default):

var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "CBC"
myword = myword.replace("B", "D") => myword is now "CDC"
myword = myword.replace("C", "E") => myword is now "EDC" (here the first error occurs)
myword = myword.replace("D", "F") => myword is now "EFC"
myword = myword.replace("E", "G") => myword is now "EFC"
myword = myword.replace("F", "H") => myword is now "EHC"
myword = myword.replace("G", "A") => myword is still "EHC"
myword = myword.replace("H", "B") => myword is now "EBC"

or, (2) if Replace replaced all the letters it finds:

var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "CBC"
myword = myword.replace("B", "D") => myword is now "CDC"
myword = myword.replace("C", "E") => myword is now "EDE" (here the first error occurs)
myword = myword.replace("D", "F") => myword is now "EFE"
myword = myword.replace("E", "G") => myword is now "GFG"
myword = myword.replace("F", "H") => myword is now "GHG"
myword = myword.replace("G", "A") => myword is now "AHA"
myword = myword.replace("H", "B") => myword is now "ABA"

Conclussion: never ever use:

var myword = "something"
myword = myword.replace("A", "B")
myword = myword.replace("B", "C")
myword = myword.replace("C", "A")

or the likes (like looping using a list, as this is just the same, only shorter in code) to replace text when the text to search for contains the same characters as the text to replace with!

;)


-------------------------

quote:
Originally posted by Yukai
But why FirstWord and SecondWord? Are they linked with Kanjiword and SecondKanjiWord?

Let's say that:

FirstWord gets changed to A
KanjiWord gets changed to B

Will "A" then become "B" when i type and will an incoming "B" become "A"?
yep

But only if Kanji and Romaji don't have any words in common (or even parts of words!!). Otherwise you will have the situation as described above. Which means you will not be able to use that script for this.

Though, there are other situations in which this script will not work properly and this has got something to do with the RecievedMessage event and detecting if the recieved message is/isn't a message you wrote. But that's explained in another thread ;)

And then there is also the fact that you can not return a longer message than the one you've recieved in the RecievedMessage event. Which can and will also lead to this script not working properly in those cases.

-------------------------

This said, it could be possible that there is a Windows API which already does this convertion, I can't remember anymore, I'll need to look this up (unless someone else can confirm this or not). > EDIT: after an extremely quick plain search I can't find any api for this though...
RE: [Request] In / Out Text Replacer by Yukai on 06-25-2007 at 11:18 AM

I think it will be okay since romaji is Japanese spelled with letters

And Kanji is Japanese signs..

And are you saying that the word that will replace can't be longer than the original word?
Because the built in function can. It just doesn't have any support for incoming messages


RE: [Request] In / Out Text Replacer by CookieRevised on 06-25-2007 at 11:32 AM

quote:
From the Plus! Scripting Documentation:

OnEvent_ChatWndReceiveMessage
Return Value:

A string containing the message to be displayed in the chat window instead of Message. If you do not want to modify the message, simply return Message without changing it. The new string will be parsed for possible format codes. It is important to remember that the new message cannot be longer than the original one (Message.length) and will be cut if necessary. Also, Messenger will not re-parse the message for emoticons codes.

PS: seeing http://en.wikipedia.org/wiki/Romaji and other resources, it seems not so easy to convert romaji back though, as there are several systems possible. So you'd need something which automatically reconizes the used system, etc. All in all, not an easy script to make I think.

The Javascript used on this page might be a great help... also check out the links that page points to.

RE: [Request] In / Out Text Replacer by Yukai on 06-25-2007 at 12:31 PM

ow, this might be a little more difficult than i thought.


RE: [Request] In / Out Text Replacer by markee on 06-26-2007 at 02:10 PM

You also have to remember that changing to kanji is probably not the best to change it into as there are at least 2 ways that every kanji can be pronounced and there are many kanji that make the same sound and hence same romaji.  The only way to do a script that you were after by any means is a romaji to hiragana or a romaji to katakana script that could translate either way.

However there is one other possibility and that is to make sure that your friend uses a hiragana/katakana/kanji to romaji converter before sending a message to you and hence being able to have the longer message.

These are just some things to think about when making the script (whoever decides to devote their time to the project).


[off-topic]
quote:
Originally posted by CookieRevised
The next pseudo code is almost always used in scripts like this (you can verify this in the scripting database). But it will, in most cases, render wrong results:

(Post cut short.... sorry Cookie)

This is easily fixed by using a function in your replace method instead

code:
var oString = "abcd";
var eString = oString.replace(/a|b|c|d/g,function($1){
                    switch($1){
                        case "a":
                            return "b";
                        case "b":
                            return "c";
                        case "c":
                            return "d";
                        case "d"
                            return "a";
                    }
                });
return eString;
This will return "bcda".

[/off-topic]