Skip to content

Commit

Permalink
fixing MultilangHarvester to use the iso_values values instead of cka…
Browse files Browse the repository at this point in the history
…n_locales_mapping
  • Loading branch information
Gpetrak committed Jul 17, 2024
1 parent dbfce49 commit 4b3be9c
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions ckanext/multilang/harvesters/multilang.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,43 +160,49 @@ def get_package_dict(self, iso_values, harvest_object):
package_dict = super(MultilangHarvester, self).get_package_dict(iso_values, harvest_object)

self._package_dict = {}

harvester_config = self.source_config.get('ckan_locales_mapping', {})
if harvester_config:
self._ckan_locales_mapping = harvester_config
log.info('::::: ckan_locales_mapping entry found in harvester configuration :::::')

if iso_values['abstract-text'] and iso_values['title-text']:
log.debug('::::: Collecting localised data from the metadata abstract :::::')
localised_abstracts = []
for abstract_entry in iso_values['abstract-text']:
if abstract_entry['text'] and abstract_entry['locale'].lower()[1:]:
if self._ckan_locales_mapping[abstract_entry['locale'].lower()[1:]]:
localised_abstracts.append({
'text': abstract_entry['text'],
'locale': self._ckan_locales_mapping[abstract_entry['locale'].lower()[1:]]
})
else:
log.warning('Locale Mapping not found for metadata abstract, entry skipped!')
# We comment out this if because abstract_entry['locale'] is equal with the CKAN
# definition so we don't need the ckan_locales_mapping for now
# if self._ckan_locales_mapping[abstract_entry['locale'].lower()[1:]]:
localised_abstracts.append({
'text': abstract_entry['text'],
'locale': abstract_entry['locale'].lower()[1:]
# 'locale': self._ckan_locales_mapping[abstract_entry['locale'].lower()[1:]]
})
#else:
# log.warning('Locale Mapping not found for metadata abstract, entry skipped!')
else:
log.warning('TextGroup data not available for metadata abstract, entry skipped!')

log.debug('::::: Collecting localized data from the metadata title :::::')
localised_titles = []
for title_entry in iso_values['title-text']:
if title_entry['text'] and title_entry['locale'].lower()[1:]:
if self._ckan_locales_mapping[title_entry['locale'].lower()[1:]]:
localised_titles.append({
'text': title_entry['text'],
'locale': self._ckan_locales_mapping[title_entry['locale'].lower()[1:]]
})
else:
log.warning('Locale Mapping not found for metadata title, entry skipped!')
# the same as above
# if self._ckan_locales_mapping[title_entry['locale'].lower()[1:]]:
localised_titles.append({
'text': title_entry['text'],
# 'locale': self._ckan_locales_mapping[title_entry['locale'].lower()[1:]]
'locale': title_entry['locale'].lower()[1:]
})
#else:
# log.warning('Locale Mapping not found for metadata title, entry skipped!')
else:
log.warning('TextGroup data not available for metadata title, entry skipped!')

localised_titles.append({
'text': iso_values['title'],
# because iso_values['metadata-language']=ita we remove the last letter
'locale': self._ckan_locales_mapping[iso_values['metadata-language'].lower()]
})

Expand Down Expand Up @@ -231,14 +237,15 @@ def get_package_dict(self, iso_values, harvest_object):

for tag_localized in tag_localized_entry:
if tag_localized['text'] and tag_localized['locale'].lower()[1:]:
if self._ckan_locales_mapping[tag_localized['locale'].lower()[1:]]:
localized_tags.append({
'text': tag_localized['name'],
'localized_text': tag_localized['text'],
'locale': self._ckan_locales_mapping[tag_localized['locale'].lower()[1:]]
})
else:
log.warning('Locale Mapping not found for metadata keyword: %r, entry skipped!', tag_localized['name'])
# if self._ckan_locales_mapping[tag_localized['locale'].lower()[1:]]:
localized_tags.append({
'text': tag_localized['name'],
'localized_text': tag_localized['text'],
# 'locale': self._ckan_locales_mapping[tag_localized['locale'].lower()[1:]]
'locale': tag_localized['locale'].lower()[1:]
})
#else:
# log.warning('Locale Mapping not found for metadata keyword: %r, entry skipped!', tag_localized['name'])
else:
log.warning('TextGroup data not available for metadata keyword: %r, entry skipped!', tag_localized['name'])

Expand Down Expand Up @@ -283,13 +290,14 @@ def handle_organization(self, harvest_object, organisation_mapping, values):

for entry in party['organisation-name-localized']:
if entry['text'] and entry['locale'].lower()[1:]:
if self._ckan_locales_mapping[entry['locale'].lower()[1:]]:
localized_org.append({
'text': org.get('value_' + self._ckan_locales_mapping[entry['locale'].lower()[1:]]) or entry['text'],
'locale': self._ckan_locales_mapping[entry['locale'].lower()[1:]]
})
else:
log.warning('Locale Mapping not found for organization name, entry skipped!')
# if self._ckan_locales_mapping[entry['locale'].lower()[1:]]:
localized_org.append({
'text': org.get('value_' + self._ckan_locales_mapping[entry['locale'].lower()[1:]]) or entry['text'],
# 'locale': self._ckan_locales_mapping[entry['locale'].lower()[1:]]
'locale': entry['locale'].lower()[1:]
})
#else:
# log.warning('Locale Mapping not found for organization name, entry skipped!')
else:
log.warning('TextGroup data not available for organization name, entry skipped!')

Expand Down

0 comments on commit 4b3be9c

Please sign in to comment.