I have used django_tables2 in my web page to display a table.
My code for this table is in tables.py:
import django_tables2 as tables
from django.utils.translation import ugettext_lazy
from django.utils.encoding import force_text
class patchTable(tables.Table):
release_version=tables.Column(verbose_name=force_text(ugettext_lazy("Release Version"),orderable=False, localize=True)
patch_version=tables.Column(verbose_name=force_text(ugettext_lazy("Patch Version")),orderable=False, localize=True)
release_date = tables.Column(verbose_name=force_text(ugettext_lazy("Release Date")),orderable=False, localize=True)
upload_date = tables.Column(verbose_name=force_text(ugettext_lazy("Upload Date")),orderable=False, localize=True)
apply_status = tables.Column(verbose_name=force_text(ugettext_lazy("Status")),orderable=False, localize=True)
installation_date = tables.Column(verbose_name=force_text(ugettext_lazy("Installation Date")),orderable=False, localize=True)
In my views.py method i am doing "from myapp.tables import patchTable" and then updating the table contents,paginating and rendering to a template.
Above code works fine and displays the column name in a language which is currently i am using(during runserver command). but if i change the language selection on my HTML page all other contents on page gets translated but column name of this table doesn't.
If i restart the django server (cntrl+c and python2.7 manage runserver 0.0.0.0:8060) then these names changes to current language but they are not happening dynamically on language selection.
I tried using 1) "ugettext" 2) "ugettext_lazy" (this throws exception:'Lazy object returned unexpected type.)' 3) "force_text" and "ugettext_lazy" combination. But they are not working. Can anyone suggest me a feasible way of doing it?
By the way I am using Python 2.7, Django 1.5.1 and Django development server. All the localization settings requirement are included in project and settings.py has "USE_L10N = True" and "USE_I18N = True". Any help would be appreciated. Please let me know if this question needs much more details. Thanks in advance.