make itemKeys also translatable

This commit is contained in:
j 2018-12-17 11:59:24 +01:00
parent df38aad4f7
commit 95b4d33614
2 changed files with 31 additions and 8 deletions

View file

@ -17,8 +17,9 @@ def get_cache_key(key, lang):
def load_itemkey_translations(): def load_itemkey_translations():
from annotation.models import Annotation from annotation.models import Annotation
from item.models import Item
from django.db.models import QuerySet from django.db.models import QuerySet
used_keys = [] used_keys = set()
for layer in settings.CONFIG['layers']: for layer in settings.CONFIG['layers']:
if layer.get('translate'): if layer.get('translate'):
qs = Annotation.objects.filter(layer=layer['id']) qs = Annotation.objects.filter(layer=layer['id'])
@ -28,11 +29,31 @@ def load_itemkey_translations():
for lang in settings.CONFIG['languages']: for lang in settings.CONFIG['languages']:
if lang == settings.CONFIG['language']: if lang == settings.CONFIG['language']:
continue continue
used_keys.append(value) used_keys.add(value)
t, created = Translation.objects.get_or_create(lang=lang, key=value) t, _ = Translation.objects.get_or_create(lang=lang, key=value, defaults={
if created: 'type': Translation.CONTENT
t.type = Translation.CONTENT })
t.save()
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() Translation.objects.filter(type=Translation.CONTENT).exclude(key__in=used_keys).delete()

View file

@ -15,8 +15,10 @@ pandora.ui.filter = function(id) {
align: 'left', align: 'left',
id: 'name', id: 'name',
format: function(value) { format: function(value) {
var layer = Ox.getObjectById(pandora.site.layers, filter.id); var layer = Ox.getObjectById(pandora.site.layers, filter.id),
if (layer && layer.translate) { key = Ox.getObjectById(pandora.site.itemKeys, filter.id);
console.log('filter', filter, key, layer)
if ((layer && layer.translate) || (key && key.translate)) {
value = Ox._(value) value = Ox._(value)
} }
return filter.flag return filter.flag