Blog

How to Add a One-Button Language Toggle in RenPy

RenPy Logo with the text; One Button Language Toggle. The background is filled with a variety of different languages.

Visual Novel readers and language learners are often looking for Visual Novels where they can switch between languages with a single button press.

Note

This guide builds on our previous RenPy tutorial, How to Add Multiple Languages to Your RenPy Game, so make sure you’ve set up multiple translations in your project before you start. If not, check out that tutorial first.

By the end of this walkthrough, your RenPy game will be able to toggle languages from the quick menu, or with a single keypress or game controller button press.

A full example of a RenPy project with a One Press Language Toggle Button, can be downloaded here.

1. Adding Language Toggle Logic

There are multiple ways a UI can be designed to allow a player to set a toggle language. In this tutorial, are simply going to set the toggle language to the last language (before the current one) that the user had selected.

Note

All of the code for this tutorial can just be added to screens.rpy. No other files need to be edited.

Let’s add out the Toggle Language script to screens.rpy:

# TOGGLE LANGUAGE
init python:
    # Toggle Language Value

    if not persistent.lang_on_toggle:
        persistent.lang_on_toggle = "ja"

    def set_lang_on_toggle():
        lang = renpy.game.preferences.language # get current renpy language
        if lang is None:
            lang  = "en"
        # print("lang_on_toggle set to:", lang)
        persistent.lang_on_toggle = lang

    # Toggle Language: Button Presses

    def toggle_text_language():
        new_lang = persistent.lang_on_toggle
        # Remember the old_lang
        set_lang_on_toggle()
        # Set language to new_lang
        renpy.change_language(new_lang)

    # Update Keyboard and Game Controller Bindings
    config.keymap["toggle_text_lang"] = [ "l", "L" ]
    config.pad_bindings["pad_lefttrigger_pos"] = [ "toggle_text_lang" ]
    config.pad_bindings["repeat_pad_lefttrigger_pos"] = [ "toggle_text_lang" ]

    # Add Mapping to Toggle Text Language Function
    custom_keymap = renpy.Keymap(toggle_text_lang = Function(toggle_text_language))
    config.underlay.append(custom_keymap)
About this Code
  1. We store the language that we’ll toggle to under ‘persistent.lang_on_toggle
  2. Whenever our function toggle_text_language is triggered, we swap the current language with the toggle language.
  3. We trigger our function toggle_text_language whenever the “L” key, or the Game Controller’s Left Trigger Button is tapped.

Toggle Language inside the Language Settings Screen

In screens.rpy, in screen language_settings():

  • Display the Toggle Language: e.g.

    vbox:
        style_prefix "radio"
        label _("Toggle Language")
        text persistent.lang_on_toggle.upper()
                    
  • Set the Toggle Language right before the current Text Language is updated, e.g.

    # Old Language Switching code:
    # textbutton "English" action Language("en")
    
    # New Language Swtiching code:
    textbutton "English" action [Function(set_lang_on_toggle), Language("en")]
                    

After those changes, your full screen language_settings() might look something like this (with some prettier labels):


3. Display a Language Toggle Button in Quick Menu

Finally, add a One-Click Language Toggle Button in the Quick Menu.

In screen quick_menu(), add one of these options, depending on your preference:

# Display a Language Toggle button with the Language Code
textbutton persistent.lang_on_toggle.upper() action Function(toggle_text_language)
            
# Display a Language Toggle button with the Language Name
$ toggleLangDetails = language_details[persistent.lang_on_toggle]
textbutton toggleLangDetails["name"] text_font toggleLangDetails["font"] action Function(toggle_text_language) yoffset -4
            

Summary

That’s it! You now have a working One-Click Language Switching Button in your RenPy game! 🎊✨

If you have any questions, or are keen to share what you’ve created (we would love to play your Visual Novel 💖), please reach out!


Omnilingual Access Logo
Omnilingual Access

Copyright © 2025 Omnilingual Access. All rights reserved.