[wgem] handling i18n suggestion description | fix indexed search

This commit is contained in:
Vinícius Moreira
2019-12-17 13:11:38 -03:00
parent ea14310ad7
commit b4d3a48112
3 changed files with 29 additions and 10 deletions

View File

@@ -34,7 +34,7 @@ def main():
i18n_key, current_i18n = translation.get_locale_keys(args.locale)
default_i18n = translation.get_locale_keys(DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {}
i18n = I18n(current_i18n, default_i18n)
i18n = I18n(i18n_key, current_i18n, DEFAULT_I18N_KEY, default_i18n)
cache_cleaner = CacheCleaner()
cache_factory = DefaultMemoryCacheFactory(expiration_time=args.cache_exp, cleaner=cache_cleaner)

View File

@@ -190,13 +190,18 @@ class WebApplicationManager(SoftwareManager):
split_words = lower_words.split(' ')
singleword = ''.join(lower_words)
index_match_keys = set()
for word in (*split_words, singleword):
indexed = index.get(word)
if indexed:
index_match_keys.update(indexed)
query_list = [*split_words, singleword]
if index_match_keys:
index_match_keys = set()
for key in index:
for query in query_list:
if query in key:
index_match_keys.update(index[key])
if not index_match_keys:
self.logger.info("Query '{}' was not found in the suggestion's index".format(words))
res.installed.extend(installed_matches)
else:
if not os.path.exists(SUGGESTIONS_CACHE_FILE):
# if the suggestions cache was not found, it will not be possible to retrieve the matched apps
# so only the installed matches will be returned
@@ -224,7 +229,7 @@ class WebApplicationManager(SoftwareManager):
# checking if any of the installed matches is one of the matched suggestions
for sug in matched_suggestions:
found = (installed for installed in installed_matches if i.url == sug.get('url'))
found = [i for i in installed_matches if i.url == sug.get('url')]
if found:
res.installed.extend(found)
@@ -376,7 +381,7 @@ class WebApplicationManager(SoftwareManager):
op_igcert = InputOption(id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip'])
adv_opts = [op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert]
def_adv_opts = {op_single}
def_adv_opts = {op_single, op_allow_urls}
if app.preset_options:
for opt in adv_opts:
@@ -623,6 +628,18 @@ class WebApplicationManager(SoftwareManager):
icon_url=suggestion.get('icon_url'),
categories=[suggestion['category']] if suggestion.get('category') else None,
preset_options=suggestion.get('options'))
description = suggestion.get('description')
if isinstance(description, dict):
app.description = description.get(self.i18n.current_key, description.get(self.i18n.default_key))
elif isinstance(description, str):
app.description = description
if self.env_settings and self.env_settings.get('electron'):
app.version = self.env_settings['electron']['version']
app.latest_version = app.version
app.status = PackageStatus.LOADING_DATA
Thread(target=self._fill_suggestion, args=(app,)).start()

View File

@@ -7,9 +7,11 @@ from bauh.view.util import resource
class I18n(dict):
def __init__(self, current_locale: dict, default_locale: dict):
def __init__(self, current_key: str, current_locale: dict, default_key: str, default_locale: dict):
super(I18n, self).__init__()
self.current_key = current_key
self.current = current_locale
self.default_key = default_key
self.default = default_locale
def __getitem__(self, item):