Add ability to set eos language separate from pyfa language

This commit is contained in:
blitzmann
2020-07-22 23:41:38 -04:00
parent f1feb8cebe
commit ffb14a2393
5 changed files with 61 additions and 20 deletions

View File

@@ -190,10 +190,12 @@ def defPaths(customSavePath=None):
from service.settings import EOSSettings, LocaleSettings
eos.config.settings = EOSSettings.getInstance().EOSSettings # this is kind of confusing, but whatever
# set langauge
# set langauge, taking the passed argument or falling back to what's saved in the settings
localeSettings = LocaleSettings.getInstance()
language = language if language in localeSettings.supported_langauges else localeSettings.get('locale')
eos.config.set_lang(language)
# sets the lang for eos, using the mapped langauge.
eos.config.set_lang(localeSettings.get_eos_locale())
def defLogging():
global debug

View File

@@ -20,7 +20,7 @@ lang = ""
translation_mapping = {
"en": "",
"fr": "_fr",
"it": "_it",
# "it": "_it",
"ja": "_ja",
"ko": "_ko",
"ru": "_ru",
@@ -29,7 +29,7 @@ translation_mapping = {
def set_lang(i18n_lang):
global lang
lang = translation_mapping.get(i18n_lang, translation_mapping.get("en_US"))
lang = translation_mapping.get(i18n_lang, translation_mapping.get("en"))
pyfalog.debug("Gamedata connection string: {0}", gamedata_connectionstring)

View File

@@ -60,7 +60,7 @@ class PyfaApp(wx.App):
# If an unsupported language is requested default to English.
if lang in supLang:
selLang = supLang[lang]
selLang = supLang[lang].wxLocale
else:
selLang = wx.LANGUAGE_ENGLISH_US

View File

@@ -7,6 +7,8 @@ from gui.bitmap_loader import BitmapLoader
from gui.preferenceView import PreferenceView
from service.fit import Fit
from service.settings import SettingsProvider, LocaleSettings
import eos.config
_t = wx.GetTranslation
@@ -91,21 +93,43 @@ class PFGeneralPref(PreferenceView):
mainSizer.Add(self.rbAddLabels, 0, wx.EXPAND | wx.TOP | wx.RIGHT | wx.BOTTOM, 10)
self.rbAddLabels.Bind(wx.EVT_RADIOBOX, self.OnAddLabelsChange)
langBox = wx.StaticBoxSizer(wx.VERTICAL, panel, "Language (requires restart)")
mainSizer.Add(langBox, 0, wx.EXPAND | wx.TOP | wx.RIGHT | wx.BOTTOM, 10)
langSizer = wx.BoxSizer(wx.HORIZONTAL)
self.stLangLabel = wx.StaticText(panel, wx.ID_ANY, _t("Language (restart required):"), wx.DefaultPosition, wx.DefaultSize, 0)
self.stLangLabel = wx.StaticText(panel, wx.ID_ANY, _t("pyfa:"), wx.DefaultPosition, wx.DefaultSize, 0)
self.stLangLabel.Wrap(-1)
langSizer.Add(self.stLangLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.langChoices = self.localeSettings.supported_langauges.keys()
self.chLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [x for x in self.langChoices], 0)
self.chLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, sorted([x for x in self.langChoices]), 0)
self.chLang.Bind(wx.EVT_CHOICE, self.onLangSelection)
self.chLang.SetStringSelection(self.localeSettings.get('locale'))
langSizer.Add(self.chLang, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
mainSizer.Add(langSizer)
langBox.Add(langSizer)
eosLangSizer = wx.BoxSizer(wx.HORIZONTAL)
self.stEosLangLabel = wx.StaticText(panel, wx.ID_ANY, _t("EVE Data:"), wx.DefaultPosition, wx.DefaultSize, 0)
self.stEosLangLabel.Wrap(-1)
eosLangSizer.Add(self.stEosLangLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.eosLangChoices = eos.config.translation_mapping.keys()
self.chEosLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [LocaleSettings.defaults['eos_locale']]+sorted([x for x in self.eosLangChoices]), 0)
self.chEosLang.Bind(wx.EVT_CHOICE, self.onEosLangSelection)
self.chEosLang.SetStringSelection(self.localeSettings.get('eos_locale'))
eosLangSizer.Add(self.chEosLang, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
langBox.Add(eosLangSizer)
langBox.Add(wx.StaticText(panel, wx.ID_ANY,
_t("(Auto will use the same language pyfa uses if available, otherwise English)"),
wx.DefaultPosition,
wx.DefaultSize, 0), 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
self.sFit = Fit.getInstance()
self.cbGlobalChar.SetValue(self.sFit.serviceFittingOptions["useGlobalCharacter"])
@@ -145,6 +169,9 @@ class PFGeneralPref(PreferenceView):
def onLangSelection(self, event):
self.localeSettings.set('locale', self.chLang.GetString(self.chLang.GetSelection()))
def onEosLangSelection(self, event):
self.localeSettings.set('eos_locale', self.chEosLang.GetString(self.chEosLang.GetSelection()))
def onCBGlobalColorBySlot(self, event):
# todo: maybe create a SettingChanged event that we can fire, and have other things hook into, instead of having the preference panel itself handle the
# updating of things related to settings.

View File

@@ -22,6 +22,7 @@ import os.path
import urllib.request
import urllib.error
import urllib.parse
from collections import namedtuple
import wx
from logbook import Logger
@@ -535,19 +536,25 @@ class GraphSettings:
def set(self, type, value):
self.settings[type] = value
Locale = namedtuple('Locale', ['wxLocale', 'eosLang'])
class LocaleSettings:
_instance = None
DEFAULT = "en"
supported_langauges = {
"en": wx.LANGUAGE_ENGLISH_US,
"fr": wx.LANGUAGE_FRENCH,
"it": wx.LANGUAGE_ITALIAN,
"ja": wx.LANGUAGE_JAPANESE,
"ko": wx.LANGUAGE_KOREAN,
"ru": wx.LANGUAGE_RUSSIAN,
"zh": wx.LANGUAGE_CHINESE_SIMPLIFIED,
"en": Locale(wx.LANGUAGE_ENGLISH_US, 'en'),
"fr": Locale(wx.LANGUAGE_FRENCH, 'fr'),
"ja": Locale(wx.LANGUAGE_JAPANESE, 'ja'),
"ko": Locale(wx.LANGUAGE_KOREAN, 'ko'),
"ru": Locale(wx.LANGUAGE_RUSSIAN, 'ru'),
"zh": Locale(wx.LANGUAGE_CHINESE_SIMPLIFIED, 'zh'),
# Non game client langauges
"it": Locale(wx.LANGUAGE_ITALIAN, None),
}
defaults = {
'locale': DEFAULT,
'eos_locale': 'Auto' # flag for "Default" which is the same as the locale or, if not available, English
}
@classmethod
@@ -558,14 +565,19 @@ class LocaleSettings:
def __init__(self):
defaults = {
'locale': self.DEFAULT
}
self.settings = SettingsProvider.getInstance().getSettings('localeSettings', defaults)
self.settings = SettingsProvider.getInstance().getSettings('localeSettings', self.defaults)
def get(self, key):
"""gets the raw value fo the setting"""
return self.settings[key]
def get_eos_locale(self):
"""gets the effective value of the setting"""
val = self.settings['eos_locale']
return val if val != self.defaults['eos_locale'] else self.supported_langauges.get(self.settings['locale'], 'en').eosLang
def set(self, key, value):
if key == 'locale' and value not in self.supported_langauges:
self.settings[key] = self.DEFAULT