diff --git a/pandora/translation/models.py b/pandora/translation/models.py index 4151c269f..7ebc44853 100644 --- a/pandora/translation/models.py +++ b/pandora/translation/models.py @@ -17,8 +17,9 @@ def get_cache_key(key, lang): def load_itemkey_translations(): from annotation.models import Annotation + from item.models import Item from django.db.models import QuerySet - used_keys = [] + used_keys = set() for layer in settings.CONFIG['layers']: if layer.get('translate'): qs = Annotation.objects.filter(layer=layer['id']) @@ -28,11 +29,31 @@ def load_itemkey_translations(): for lang in settings.CONFIG['languages']: if lang == settings.CONFIG['language']: continue - used_keys.append(value) - t, created = Translation.objects.get_or_create(lang=lang, key=value) - if created: - t.type = Translation.CONTENT - t.save() + used_keys.add(value) + t, _ = Translation.objects.get_or_create(lang=lang, key=value, defaults={ + 'type': Translation.CONTENT + }) + + translated_keys = [] + for key in settings.CONFIG['itemKeys']: + if key.get('translate'): + translated_keys.append(key['id']) + + if translated_keys: + for item in Item.objects.all(): + for key in translated_keys: + values = item.get(key) + if isinstance(values, str): + values = [values] + if values: + for value in values: + for lang in settings.CONFIG['languages']: + if lang == settings.CONFIG['language']: + continue + used_keys.add(value) + t, _ = Translation.objects.get_or_create(lang=lang, key=value, defaults={ + 'type': Translation.CONTENT + }) Translation.objects.filter(type=Translation.CONTENT).exclude(key__in=used_keys).delete() diff --git a/static/js/filter.js b/static/js/filter.js index 68ba16183..dbbfaf4d9 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -15,8 +15,10 @@ pandora.ui.filter = function(id) { align: 'left', id: 'name', format: function(value) { - var layer = Ox.getObjectById(pandora.site.layers, filter.id); - if (layer && layer.translate) { + var layer = Ox.getObjectById(pandora.site.layers, filter.id), + key = Ox.getObjectById(pandora.site.itemKeys, filter.id); + console.log('filter', filter, key, layer) + if ((layer && layer.translate) || (key && key.translate)) { value = Ox._(value) } return filter.flag