Repository: lutris/lutris

Issue:
[Feature Request] Allow User to Choose Locale when installing Games
I play a lot of Japanese visual novels. These usually require a Japanese environment. At the moment, what I do is manually create a shared Wineprefix in the terminal and run the installer with `LANG=ja_JP.UTF-8`, but it would be cool if I could just use Lutris to install the game without needing to touch the terminal.

Not all visual novel installers require Japanese locale, but many do. I can already set the `WINEARCH` in Lutris with the installer preset, which is another problem with games that need a 32-bit environment.

If users could choose Japanese Locale in the installer, it would make a lot of visual novel installers work!
[Feature Request] Allow User to Choose Locale when installing Games
I play a lot of Japanese visual novels. These usually require a Japanese environment. At the moment, what I do is manually create a shared Wineprefix in the terminal and run the installer with `LANG=ja_JP.UTF-8`, but it would be cool if I could just use Lutris to install the game without needing to touch the terminal.

Not all visual novel installers require Japanese locale, but many do. I can already set the `WINEARCH` in Lutris with the installer preset, which is another problem with games that need a 32-bit environment.

If users could choose Japanese Locale in the installer, it would make a lot of visual novel installers work!


Discussion:
Did some more testing today. See H2O, which has garbled text/filenames when run without Japanese locale:

![h2o-nolocale](https://github.com/lutris/lutris/assets/88186997/1f57e932-09fd-4bac-818e-12fe2d8948ee)

When run with `LANG=ja_JP.UTF-8`, everything is fine:

![h2o-withlocale](https://github.com/lutris/lutris/assets/88186997/e214f397-9c37-4052-9e46-8f994afdb4ab)

If you proceed with the install process with the garbled characters, H2O won't install properly. When you try to launch it, it  will fail because the directory contains an illegal character instead of 枕. You need to rename the directory in your file manager if you install it with Lutris in order for it to work after install.
Setting `ja_JP.UTF-8` as the default Locale globally doesn't work. The installer appears to not respect this and the text does not display properly.

To confirm this, when running the Wineprefix that the Lutris installer wizard created in the terminal with `LANG=ja_JP.UTF-8` , the installer window text *does* display properly.
As a workaround, you can launch Lutris from the CLI with `LANG=ja_JP.UTF-8`:

```
LANG=ja_JP.UTF-8 lutris
```

And the text/filenames render correctly.
It occurs to me that this workaround would be different on distributions like Linux Mint, where they might be installing the latest version of Lutris via Flatpak:

```
LANG=ja_JP.UTF-8 flatpak run net.lutris.Lutris
```
Did some more testing today. See H2O, which has garbled text/filenames when run without Japanese locale:

![h2o-nolocale](https://github.com/lutris/lutris/assets/88186997/1f57e932-09fd-4bac-818e-12fe2d8948ee)

When run with `LANG=ja_JP.UTF-8`, everything is fine:

![h2o-withlocale](https://github.com/lutris/lutris/assets/88186997/e214f397-9c37-4052-9e46-8f994afdb4ab)

If you proceed with the install process with the garbled characters, H2O won't install properly. When you try to launch it, it  will fail because the directory contains an illegal character instead of 枕. You need to rename the directory in your file manager if you install it with Lutris in order for it to work after install.
Setting `ja_JP.UTF-8` as the default Locale globally doesn't work. The installer appears to not respect this and the text does not display properly.

To confirm this, when running the Wineprefix that the Lutris installer wizard created in the terminal with `LANG=ja_JP.UTF-8` , the installer window text *does* display properly.
As a workaround, you can launch Lutris from the CLI with `LANG=ja_JP.UTF-8`:

```
LANG=ja_JP.UTF-8 lutris
```

And the text/filenames render correctly.
It occurs to me that this workaround would be different on distributions like Linux Mint, where they might be installing the latest version of Lutris via Flatpak:

```
LANG=ja_JP.UTF-8 flatpak run net.lutris.Lutris
```

Resolving patch:
diff --git a/lutris/gui/addgameswindow.py b/lutris/gui/addgameswindow.py
--- a/lutris/gui/addgameswindow.py
+++ b/lutris/gui/addgameswindow.py
@@ -14,6 +14,7 @@
 from lutris.scanners.lutris import scan_directory
 from lutris.util.jobs import AsyncCall
 from lutris.util.strings import gtk_safe, slugify
+from lutris import sysoptions
 
 
 class AddGamesWindow(ModelessDialog):  # pylint: disable=too-many-public-methods
@@ -125,6 +126,8 @@ def __init__(self, **kwargs):
         self.install_from_setup_game_slug_entry = Gtk.Entry(sensitive=False)
         self.installer_presets = Gtk.ListStore(str, str)
         self.install_preset_dropdown = Gtk.ComboBox.new_with_model(self.installer_presets)
+        self.installer_locale = Gtk.ListStore(str, str)
+        self.install_locale_dropdown = Gtk.ComboBox.new_with_model(self.installer_locale)
 
         self.install_script_file_chooser = FileChooserEntry(
             title=_("Select script"), action=Gtk.FileChooserAction.OPEN
@@ -457,6 +460,23 @@ def create_install_from_setup_page(self):
         grid.attach(self.install_preset_dropdown, 1, 3, 1, 1)
         self.install_preset_dropdown.set_halign(Gtk.Align.START)
 
+        locale_label = Gtk.Label(_("Locale:"), visible=True)
+        locale_label.set_xalign(0)
+        grid.attach(locale_label, 0, 4, 1, 1)
+
+        locale_list = sysoptions.get_locale_choices()
+        for locale_humanized, locale in locale_list:
+            self.installer_locale.append([locale, _(locale_humanized)])
+
+        locale_renderer_text = Gtk.CellRendererText()
+        self.install_locale_dropdown.pack_start(locale_renderer_text, True)
+        self.install_locale_dropdown.add_attribute(locale_renderer_text, "text", 1)
+        self.install_locale_dropdown.set_id_column(0)
+        self.install_locale_dropdown.set_active(0)
+
+        grid.attach(self.install_locale_dropdown, 1, 4, 1, 1)
+        self.install_locale_dropdown.set_halign(Gtk.Align.START)
+
         grid.set_vexpand(True)
         return grid
 
@@ -498,6 +518,8 @@ def _on_install_setup_continue(self, button):
         else:
             win_ver_task = None
 
+        locale_selected = self.installer_locale[self.install_locale_dropdown.get_active()][0]
+
         installer = {
             "name": name,
             "version": _("Setup file"),
@@ -513,7 +535,12 @@ def _on_install_setup_continue(self, button):
                 ],
                 "installer": [
                     {"task": {"name": "wineexec", "executable": "setupfile", "arch": arch}}
-                ]
+                ],
+                "system": {
+                    "env": {
+                        "LC_ALL": locale_selected
+                    }
+                }
             }
         }
         if win_ver_task:


Test patch: