Copy link to clipboard
Copied
My HTML/CSS knowledge can best be described as "good enough to get by". I've also (barely) dipped my toe in PHP (mainly to assemble modular pages and use variables).
When I was a kid, there was a website that offered to "translate" any block of text into various slangs. For example, Pirate Talk, which would replace all instances of friend or pal with "matey", add lots of "Arrrr"s, etc. Pretty basic stuff, really.
I'd like to do something like that : a web page with a large input box which, once submitted, would spit out the same text with a modified slang. I assume this would simply require a bunch of if/then statements : like FRIEND or PAL = MATEY.
I would imagine this is easy enough to do in PHP via string search/replace calls, but my PHP knowledge doesn't extend far enough for me to produce the code from scratch. I'd be able to customize it, however. I'm picturing a simple form with an input box, a submit button, and a div with the displayed results -- using a demo search/replace string I can clone to build up a more exhaustive word bank -- would do the trick (if there's a good samaritan out there reading this).
Copy link to clipboard
Copied
This may help
Copy link to clipboard
Copied
This may help
By @BenPleysier
Sad indeed, the youth of today are becoming too thick to think or do anything for themselves.
Copy link to clipboard
Copied
@Under S. wrote:
I'd like to do something like a web page with a large input box which, once submitted, would spit out the same text with a modified slang. I assume this would simply require a bunch of if/then statements : like FRIEND or PAL = MATEY.
I would imagine this is easy enough to do in PHP via string search/replace calls......
You dont need php at all for this you can use plain old javascript. Of course you might want to do something with the translated version at server level in which case you will have to involve a server language.
Anyway food for thought below is a full javascript version, just add the current and replacement words to the wordBank array and then type away in the top box, click the translate button and the translated version will appear in the bottom box.
Of course be mindfull of ALL user input. You'll need to sanitize the input. I think there is a javacript library which can be deployed to do that.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Translate Text</title>
<style>
.inputWrapper {
width: 50%;
margin: 0 auto;
}
.inputText, .translatedText {
min-height: 200px;
padding: 25px;
border: 1px solid #000;
}
.inputText p, .translatedText p {
margin: 0 0 8px 0;
padding: 0;
}
p::first-letter {
text-transform: uppercase;
}
button.translate {
display: block;
margin: 20px auto;
background-color: #000;
color: #fff;
padding: 10px 25px;
border-radius: 6px;
border: none;
}
</style>
</head>
<body>
<div class="inputWrapper">
<div class="inputText" contentEditable="true">
<p>Hello friend you are a good pal</p>
</div>
<button class="translate">Translate</button>
<div class="translatedText"></div>
</div>
<!-- end inputWrapper -->
<script>
/* BUILD WORD BANK */
const wordBank = [
{current: 'friend' , replacement: 'matey'},
{current: 'pal' , replacement: 'mate'},
];
const translate = document.querySelector('.translate');
const translatedText = document.querySelector('.translatedText');
translate.onclick = function() {
let inputText = document.querySelector('.inputText').innerHTML.toLowerCase();
wordBank.forEach(function(word) {
inputText = inputText.replaceAll(word.current, word.replacement);
});
translatedText.innerHTML = inputText;
}
</script>
</body>
</html>
Copy link to clipboard
Copied
@Under S. wrote:
I'd like to do something like a web page with a large input box which, once submitted, would spit out the same text with a modified slang. I assume this would simply require a bunch of if/then statements : like FRIEND or PAL = MATEY.
I would imagine this is easy enough to do in PHP via string search/replace calls......
Its not difficult. See example php code below. There are several ways to do it but having the replacement words in an associative array along side the words they are replacing then looping through the array using 'foreach' and 'str_replace' php functions will be a lot easier to manage.
You can split the current/replacement words into 2 arrays but if you have a lot of current/replacement words that will be difficult to manage and keep track of what word replacement word belongs to which current word.
<?php
$string = "Hello friend you are a good pal";
$wordBank = [
['current'=>'friend', 'replacement'=>'matey'],
['current'=>'pal', 'replacement'=>'mate']
];
foreach ($wordBank as $word) {
$string = str_replace($word['current'], $word['replacement'], $string);
}
echo "<p>$string</p>";
?>
Copy link to clipboard
Copied
great, just curious what happen, for mate, buddy, fellow... and so on... does it mean that we will have to feed the duck for each entrance ?
Copy link to clipboard
Copied
great, just curious what happen, for mate, buddy, fellow... and so on... does it mean that we will have to feed the duck for each entrance ?
By @B i r n o u
Of course you would need a word bank to 'compare' words in the user input string against those you want to replace, which is built up over time.
Copy link to clipboard
Copied
ok, ... so it must takes sometime to fill up the tank... well if the user doesn't mind spending hours filling in the bucket, and finding all the alternatives, why not, if not, for a much more direct and efficient case, I second @BenPleysier about using the ChatGPT API which is some how simple to use, and ready out of the box...
https://www.ghacks.net/2023/01/05/using-chatgpt-as-a-translation-service-with-a-kick/ and fulfilled the task perfectly
Copy link to clipboard
Copied
This isn't a translation service but an app where only specific words need to be swapped with other words. That needs a bank of words created by a human who is building the app not a robot because the robot until expressively programmed by a human doesn't know which words to swap.
Sure you can use AI to ask for standard stuff to be translated or stuff that openly exists to be returned but l doubt it knows which specific words to translate into pirate talk. How would AI know, without being programmed that you specifically wanted to change the word dumb to ignorant?
Copy link to clipboard
Copied
in fact you just have to ask to ChatGPT to do what you expect 😉 and he will do it for you, it's not a dead DDB
Copy link to clipboard
Copied
in fact you just have to ask to ChatGPT to do what you expect 😉 and he will do it for you, it's not a dead DDB
By @B i r n o u
Might do it for you or point you in the right direction, according to a lot of feedback it's not 100 reliable. Don't believe everything you see on YT, or read, its good click bait, on this point you're barking up the wrong tree AI = Artifical Ineffective.
Interestingly but not surprising Stack Overflow moderators are apparently banning AI generated code created by ChatGPT, for an unspecified period, because its unreliable. Lots of crap has been posted on their website since its release by those too ignorant to learn to code or dont have the slightest clue what it does. That can't be a good situation for Stack Overflows reputation as the 'go to' place when seeking answers.
Copy link to clipboard
Copied
Thank you. I haven't tried this yet, but at first glance, this seems to be ideal.
PS: I appreciate people trying to spare me from having to manually build a word bank from scratch, but this isn't for translating into any known languages : that's why I chose the Pirate Talk example. This is to take regular English and translate it into various slangs used by various non-famous people : for example, it could mimic how my best friend speaks. There won't be a premade word bank for that, he's a nobody; we (his friends) have to build it.
Copy link to clipboard
Copied
PS: I appreciate people trying to spare me from having to manually build a word bank from scratch, but this isn't for translating into any known languages : that's why I chose the Pirate Talk example. This is to take regular English and translate it into various slangs used by various non-famous people : for example, it could mimic how my best friend speaks. There won't be a premade word bank for that, he's a nobody; we (his friends) have to build it.
By @Under S.
Was clear to me but then again l've yet to be brain washed by the next generation of kids who have just fallen out their pram.
Either php or javascript will work. You can even have different slang buttons for the same block of text if needed, just include the relevant words in their own arrays and evoke that array on the click of specific buttons
Copy link to clipboard
Copied
sorry 🙏 i didn't get it 😂 .
Copy link to clipboard
Copied
sorry 🙏 i didn't get it 😂 .
By @Moneeb27978289smy8
Some experience and more so reading posts 2 or 3 times counts, obviously.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now