Different characters names depending of the language

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Different characters names depending of the language

#1 Post by Keinart » Mon Jul 20, 2015 8:53 pm

In my visual novel I have some names that are different depending of the language. Like "pianist" that is "pianista" in spanish. I thought that with a simple if and elif statements should be enough to make this difference but it doesn't work. How can I make it so I have different names depending of the language?

My code

Code: Select all

init:
    if Language(None):
        define chico = Character('Chico', ctc="ctce", what_prefix="«", what_suffix="»")
        define pianista = Character('Pianista', ctc="ctce", what_prefix="«", what_suffix="»")
        
    elif Language("english"):
        define chico = Character('Guy', ctc="ctce", what_prefix="\"", what_suffix="\"")
        define pianista = Character('Pianist', ctc="ctce", what_prefix="\"", what_suffix="\"")
Thanks in advance for the help.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Different characters names depending of the language

#2 Post by trooper6 » Mon Jul 20, 2015 9:16 pm

try--

Code: Select all

define chico = Character("[ch_name]", ctc="ctce", what_prefix="«", what_suffix="»")
define pianista = Character("[p_name]", ctc="ctce", what_prefix="«", what_suffix="»")

label start:
    if Language(None):
        $ch_name = "Chico"
        $p_name = "Pianista"
    else:
        $ch_name = "Guy"
        $p_name = "Pianist"
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Different characters names depending of the language

#3 Post by Donmai » Mon Jul 20, 2015 10:48 pm

If you are generating translations using Ren'Py default translation system, you just have to declare your characters names as the documentation recommends for string translations. For example, if a game is being created in Spanish:

Code: Select all

define p = Character(_("Pianista"))
The _() around the name is telling Ren'Py to translate that name. If then you generate English translations for the game, that name will appear in the translation files and you will be able to translate it as "Pianist". No need to define the character twice. http://www.renpy.org/doc/html/translati ... anslations
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Different characters names depending of the language

#4 Post by Keinart » Tue Jul 21, 2015 5:32 pm

Donmai wrote:[...]
I've read the translation documentation like a million times and for some reason didn't realize of something so simple. Oh well, thank you very much, it works perfectly.

Now I have a realated second question (more like two questions actually), about this.

I have a short sequence of images that move around in one screen. It's like a really small animation, but of course, because the text will be different in english than spanish, I need two different animations because how the words move around the screen would be different. Since if/elif/else doesn't work here I would like to know a method to do this.

Code: Select all

    if Language(None):
        show basado en hechos at Position(xalign=0.34, yalign=0.3)
        show reales at Position(xalign=0.7, yalign=0.3)
        with longdissolve
        with Pause(1.0)
        show reales at Position(xalign=0.7, yalign=0.5) with MoveTransition(3.0)
        show que deberian at Position(xalign=0.4, yalign=0.5)
    elif Language("english"):
        show basado en hechos at Position(xalign=0.34, yalign=0.3)
        show reales at Position(xalign=0.6, yalign=0.3)
        show story at Position(xalign=0.74, yalign=0.3)
        with longdissolve
        with Pause(1.0)
        hide reales with dissolve
        show story at Position(xalign=0.61, yalign=0.3) with MoveTransition(2.0)
        show que deberian at Position(xalign=0.5, yalign=0.5)
As you can notice, the english one even have one extra part and some different transitions due the nature of the sentence in english.

My other question would be about the what_prefix and what_suffix. I want to make it so the quotes mark " are always there before and after during dialogues for all characters, but in spanish I want to use a different quote «» since it's the correct one for this language. By just adding _() and then translating it doesn't seem to work. Any ideas?

Thanks again.

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Different characters names depending of the language

#5 Post by Donmai » Tue Jul 21, 2015 8:38 pm

Well... (¡Madre de Dios! ¡Esto parece ser bastante complicado! :lol: )
Using translated images is very easy. If you have an image with a text in Spanish inside, say, a folder named 'backgrounds' you just need to have an image in English with the same name inside another 'backgrounds' folder, inside the tl/english/ directory.
But you said the animations are different... In this case it would be better to convert the animations to movieclips, what do you think? You could have two movieclips with the same name (for example: palabras.webm) one in your game folder and the other inside the tl/english folder. Switching languages should select the right movieclip. Not certain it would work, though.
Keinart wrote:My other question would be about the what_prefix and what_suffix. I want to make it so the quotes mark " are always there before and after during dialogues for all characters, but in spanish I want to use a different quote «» since it's the correct one for this language. By just adding _() and then translating it doesn't seem to work. Any ideas?
No, sorry. That's looking like the case of having to declare the characters twice... and that would send us back to the starting point.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Different characters names depending of the language

#6 Post by nyaatrap » Tue Jul 21, 2015 10:56 pm

This works with if/elif clauses in labels/screens http://www.renpy.org/doc/html/translati ... s.language
Keinart wrote:My other question would be about the what_prefix and what_suffix. I want to make it so the quotes mark " are always there before and after during dialogues for all characters, but in spanish I want to use a different quote «» since it's the correct one for this language. By just adding _() and then translating it doesn't seem to work. Any ideas?
Characters can be redefined after start, so you can make a function to redefine characters then put it in an language change action.

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Different characters names depending of the language

#7 Post by Keinart » Wed Jul 22, 2015 5:22 am

Donmai wrote:[...]
It's a good idea and probably the easiest way to get this done, but at the same time I would like to evade using movieclips since I want to make the novel as lightweigh as possible. If I don't find any other solution I guess I'll just do that.

About the prefix and suffix it's kinda a problem, I guess I can make a pair for every character then just change the character talking in the translation document, but I wanted to look for a more professional way to do this.

nyaatrap wrote:This works with if/elif clauses in labels/screens http://www.renpy.org/doc/html/translati ... s.language

Characters can be redefined after start, so you can make a function to redefine characters then put it in an language change action.
Um... I'm not really getting what you mean. Do you say if I put the scene in a label then define it with _preferences.language it should work normally using if/elif? I would appreciate a dummies example if possible here :P, in any case, I'll try to experiment with this once I come back home.

For the second part, you mean something like what trooper6 said? I actually tried to do something like that but I couldn't manage to make it work. I'm not really good with code and more a writer man so I would appreciate examples :oops:

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Different characters names depending of the language

#8 Post by Donmai » Wed Jul 22, 2015 9:21 am

nyaatrap wrote:Characters can be redefined after start, so you can make a function to redefine characters then put it in an language change action.
That would be a nice and very useful cookbook recipe, for sure!
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Different characters names depending of the language

#9 Post by Keinart » Sat Jul 25, 2015 8:38 am

Well, after asking nyaatrap in private and some experimenting on my own I managed to make it work. I leave the code here in case someone else needs it :)

For the "two different animations" depending of the language, it was actually quite simple:

Code: Select all

    if _preferences.language == "english":
        show basado en hechos at Position(xalign=0.34, yalign=0.3)
        show reales at Position(xalign=0.6, yalign=0.3)
        show story at Position(xalign=0.74, yalign=0.3)
        with longdissolve
        with Pause(1.0)
        hide reales with dissolve
        show story at Position(xalign=0.61, yalign=0.3) with MoveTransition(2.0)
        show que deberian at Position(xalign=0.5, yalign=0.5)
    else:
        show basado en hechos at Position(xalign=0.34, yalign=0.3)
        show reales at Position(xalign=0.7, yalign=0.3)
        with longdissolve
        with Pause(1.0)
        show reales at Position(xalign=0.7, yalign=0.5) with MoveTransition(3.0)
        show que deberian at Position(xalign=0.4, yalign=0.5)
I was using the incorrect term, but doing it like this goes like a charm. The only issue is that if you change language in the middle of the game then it will display the incorrect images, due to them being saved in the cache memory.

Now for the prefix and suffix part, this is how I made it:

Code: Select all

define chico = Character(_('Chico'), ctc="ctce", what_prefix="[comillas]", what_suffix="[comillas2]")
define pianista = Character(_('Pianista'), ctc="ctce", what_prefix="[comillas]", what_suffix="[comillas2]")

label start:
    if _preferences.language == "english":
        $comillas = "\""
        $comillas2 = "\""
    else:
        $comillas = "«"
        $comillas2 = "»"
It works perfectly, but again it has a small issue, and that if you change language in the middle of the game then you need to start again the novel from the beginning or the prefix and suffix won't change. The same happens if you change language then load the game, but for that I managed to fix it adding the same code at the label after_load.

Code: Select all

label after_load:
    if _preferences.language == "english":
        $comillas = "\""
        $comillas2 = "\""
    else:
        $comillas = "«"
        $comillas2 = "»"
label start:
[...]
I guess to fix the small issues I'll just have to disable changing language in-game (that's is something I can deal with), unless I make the game reaload itself everytime the language is changed, but I have no idea how to do that, I tried with stuff like renpy.reload_script() but it just breaks my game and doesn't seem to work (or I have no idea how to use it, that is probably what happens here).

In any case, thank you guys very much for your help, if any of you know how to make the game autoreload after pressing a button I would appreaciate it.

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Different characters names depending of the language

#10 Post by Donmai » Sat Jul 25, 2015 9:01 am

Nice! Gracias for the code. :)
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Different characters names depending of the language

#11 Post by nyaatrap » Sat Jul 25, 2015 10:04 am

If you add an interact callback, then the code will run in every interaction. http://www.renpy.org/doc/html/config.ht ... _callbacks
This allows to redefine variables in mid-of the game. Example:

Code: Select all

init python:
    def change_language_callback():
        if _preferences.language == "english":
            store.variable = x # don't forget to add 'store.' to make a variable global.
        else:
            store.variable = y
        
    config.interact_callbacks.append(change_language_callback)
Alternatively, you can just run this function as a screen action (but I didn't test if functions run in order correctly)

Code: Select all

screen preferences():
   textbutton "English" action [Language("english"), Function(change_language_callback)]

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Different characters names depending of the language

#12 Post by Keinart » Sat Jul 25, 2015 12:07 pm

nyaatrap wrote:...
I'm getting an error message from this and the game won't even open

Code: Select all

While running game code:
  File "renpy/common/00start.rpy", line 150, in script call
    call _gl_test
  File "renpy/common/00gltest.rpy", line 358, in script
    $ __gl_test()
  File "renpy/common/00gltest.rpy", line 358, in <module>
    $ __gl_test()
  File "renpy/common/00gltest.rpy", line 284, in _m1_00gltest__gl_test
    _gl_performance_test()
  File "renpy/common/00gltest.rpy", line 301, in _gl_performance_test
    ui.interact(suppress_underlay=True, suppress_overlay=True)
  File "game/script.rpy", line 10, in change_language_callback
    store.variable = x # don't forget to add 'store.' to make a variable global.
NameError: global name 'x' is not defined
Do I need to define x and y?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Different characters names depending of the language

#13 Post by nyaatrap » Sat Jul 25, 2015 12:43 pm

au.. it's hard to explain programming basic in English for me. I'll pass it to a volunteer who is good on both English and Programming.

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Different characters names depending of the language

#14 Post by orz » Sat Jul 25, 2015 6:54 pm

Do I need to define x and y?
You're supposed to put in whatever you were wanting there *instead* of "store.variable = x" and y.

So instead of "store.variable = x", you'd put something like

Code: Select all

        define chico = Character('Guy', ctc="ctce", what_prefix="\"", what_suffix="\"")
        define pianista = Character('Pianist', ctc="ctce", what_prefix="\"", what_suffix="\"")
EXCEPT... the code nyaatrap posted was in python, not in renpy-script.

So in python, it'd be something like:

Code: Select all

    chico = Character('Guy', ctc="ctce", what_prefix="\"", what_suffix="\"")
    pianista = Character('Pianist', ctc="ctce", what_prefix="\"", what_suffix="\"")
EXCEPT... nyaatrap said, "don't forget to add 'store.' to make a variable global."

Therefore:

Code: Select all

    store.chico = Character('Guy', ctc="ctce", what_prefix="\"", what_suffix="\"")
    store.pianista = Character('Pianist', ctc="ctce", what_prefix="\"", what_suffix="\"")
and you'd put that in place of the "store.variable = x".

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Different characters names depending of the language

#15 Post by Keinart » Sat Jul 25, 2015 8:02 pm

orz wrote:...
It worked in the first try! Thank you very much, it was a great explanation.

Post Reply

Who is online

Users browsing this forum: No registered users