From 8ae7b5947eb4081bc743fe61dc9148f3d73fa2b2 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 26 Apr 2021 11:37:03 -0400 Subject: [PATCH] Separate interface language from search language in env vars The search language is now set using the WHOOGLE_CONFIG_SEARCH_LANGUAGE environment variable. Interface language is still set using WHOOGLE_CONFIG_LANGUAGE. Fixes #260 --- README.md | 25 +++++++++++++------------ app.json | 7 ++++++- app/models/config.py | 13 +++++++------ whoogle.env | 1 + 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 310fab5..cdcb2ad 100644 --- a/README.md +++ b/README.md @@ -258,18 +258,19 @@ There are a few optional environment variables available for customizing a Whoog ### Config Environment Variables These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. -| Variable | Description | -| ----------------------- | --------------------------------------------------------------- | -| WHOOGLE_CONFIG_COUNTRY | Filter results by hosting country | -| WHOOGLE_CONFIG_LANGUAGE | Set interface and search result language | -| WHOOGLE_CONFIG_DARK | Enable dark theme | -| WHOOGLE_CONFIG_SAFE | Enable safe searches | -| WHOOGLE_CONFIG_ALTS | Use social media site alternatives (nitter, invidious, etc) | -| WHOOGLE_CONFIG_TOR | Use Tor routing (if available) | -| WHOOGLE_CONFIG_NEW_TAB | Always open results in new tab | -| WHOOGLE_CONFIG_GET_ONLY | Search using GET requests only | -| WHOOGLE_CONFIG_URL | The root url of the instance (`https:///`) | -| WHOOGLE_CONFIG_STYLE | The custom CSS to use for styling (must be single line) | +| Variable | Description | +| ------------------------------ | --------------------------------------------------------------- | +| WHOOGLE_CONFIG_COUNTRY | Filter results by hosting country | +| WHOOGLE_CONFIG_LANGUAGE | Set interface language | +| WHOOGLE_CONFIG_SEARCH_LANGUAGE | Set search result language | +| WHOOGLE_CONFIG_DARK | Enable dark theme | +| WHOOGLE_CONFIG_SAFE | Enable safe searches | +| WHOOGLE_CONFIG_ALTS | Use social media site alternatives (nitter, invidious, etc) | +| WHOOGLE_CONFIG_TOR | Use Tor routing (if available) | +| WHOOGLE_CONFIG_NEW_TAB | Always open results in new tab | +| WHOOGLE_CONFIG_GET_ONLY | Search using GET requests only | +| WHOOGLE_CONFIG_URL | The root url of the instance (`https:///`) | +| WHOOGLE_CONFIG_STYLE | The custom CSS to use for styling (should be single line) | ## Usage Same as most search engines, with the exception of filtering by time range. diff --git a/app.json b/app.json index eb80f95..d1c7b55 100644 --- a/app.json +++ b/app.json @@ -71,7 +71,12 @@ "required": false }, "WHOOGLE_CONFIG_LANGUAGE": { - "description": "[CONFIG] The language to use for search results and interface (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", + "description": "[CONFIG] The language to use for the interface (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", + "value": "", + "required": false + }, + "WHOOGLE_CONFIG_SEARCH_LANGUAGE": { + "description": "[CONFIG] The language to use for search results (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", "value": "", "required": false }, diff --git a/app/models/config.py b/app/models/config.py index 8c83441..84ad0e4 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -12,7 +12,7 @@ class Config: app_config = current_app.config self.url = os.getenv('WHOOGLE_CONFIG_URL', '') - self.lang_search = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '') + self.lang_search = os.getenv('WHOOGLE_CONFIG_SEARCH_LANGUAGE', '') self.lang_interface = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '') self.style = os.getenv( 'WHOOGLE_CONFIG_STYLE', @@ -36,11 +36,12 @@ class Config: # Skip setting custom config if there isn't one if kwargs: - for attr in self.get_mutable_attrs(): - if attr not in kwargs.keys(): - setattr(self, attr, '') - else: + mutable_attrs = self.get_mutable_attrs() + for attr in mutable_attrs: + if attr in kwargs.keys(): setattr(self, attr, kwargs[attr]) + elif attr not in kwargs.keys() and mutable_attrs[attr] == bool: + setattr(self, attr, False) def __getitem__(self, name): return getattr(self, name) @@ -55,7 +56,7 @@ class Config: return hasattr(self, name) def get_mutable_attrs(self): - return {name: attr for name, attr in self.__dict__.items() + return {name: type(attr) for name, attr in self.__dict__.items() if not name.startswith("__") and (type(attr) is bool or type(attr) is str)} diff --git a/whoogle.env b/whoogle.env index 87a77a2..235a2e7 100644 --- a/whoogle.env +++ b/whoogle.env @@ -15,6 +15,7 @@ #WHOOGLE_CONFIG_COUNTRY=countryUK # See app/static/settings/countries.json for values #WHOOGLE_CONFIG_LANGUAGE=lang_en # See app/static/settings/languages.json for values +#WHOOGLE_CONFIG_SEARCH_LANGUAGE=lang_en # See app/static/settings/languages.json for values #WHOOGLE_CONFIG_DARK=1 # Dark mode #WHOOGLE_CONFIG_SAFE=1 # Safe searches #WHOOGLE_CONFIG_ALTS=1 # Use social media site alternatives