Skip to content

Commit

Permalink
allow setting bottle language
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Jun 27, 2022
1 parent 036f1f1 commit 84e931f
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/backend/models/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class Samples:
"DLL_Overrides": {},
"External_Programs": {},
"Uninstallers": {},
"Latest_Executables": []
"Latest_Executables": [],
"Language": "sys"
}

environments = {
Expand Down
91 changes: 91 additions & 0 deletions src/backend/utils/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import shutil
import gi
import os
import locale
import subprocess
from glob import glob
from typing import NewType, Union
Expand Down Expand Up @@ -299,3 +300,93 @@ def browse_wineprefix(wineprefix: dict):
path_type="custom",
custom_path=wineprefix.get("Path")
)

@staticmethod
def get_languages(from_name=None, from_locale=None, from_index=None, get_index=False, get_locales=False):
locales = [
'sys',
'bg_BG',
'cs_CZ',
'da_DK',
'de_DE',
'el_GR',
'en_US',
'es_ES',
'et_EE',
'fi_FI',
'fr_FR',
'hr_HR',
'hu_HU',
'it_IT',
'lt_LT',
'lv_LV',
'nl_NL',
'no_NO',
'pl_PL',
'pt_PT',
'ro_RO',
'ru_RU',
'sk_SK',
'sl_SI',
'sv_SE',
'tr_TR',
'zh_CN'
]
names = [
_('System'),
_('Bulgarian'),
_('Czech'),
_('Danish'),
_('German'),
_('Greek'),
_('English'),
_('Spanish'),
_('Estonian'),
_('Finnish'),
_('French'),
_('Croatian'),
_('Hungarian'),
_('Italian'),
_('Lithuanian'),
_('Latvian'),
_('Dutch'),
_('Norwegian'),
_('Polish'),
_('Portuguese'),
_('Romanian'),
_('Russian'),
_('Slovak'),
_('Slovenian'),
_('Swedish'),
_('Turkish'),
_('Chinese'),
]

if from_name and from_locale:
raise ValueError("Cannot pass both from_name, from_locale and from_index.")

if from_name:
if from_name not in names:
raise ValueError("Given name not in list.")
i = names.index(from_name)
if get_index:
return i
return from_name, locales[i]

if from_locale:
if from_locale not in locales:
raise ValueError("Given locale not in list.")
i = locales.index(from_locale)
if get_index:
return i
return from_locale, names[i]

if isinstance(from_index, int):
if from_index not in range(0, len(locales)):
raise ValueError("Given index not in range.")
return locales[from_index], names[from_index]

if get_locales:
return locales

return names
6 changes: 5 additions & 1 deletion src/backend/wine/winecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_env(self, environment, return_steam_env: bool = False) -> dict:
for var in config.get("Environment_Variables").items():
env.add(var[0], var[1], override=True)

# Environment variables from argument
# Environment variables from argument
if environment:
if environment.get("WINEDLLOVERRIDES"):
dll_overrides.append(environment["WINEDLLOVERRIDES"])
Expand All @@ -159,6 +159,10 @@ def get_env(self, environment, return_steam_env: bool = False) -> dict:
for e in environment:
env.add(e, environment[e], override=True)

# Language
if config["Language"] != "sys":
env.add("LC_ALL", config["Language"])

# Bottle DLL_Overrides
if config["DLL_Overrides"]:
for dll in config.get("DLL_Overrides").items():
Expand Down
12 changes: 11 additions & 1 deletion src/ui/details-preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
<object class="AdwActionRow">
<!-- TODO: replace with ComboRow -->
<property name="activatable-widget">combo_windows</property>
<property name="title" translatable="yes">Windows version</property>
<property name="title" translatable="yes">Windows Version</property>
<child>
<object class="GtkSpinner" id="spinner_win">
<property name="tooltip-text" translatable="yes">Updating Windows version, please wait…</property>
Expand Down Expand Up @@ -481,6 +481,16 @@
</child>
</object>
</child>
<child>
<object class="AdwComboRow" id="combo_language">
<property name="title" translatable="yes">Language</property>
<property name="subtitle" translatable="yes">Choose the language to use with programs.</property>
<property name="model">
<object class="GtkStringList" id="str_list_languages">
</object>
</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="row_runtime">
<property name="activatable-widget">switch_runtime</property>
Expand Down
31 changes: 30 additions & 1 deletion src/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from bottles.utils.threading import RunAsync # pyright: reportMissingImports=false
from bottles.utils.gtk import GtkUtils

from bottles.backend.runner import Runner, gamemode_available, gamescope_available, mangohud_available, obs_vkc_available
from bottles.backend.runner import Runner, gamemode_available, gamescope_available, mangohud_available, \
obs_vkc_available
from bottles.backend.managers.runtime import RuntimeManager
from bottles.backend.utils.manager import ManagerUtils

Expand Down Expand Up @@ -99,6 +100,7 @@ class PreferencesView(Adw.PreferencesPage):
combo_latencyflex = Gtk.Template.Child()
combo_windows = Gtk.Template.Child()
combo_renderer = Gtk.Template.Child()
combo_language = Gtk.Template.Child()
spinner_dxvk = Gtk.Template.Child()
spinner_dxvkbool = Gtk.Template.Child()
spinner_vkd3d = Gtk.Template.Child()
Expand All @@ -112,6 +114,7 @@ class PreferencesView(Adw.PreferencesPage):
box_sync = Gtk.Template.Child()
group_details = Gtk.Template.Child()
exp_components = Gtk.Template.Child()
str_list_languages = Gtk.Template.Child()
ev_controller = Gtk.EventControllerKey.new()

# endregion
Expand Down Expand Up @@ -167,6 +170,7 @@ def __init__(self, window, config, **kwargs):
self.combo_latencyflex.connect('changed', self.__set_latencyflex)
self.combo_windows.connect('changed', self.__set_windows)
self.combo_renderer.connect('changed', self.__set_renderer)
self.combo_language.connect('notify::selected-item', self.__set_language)
self.ev_controller.connect("key-released", self.__check_entry_name)
self.entry_name.connect("apply", self.__save_name)
# endregion
Expand Down Expand Up @@ -214,6 +218,7 @@ def __save_name(self, *args):

def choose_cwd(self, widget, reset=False):
"""Change the default current working directory for the bottle"""

def set_path(_dialog, response, _file_dialog):
if response == Gtk.ResponseType.OK:
_file = _file_dialog.get_file()
Expand Down Expand Up @@ -259,12 +264,14 @@ def update_combo_components(self):
self.combo_vkd3d.handler_block_by_func(self.__set_vkd3d)
self.combo_nvapi.handler_block_by_func(self.__set_nvapi)
self.combo_latencyflex.handler_block_by_func(self.__set_latencyflex)
self.combo_language.handler_block_by_func(self.__set_language)

self.combo_runner.remove_all()
self.combo_dxvk.remove_all()
self.combo_vkd3d.remove_all()
self.combo_nvapi.remove_all()
self.combo_latencyflex.remove_all()
self.str_list_languages.splice(0, self.str_list_languages.get_n_items())

for runner in self.manager.runners_available:
self.combo_runner.append(runner, runner)
Expand All @@ -281,11 +288,15 @@ def update_combo_components(self):
for latencyflex in self.manager.latencyflex_available:
self.combo_latencyflex.append(latencyflex, latencyflex)

for l in ManagerUtils.get_languages():
self.str_list_languages.append(l)

self.combo_runner.handler_unblock_by_func(self.__set_runner)
self.combo_dxvk.handler_unblock_by_func(self.__set_dxvk)
self.combo_vkd3d.handler_unblock_by_func(self.__set_vkd3d)
self.combo_nvapi.handler_unblock_by_func(self.__set_nvapi)
self.combo_latencyflex.handler_unblock_by_func(self.__set_latencyflex)
self.combo_language.handler_unblock_by_func(self.__set_language)

def set_config(self, config):
self.config = config
Expand Down Expand Up @@ -323,6 +334,7 @@ def set_config(self, config):
self.combo_latencyflex.handler_block_by_func(self.__set_latencyflex)
self.combo_windows.handler_block_by_func(self.__set_windows)
self.combo_renderer.handler_block_by_func(self.__set_renderer)
self.combo_language.handler_block_by_func(self.__set_language)
self.combo_dpi.handler_block_by_func(self.__set_custom_dpi)
self.toggle_sync.handler_block_by_func(self.__set_wine_sync)
self.toggle_esync.handler_block_by_func(self.__set_esync)
Expand Down Expand Up @@ -388,6 +400,10 @@ def set_config(self, config):
self.combo_windows.append("win95", "Windows 95")

self.combo_windows.set_active_id(self.config.get("Windows"))
self.combo_language.set_selected(ManagerUtils.get_languages(
from_locale=self.config.get("Language"),
get_index=True
))

# unlock functions connected to the widgets
self.switch_dxvk.handler_unblock_by_func(self.__toggle_dxvk)
Expand Down Expand Up @@ -421,6 +437,7 @@ def set_config(self, config):
self.combo_latencyflex.handler_unblock_by_func(self.__set_latencyflex)
self.combo_windows.handler_unblock_by_func(self.__set_windows)
self.combo_renderer.handler_unblock_by_func(self.__set_renderer)
self.combo_language.handler_unblock_by_func(self.__set_language)
self.combo_dpi.handler_unblock_by_func(self.__set_custom_dpi)
self.toggle_sync.handler_unblock_by_func(self.__set_wine_sync)
self.toggle_esync.handler_unblock_by_func(self.__set_esync)
Expand Down Expand Up @@ -457,6 +474,7 @@ def __set_sync_type(self, sync):
Set the sync type (wine, esync, fsync, futext2)
Don't use this directly, use dedicated wrappers instead (e.g. __set_wine_sync)
"""

def update(result, error=False):
self.config = result.data["config"]
toggles = [
Expand Down Expand Up @@ -873,6 +891,7 @@ def update(result, error=False):

def __set_renderer(self, widget):
"""Set the renderer to use for the bottle"""

def update(result, error=False):
self.config = self.manager.update_config(
config=self.config,
Expand All @@ -892,6 +911,16 @@ def update(result, error=False):
value=renderer
)

def __set_language(self, *args):
"""Set the language to use for the bottle"""
index = self.combo_language.get_selected()
language = ManagerUtils.get_languages(from_index=index)
self.config = self.manager.update_config(
config=self.config,
key="Language",
value=language[0],
).data["config"]

def __toggle_pulse_latency(self, widget, state):
"""Set the pulse latency to use for the bottle"""
self.config = self.manager.update_config(
Expand Down

0 comments on commit 84e931f

Please sign in to comment.