 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Thu Jan 18, 2007 2:54 am
Creating a language translator |
On my mud there are a few people wanting to be pirates in my city. I would like to somehow have my typing translated into pirate speak. I have found some conversion sites which i guess use the same type of thing as zmud to do it. Wondered if I could get some advice of how/where to start this project. I have found pirates.lang file but no idea how to use it if it is useable. thanks
|
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 18, 2007 4:42 am |
What you're looking for is probably %subregex. You can use an alias like this:
#alias say {~say @Piratenate(%-1)}
The @Piratenate function will execute a series of %subregexes on the parameters, doing whatever you want them to do. Changing "you" to "ye", for example. You can then reuse @Piratenate for any other times you want your text Pirateified.
I wouldn't advise finding a way to convert ALL your text into pirate-speak, because then you won't be able to send normal commands or do zMUD scripting without it being piratenated. Also, I believe pirates.lang is used to convert actual text in zMUD to pirate speak. That is, menu items, preferences, and so on. It's like translating it into a different language (just like the comedy Google language options), which is what I believe the .lang files are for. |
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Thu Jan 18, 2007 1:51 pm |
so how would i set up for example yes = aye in the @piratenate variable ? function or above?
|
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 18, 2007 6:45 pm |
Look up %subregex and #function. You'll want something like this:
#FU Piratenate {%subregex(%subregex(%-1,yes,aye),you,ye)}
You can add as many as you like, then you just use @Piratenate as I described above. |
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 1:12 am |
hate to be dumb about this but i just tried this
%subregex( %subregex( %-1, yes, aye), you, ye),captain,Cap'n)
then I said
say yes you captain
I got
Yous say, "Aye ye captain,captain,Cap'n)"
just need to get a grip of how i add this and then im good to go as I can see it is exactly what I want
I can then put all this in a class for rp |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 1:47 am |
You only have two %subregexes there. You need this:
%subregex(%-1,yes,aye)
%subregex(<previous string>,you,ye)
%subregex(<previous string>,captain,Cap'n)
to get %subregex(%subregex(%subregex(%-1,yes,aye),you,ye),captain,Cap'n) |
|
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Jan 19, 2007 2:19 am |
No code (yet) but some thoughts, taken from http://pirate.monkeyness.com/suggest ...
| Quote: |
- Context - Many translations rely on the context of the sentence. I can't just replace 'left' with 'port', because 'left' can be a verb, but I can replace 'the left' with 'port' or 'turn left' with 'turn to port'.
- Random Replacement - There are some pirate words or phrases that are equally applicable in a situation. For instance, 'What's up' gets replaced with a random assortment of 'Arr', 'Argh', 'Arrgh', 'Yarr', or 'Harr'. |
You will probably want to specify that only full words be translated, for example if you have the letters "you" inside of another word, you wouldn't want to translate it.
Case--words which have the first letter capitalized should be capitalized, other words should generally not, except for Cap'n, which should always be capitalized. This is problematic, because afaik there isn't a good way to do this in ZMud.
The random replacements could be fun, and you could probably reasonably set up string lists in variables to do that.
Speed...of course we always all have speed problems, but here the problem would be less with the parse speed on the function (if your says are delayed by a couple of milliseconds most people wouldn't care) and more by the time it would take to add new translations to the function. There is probably a decent way to run the entire thing off of a string list directly, or possibly easier would be to maintain a string list dictionary and a second function which completely rewrites the first function using the dictionary (i.e. to add a word, add it to the string list and then call the update function).
Edit: Almost forgot, plurals and possessives... |
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 3:54 am |
ok here is what i got so far
I use a pirate translate site for posting things in city bulletin boards which works great
Speed...o' course we always all be havin' speed problems, but here th' problem would be less wi' th' parse speed on th' function (if yer says be delayed by a couple o' milliseconds most swabbies wouldna care) an' more by th' time 't would take t' add new translations t' th' function. Thar be probably a decent way t' run th' entire thin' off o' a strin' list directly, or possibly easier would be t' maintain a strin' list dictionary an' a second function which completely rewrites th' first function usin' th' dictionary (i.e. t' add a word, add 't t' th' strin' list an' then call th' update function)
then I have the above with some words in it for speaking while rp it is in a class which i switch off when fighting chatting none pirate or other such things that sort of looks like
say ok captain lets get the sailors together and go and find that enemy fred
with the above code on that reads
You say, "Ok Cap'n lets get the Jack tars together and go and find that shark bait fred".
i got a problem as you said with a word like hi
say hi higher his hit hills him
translates to
You say, "Ahoy ahoygher ahoys ahoyt ahoylls ahoym"
anything i can do to stop this - the other problems i can live with but its a shame if i cant use words like
me hi my and
stark |
|
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Jan 19, 2007 4:32 am |
A quick fix is to change your pattern from, for example:
%regex( ... , "you", "ye")
to
%regex( ... , "(\W)you(\W)","%%1ye%%2")
Short explanation: \W (note capitalization) is a "character class", basically it means "match a non-word character" (\w, again note lack of capitalization, means "match any word character"...for future reference). Putting the parentheses around it allows you to reference it later, since otherwise the charcters immediately in front of and after would be removed...and the %%1 and %%2 are putting those characters back in correctly, double %s because it is/will be inside a function...if we had lookahead and lookbehind, this wouldn't be such a big issue, but as is we have to work around it.
Anyway, it still has problems. It won't match the first word in the block of text, for one thing, or the last word unless it is followed by punctuation/space/something like that--possibly a large problem with the first half, the second half not so much as long as you consistantly end your says with puncuation! It also won't correctly cope with plurals or possessive forms (unless you add them specifically): "your" will NOT beocome "yer", "you're" will NOT become "ye're". If you get the same word twice in a row it won't match (this is not really a problem, imho). It is longer to add and more prone to error due to being more complicated....back to the speed issue.
Quick edit: While I'm adding to your feature list, you might some day try and make it so that it only changes a percentage of the words... in an ideal world where just thinking about something causes it to happen, you could change it so that common words are changed randomly but less frequently, certain words are changed all of the time (based on your character), and average words are changed randomly but fairly regularly. This would help with readability, since just reading the one paragraph made my eyes bleed. :/ |
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 5:52 am |
sorry to be stupid but %regex( ... , "(\W)you(\W)","%%1ye%%2")
how does that fit in to
%subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %subregex( %-1 , yes, aye), you, ye), captain, Cap'n), mad, addled), after, aft), hello, ahoy), rubbish, bilge), nonesense, bilge), treasure, booty), pirates, bretheren of the coast), friends, bucko's), song, shanty), eyes, deadlights), bye, fairwinds), drink, grog), food, grub), sailors, Jack tars), flag, Jolly Roger), coins, pieces of eight), enemy, shark bait), hi, ahoy) |
|
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Jan 19, 2007 2:56 pm |
Er, sorry, instead of %regex it should be %subregex, and then you would use it as you're already using... Um. Instead if where you have "you" put "(\W)you(\W)" and instead of where you have "ye" put "%%1ye%%2"... and so on for all of your patterns (or at least the small words that are likely to show up in something else). Like I said, it can very quickly become difficult to maintain!
|
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 3:58 pm |
this didnt work
thanks for the idea though and ill keep messing with it |
|
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Jan 19, 2007 5:39 pm |
How did it fail?
One thing... You will probably -need- the quotes with the patterns that I've posted, since I notice you're not using quotes normally (also there is no harm in using them for all patterns, even simple ones). |
|
|
|
 |
stark62 Wanderer
Joined: 04 Apr 2003 Posts: 94 Location: United Kingdom
|
Posted: Fri Jan 19, 2007 7:13 pm |
dont want this to sound bad but
if i new that i could fix it
just doesnt accept code and doesnt work
Ive had stuff like this every time i try to get stuff working .... maybe i have my preferences wrong or just dont do stuff right.
dont worry as it works for all but small words etc so its good fpr some rp thanks |
|
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Jan 19, 2007 7:51 pm |
Hmm, what I meant was things like...
Does it give you an error message, either when you put it into the function or when you try and use the function?
If you use the function on some text, does the text come through garbled (translated incorrectly) or not translated at all?
What kind of test are you using to see if it works, and what result does the test give? |
|
|
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|