Open guglielmo opened 12 years ago
The same issue affects SearchIndex and prepare_* methods. Calling update_index from shell causes wrong (not translated) index entries, generated with ugettext.
This is really an issue with Django: management commands force the locale to 'en-us'. Django 1.6 added the leave_locale_alone
option to help with this:
I think @bmihelac has the right solution in #933 for adding a --locale
option to parallel the makemessages command.
Note also that there's currently no clean way to handle multilingual content when the backends are language-specific without using a custom update_index.py
which overrides the Haystack default one like this:
# encoding: utf-8
from __future__ import absolute_import
from django.utils import translation
from haystack.management.commands.update_index import Command as DefaultCommand
class Command(DefaultCommand):
def update_backend(self, label, using):
with translation.override(using):
super(Command, self).update_backend(label, using)
It feels like we should have an easier way to do this but it's something of an edge-case for many Haystack users.
Thanks. You are right, solution by @bmihelac in #933 seems correct.
@pirax In the meantime, should you need it the management command above should work in your project as well. If you just have a single language you could simplify it to override handle()
instead of update_backend()
and do the activation once at that level.
The
LANGUAGE_CODE
setting seem not to be active while in django shell. A simple way to reproduce the problem is:1 set the following variables in settings
2 copy-paste these instructions in the django shell.
The output will be
en-us
, regardless of the settings.Launching this as a python script, providing that the
DJANGO_SETTINGS_MODULE
variable is properly set, will output the correctit-it
value.This issue produces wrong index building, whenever using the prepare_template() method of SearchField to render values that need to be automatically converted for L10N reasons. For examples float values using
USE_THOUSAND_SEPARATOR = True
or dates.The issue is minor and can easily be circumvented, by subclassing the
SearchField
and overwriting theprepare_template
method, and then using the subclass in thesearch_indexes.py
definitions.:Nevertheless it could be more easily addressed directly in the
SerchField.prepare_render
method. This could also be inspiring to find analogue issues around Haystack code.