python - Translation in Django 1.6.5 -


recently had been working on website made 2 or 3 years ago predecessor (i write because app mess , it's not fault). boss asked me make multilingual adding english version. followed instructions djangoproject docs, made nice .po , .mo files in locale directory, set urls i18n views , added form proper select html. problem is, when send post language code setlang view i18n, django not change language nor throw errors. unfortunately, in 1.6.5, django.utils.translation doesn't have language_session_key, don't know how should change session data... so, here have settings:

""" django settings profilaktyka project.  more information on file, see https://docs.djangoproject.com/en/1.6/topics/settings/  full list of settings , values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """  # build paths inside project this: os.path.join(base_dir, ...) import os import time socket import gethostname   root = base_dir = os.path.dirname(os.path.dirname(__file__)) hostname = gethostname()   def make_path(path):     return os.path.join(base_dir, path)   def make_abs_path(path):     return os.path.abspath(make_path(path))   def get_proj_root():     curr_path = make_abs_path('')     return os.path.split(curr_path)[0]   # quick-start development settings - unsuitable production # see https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/  # security warning: keep secret key used in production secret! secret_key = ''  # security warning: don't run debug turned on in production! try:     plan_zajec import myconf     debug = myconf.debug     dist = myconf.dist except importerror:     debug = true     dist = false  template_debug = debug  if os.path.exists(os.path.join(base_dir, 'my.cnf')):     allowed_hosts = ['*']     # database     # https://docs.djangoproject.com/en/1.6/ref/settings/#databases     # settings.py     databases = {         'default': {             'engine': 'django.db.backends.mysql',             'options': {                 'read_default_file': os.path.join(base_dir, 'my.cnf'),             },         }     } else:     allowed_hosts = []     # database     # https://docs.djangoproject.com/en/1.6/ref/settings/#databases      # databases = {     #     'default': {     #         'engine': 'django.db.backends.sqlite3',     #         'name': os.path.join(base_dir, 'dev.sqlite'),     #     }     # }     databases = {         'default': {             'engine': 'django.db.backends.mysql', # add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.             'name': '', # or path database file if using sqlite3.             'user': '', # not used sqlite3.             'password': '', # not used sqlite3.             'host': '', # set empty string localhost. not used sqlite3.             'port': '', # set empty string default. not used sqlite3.         }     }  # application definition  installed_apps = (     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     # installed app:     # 'tinymce',     'djcelery',     'gunicorn',     'django_extensions',     'south',     # myapps:     'cv.editcv',     'cv.bazy', )   middleware_classes = (     'django.contrib.sessions.middleware.sessionmiddleware',     'django.middleware.locale.localemiddleware',     'django.middleware.common.commonmiddleware',     #'django.middleware.csrf.csrfviewmiddleware',     'django.contrib.auth.middleware.authenticationmiddleware',     'django.contrib.messages.middleware.messagemiddleware',     'django.middleware.clickjacking.xframeoptionsmiddleware',     'cv.lang.language', )  template_context_processors = (     'django.contrib.auth.context_processors.auth',     'django.core.context_processors.debug',     'django.core.context_processors.i18n',     'django.core.context_processors.media',     'django.core.context_processors.static',     'django.core.context_processors.tz',     'django.contrib.messages.context_processors.messages',     'django.core.context_processors.csrf' )   root_urlconf = 'website.urls'  wsgi_application = 'website.wsgi.application'  # internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/  language_code = 'pl'  time_zone = 'utc'  use_i18n = true  use_l10n = true  use_tz = true  # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.6/howto/static-files/ static_root = make_abs_path('static_root') static_url = '/static/'  # file upload config media_root = make_abs_path('media') media_url = '/media/'  # todo if 'ibmed' in hostname:     media_url = 'http://192.168.1.120:8080' + media_url     static_url = 'http://192.168.1.120:8080' + static_url   # logging logging = {     'version': 1,     'disable_existing_loggers': true,     'formatters': {         'verbose': {             'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'         },         'simple': {             'format': '%(levelname)s %(message)s'         },     },     'handlers': {         'null': {             'level': 'debug',             'class': 'logging.nullhandler',         },         'console': {             'level': 'debug',             'class': 'logging.streamhandler',             'formatter': 'simple'         },         'mail_admins': {             'level': 'error',             'class': 'django.utils.log.adminemailhandler',             'filters': [],         }     },     'loggers': {         'django': {             'handlers': ['null'],             'propagate': true,             'level': 'info',         },         'django.request': {             'handlers': ['mail_admins'],             'level': 'error',             'propagate': false,         },     } }   # south conf:  south_migration_modules = {     'django_extensions': 'ignore', }  session_expire_at_browser_close = true session_cookie_age = 36000 adres = '/cv/' login_url = adres + "logowanie/" date_format = 'y-m-d' my_adr = 'cv'  locale_paths = (     make_abs_path('locale')  )  broker_transport = 'redis' broker_url = 'redis://localhost:6379/0' celery_result_backend = "redis" celery_redis_host = "localhost" celery_redis_port = 6379 celery_redis_db = 0 

directory tree (as told, mess can't rework that, because "we don't have time that"...)

. ├── celerybeat-schedule ├── dryscrape │   └── (...) ├── env │   └── (...) ├── kariera.sublime-project ├── kariera.sublime-workspace ├── requirements.txt ├── src │   ├── addons.py │   ├── cv │   │   ├── editcv │   │   │   ├── administrator.py │   │   │   ├── admin.py │   │   │   ├── celeryconfig.py │   │   │   ├── celery.py │   │   │   ├── formularze2.py │   │   │   ├── formularze.py │   │   │   ├── formy.py │   │   │   ├── __init__.py │   │   │   ├── migrations │   │   │   │   └── (...) │   │   │   ├── models.py │   │   │   ├── opisy.py │   │   │   ├── publik.py │   │   │   ├── pubmedapi.py │   │   │   ├── punkty.py │   │   │   ├── tasks.py │   │   │   ├── templates │   │   │   │   └── (...) │   │   │   ├── templatetags │   │   │   │   └── (...) │   │   │   ├── ujbib.py │   │   │   ├── views.py │   │   │   ├── webofscienceapi.py │   │   │   ├── wykresy.py │   │   ├── formy.py │   │   ├── __init__.py │   │   ├── lang.py │   │   ├── std.py │   │   ├── views.py │   ├── czcionki │   │   └── (...) │   ├── develop.py │   ├── dev.sqlite │   ├── docxmp │   │   └── (...) │   ├── __init__.py │   ├── locale │   │   ├── en │   │   │   └── lc_messages │   │   │       ├── django.mo │   │   │       └── django.po │   │   └── pl │   │       └── lc_messages │   │           ├── django.mo │   │           └── django.po │   ├── manage.py │   ├── media │   │   └── (...) │   └── website │       ├── celery.py │       ├── __init__.py │       ├── settings.py │       ├── urls.py │       ├── wsgi.py ├── tags ├── webkit-server │   └── build │       ├── lib │       └── lib.linux-x86_64-2.7 └── xls     └── (...) 

in urls.py added:

url(r'^lang/', include(i18n)) 

which i'm using form:

<form action="/lang/setlang/" method="post">   {% csrf_token %}   <input type="submit" value="{% trans 'zmień język' %}" />   <select name="language">   {% language in st.languages %}   <option value="{{ language.code }}"{% if language.code == language_code %} selected="selected"{% endif %}>       {{ language.name_local }} ({{ language.code }})   </option>   {% endfor %}   </select> </form> 

st.languages just:

'languages': [     {'code': 'pl',      'name_local': 'polski'},     {'code': 'en',      'name_local': 'english'}] 

anyone?


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -