Separate Text and Voice Acting Selector, And Predicting User Language

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
CoolerMudkip
Regular
Posts: 40
Joined: Tue Jul 24, 2018 9:15 pm
Completed: Memories~ Megami no hogo-sha [Demo]
Projects: Northward
Tumblr: CoolerMudkip
Github: ztc0611
itch: MorallyGay
Location: United States, East Coast
Discord: MorallyGay#5861
Contact:

Separate Text and Voice Acting Selector, And Predicting User Language

#1 Post by CoolerMudkip »

I just spent a few hours working on this and I figured I should post my results just in case it helps anyone else in the future. This system allows for you to have a VN that has multiple languages supported, but doesn't lock your voice acting to match the language of the text. For example, the player can read in English but use Japanese voice acting, assuming you have full localizations for both of course.

For an added bit of spice, I also had this system predict your language. This will cause the language select screen to potentially be in the users correct language as it opens, instead of whatever your "None" language is. This will not force the VN into this language, only cause it to suggest it upon the first time it is opened.

Code to set up the language selector:

Code: Select all

init python: #Causes the VN to try and determine your computer's locale upon boot
    import locale
    persistent.locale = locale.getdefaultlocale()[0]
    del locale

label splashscreen:

    if not persistent.va_lang: #Set default localization
        if "es" in persistent.locale:
            $ renpy.change_language("spanish")
            $ persistent.va_lang = "audio/va/spanish/"
        elif "jp" in persistent.locale:
            $ renpy.change_language("japanese")
            $ persistent.va_lang = "audio/va/japanese/"
        ##add or remove any more languages you want. This uses the standard abbreviations of languages like
        else: ##fallback case                                         "zh" for Chinese, or "en" for English.
            $ renpy.change_language(None)
            $ persistent.va_lang = "audio/va/english/"

    if not persistent.lang_select: #Allow user to select localization and voice acting language
        pause 1.0
        $ renpy.transition(dissolve)
        call screen lang_select()
        $ persistent.lang_select = True
Code for the language select screen:

Code: Select all

screen lang_select:
    frame:
        style_prefix "navigation"
        yalign 0.5
        xalign 0.5
        xmaximum 1200
        xpadding 45
        ypadding 45
        vbox:
            style_prefix "radio"
            label _("Select your language...")
	    null height 20
            textbutton "English" action Language(None)
            textbutton "Español" action Language("spanish")
            textbutton "日本人" action Language("japanese")
            
            null height 45
            
            label _("Select your Voice Acting language...")
            null height 20
            textbutton "Español" action SetVariable('persistent.va_lang', "audio/va/spanish/")
            textbutton "English" action SetVariable('persistent.va_lang', "audio/va/english/")
            textbutton "日本人" action SetVariable('persistent.va_lang', "audio/va/japanese/")

            null height 45
            textbutton _("CONTINUE") action Return()
How to use the voice acting in script:

Code: Select all

voice persistent.va_lang+"e01.ogg"
e "Hello, I'm Eileen!"

voice persistent.va_lang+"e02.ogg"
e "I hope you're having a great day!"

Post Reply

Who is online

Users browsing this forum: odysseus93