Game.py / change the language output to a foreign language, not English

(https://docs.replit.com/tutorials/discord-rpg-bot#creating-a-discord-application)

Replit is copying and pasting the code provided. I have no knowledge of Python. I’m getting to know this by tweaking it little by little.

I want this bot to be printed in a foreign language, not English, when it prints out a message.

Uploading: image.png…
( {character.name} 는(은) 레벨 6 이 되었습니다. DEFENSE의 능력이 1 성장했습니다.)

I’d like to change the ‘DEFENSE’ part to a foreign language in a sentence printed like this.

        
    if not increase:
        await ctx.message.reply("Please specify a stat to increase (HP, ATTACK, DEFENSE)")
        return

    increase = increase.lower()
    if increase == "체력" or increase == "hp" or increase == "hitpoints" or increase == "max_hp" or increase == "maxhp":
        increase = "max_hp"
    elif increase == "공격" or increase == "attack" or increase == "att":
        increase = "attack"
    elif increase == "방어" or increase == "defense" or increase == "def" or increase == "defence":
        increase = "defense"

    success, new_level = character.level_up(increase)
    if success:
        await ctx.message.reply(f"{character.name} 는(은) 레벨 {new_level} 이 되었습니다. {increase.upper().replace('_', ' ')}의 능력이 1 성장했습니다.")
    else:
        await ctx.message.reply(f"{character.name} failed to level up.")

There are too many words ‘DEEFENSE’ in the CODE I’m trying to change it one by one, but I haven’t found the answer yet.

I think this sentence is the key. What does this sentence mean?

{increase.upper().replace('_', ' ')}의 능력이 1 성장했습니다.")

If want to change ‘DEFFENSE’ to another word, which part of CODE should I modify?

Please tell me if it is against the rules of the community to ask these questions. I must have made a mistake because I don’t know where to ask.

Hi @mo1203 thank you for your question.

I think what you are asking is for a user to be able to type in “defence” but in a different language, is that right? If so the best way to do this is to use search and replace within the Repl (ctrl + h)

3 Likes

Hi! thank you for ur answer! :slight_smile:

When I entered the !levelup defense command,
I’d like to revise the notice of bot.

The current notice says,
ㅇㅇ advanced to level N, gaining 1 DEFENSE.
I want to change DEFENSE in this sentence to another word.

However, because there is too much DEFENSE throughout the CODE, switching to Ctrl+h results in an error. It seems to change the definition that should not be changed.

 success, new_level = character.level_up(increase)
    if success:
        await ctx.message.reply(f"{character.name} advanced to level {new_level}, gaining 1 {increase.upper().replace('_', ' ')}.")
    else:
        await ctx.message.reply(f"{character.name} failed to level up.")

In my opinion, it would be important to check what the < {increase.upper().replace(‘_’, ’ ')} > part of this code means. Then I could change DEFENSE into another language…!! (Ex. 방어)

I am very sorry if this is a basic question, because I am new to Python.

Hi @mo1203

You are doing well finding that particular section of code. What it is doing is turning whatever is in the variable increase to upper case and replacing any underscore characters (if they exist) with spaces.

So if I am reading this correctly you want to type !levelup defence into the bot, but have the following appear:

advanced to level N, gaining 1 방어.

If so, let me know.

2 Likes

Thank you so much!

Upper is an uppercase command
Replace is a command to change the previous content to the latter content.

I was really curious about what these meant
You have been very helpful!!

Well,
I deleted the upper() command first.
DEFENSE is output as defense.

And, I changed the defences that I can change using Ctrl+h.


After many challenges, I felt that modifying the already existing defense word to ctrl+forh was not the right choice. lol

I decided to bypass the problem using the information you gave me.
And as a result,

By modifying the code, I was able to derive the result I wanted. OMG XD

 {increase.upper().replace(‘_’, ’ ')}

{increase.replace('_', ' ').replace('defense','방어')}

Your knowledge was of great help to me.

It wasn’t easy for me, but I’m very happy to succeed.

I’m glad. Have a nice day!!! :+1: :+1: :+1:

1 Like

Fantastic! Well done on solving your issue!

1 Like