profile
viewpoint
Борис Верховский verhovsky Toronto, Ontario, Canada

verhovsky/dtrx 4

Do The Right eXtraction (Python 3 fork. I think it works, but still a work in progress)

alexanderGugel/gr-a-ph 1

Graph-based programming for JavaScript [deprecated - was kind of a strange idea]

verhovsky/disable-stackexchange-editor-shortcuts 1

Use readline shortcuts on macOS (like ctrl-b to go back one letter) while editing answers and questions on StackOverflow. Still working as of Nov 2019.

verhovsky/advent-of-code 0

solutions to Advent of Code 2018

verhovsky/apt 0

Mirror of the apt git repository

verhovsky/autoflake 0

Removes unused imports and unused variables as reported by pyflakes

verhovsky/babel 0

The official repository for Babel, the Python Internationalization Library

verhovsky/blockchain-to-spreadsheet 0

Chrome browser extension that replaces the word "blockchain" with the phrase "multiple copies of a giant Excel spreadsheet."

verhovsky/books-futures-explained 0

The repository for the book Futures Explained in 200 lines of Rust

verhovsky/brew 0

🍺 The missing package manager for macOS (or Linux)

startedhpjansson/chafa

started time in 10 hours

fork agrinman/ssh-agent

rust ssh agent library

fork in 11 hours

startedloadimpact/k6

started time in 16 hours

fork alexanderGugel/glog

Leveled execution logs for Go

fork in 19 hours

startedgolang/glog

started time in 19 hours

startedloadimpact/k6

started time in a day

fork geohot/appnope

Disable App Nap on OS X 10.9

fork in a day

startedutkusen/urlhunter

started time in a day

startedgoogle/bloaty

started time in a day

startedKJCracks/yololib

started time in 2 days

fork agrinman/sekey

Use Touch ID / Secure Enclave for SSH Authentication!

fork in 2 days

fork darius/monte

A dynamic language inspired by Python and E.

fork in 2 days

fork FiloSottile/homebrew-core

🍻 Default formulae for the missing package manager for macOS

https://brew.sh

fork in 3 days

startedsyncthing/syncthing-macos

started time in 3 days

startedverhovsky/dtrx

started time in 3 days

starteddoyensec/awesome-electronjs-hacking

started time in 3 days

startedrasbt/mlxtend

started time in 3 days

startedscen/osxinj

started time in 3 days

startedJonGabilondoAngulo/Organismo-Lib

started time in 4 days

startedfrida/frida-gum

started time in 4 days

started0xcpu/bonomen

started time in 4 days

startedtauri-apps/tauri

started time in 4 days

issue commentdjango-parler/django-parler

Problem passing language code to foreign key

Hi @crstian

I was facing the same issue from last 2 days Today I was found the solution for this problem

I think Method-2 will best suit for you

Let me try to explain how set language is working in django

When you try to query using language():

queryA = ModelA.objects.language("de").get(pk=1)

This will work only for specified model i.e ModelA

We can also set language manually using set_current_language as you mentioned

queryB = ModelB.objects.get(pk=1)
queryB.set_current_language("de")
queryB.modelA.set_current_language("en")

We have to somehow inform django application to use language for that session or thread

Now Let's see how can change django language

There are 2 ways that I found

1st Method

We can use combination of django locale middleware and i18_url_pattern

#in setting.py
django.middleware.locale.LocaleMiddleware

#in urls.py (project urls not app urls)
urlpatterns += i18n_patterns(
    url(r'^api/', include('backend_api.urls')),
    prefix_default_language=False,
)

Now when you access any api/url http://localhost:8080/en/api/<path> this will set language for your current session/thread. After this on querying data from models you will get translated data for that language i.e en

2nd Method (I used this)

We can translation module available in by django.utils Method available in translation module are

with translation.override('fr'):
    print(_("Hello")) # <= will be translated inside the with block

translation.activate('fr') # <= will change the language for the whole thread.
# You then have to manually "restore" the language with another activate()
translation.activate('en') # <= change languages manually

In this case url pattern used is http://localhost:8080/api/<path>?lang=en and then will activate this language for that session

I hope you find this useful

Reference: https://stackoverflow.com/a/33649210

crstian

comment created time in 5 days

created repositorygraydon/obsidian-dangling-links

obsidian plugin for displaying dangling links

created time in 5 days

created repositoryanthonywritescode/auto-caps

an auto capitalization user extension!

created time in 6 days

startedRed5d/docker-autocompose

started time in 6 days

more