How to set language for django-pagination? - django

As you can see, django-pagination has polish (pl) translations - https://github.com/ericflo/django-pagination/tree/master/pagination/locale but I dont know, how to set polish language for django-pagination? (default english)

This should happen automatically.
Check your django settings if USE_I18N is set to True and if your LANGUAGE_CODE is set to pl.
For further information take a look at the django localization page. You can find a more detailed documentation of how the translation in django works here.
There's also a list of language codes, I guess pl should be correct.

You can either change the language setting of your browser, which will send the appropriate headers with each request and trigger the translation to be used, or you can provide a language setting selection so the user can choose their language.
You can roll your own code to provide this interface or use django-user-accounts.
You also might want to check that you have the appropriate middleware installed as described in this documenation.

Related

Django enable date localization but not translations

I want Django to localize all dates (in all regions), but I don't want translations. It seems like for a date to be put into the right locale, we need to add its language to LANGUAGES.
For dates to be localized, we also need USE_I18N = True and USE_L10N = True.
Is this even possible?
I don't want translations, because as long as the site is not fully translated, you will have a website that is only half-translated. This is an issue due to django, because its error messages are all translated.
The best approach for you is to store your data in your database as unix timestamps and then display them using javascript. This immidiately eliminates all the complex code you have for detecting the user's locale in django. With javascript it's a lot easier to do that, and also to display the time using the appropriate format.
toLocaleDateString is your friend
The toLocaleDateString() method returns a string with a language
sensitive representation of the date portion of this date. The new
locales and options arguments let applications specify the language
whose formatting conventions should be used and allow to customize the
behavior of the function. In older implementations, which ignore the
locales and options arguments, the locale used and the form of the
string returned are entirely implementation dependent.

Detecting user language with Django

I'm looking for a way to detect user language. I set my default language as 'en_US', and I translated my site for 'pt_BR'. How can I switch the language and show 'pt_BR' version for Brazilians and 'en_US' for the rest of the world?
I read these documentation links:
https://docs.djangoproject.com/en/dev/topics/http/sessions/
https://docs.djangoproject.com/en/1.7/topics/i18n/translation/
I believe that maybe I'll have to take this information from user cookies or browser preferences, but how can I do this?
Furthermore, how can I test different languages? I have to change my browser language? OS language? Use a proxy?
Every user's HTTP request contains in header parameter Accept-Language.
Example would be:
user_langs = request.META.get('HTTP_ACCEPT_LANGUAGE', ['en-US', ])
Try to add navigator.language to your post data and resolve it in your view.
http://www.w3schools.com/jsref/prop_nav_language.asp

is this a good use for django internationalisation

I am working on a django website/project, it has already been internationalised/localised to us-english, gb-english and mandarin.
It is deployed with same codebase except for the settings config which states what lang to use. Some deployments are mandarin only, others are us-english.
The client now has a requirement to change some of the language used within a gb-english version for a specific deployment. My main goal is not to duplicate things and I think I can get what I need out of django 18n.
Basically, I am looking to find if i can or should use django i18n to handle:
'Welcome' on deployA
'Oh hai' on deployB,
even though they're still both gb-english based sites, I feel I should be able to say that deployA will use 'en_GB' and deployB would use 'en_GB_special'.
I suppose it's the fact that I want to use a non-standard i18n name/code that is making me wonder if I should do this, or if I am approaching this in the wrong manner.
I would only create a new language if you're intending to maintain two translations. If the new site will need to stay in sync with en_GB and/or you intend to use the customization in another language then I think you'd be better off creating new messages, adding a string for them to en_GB and add a flag to your application to switch the feature for your feline client.

parsing language params in widget=BootstrapDateInput()?

How to pass language params to BootstrapDateInput
What about?
widget=BootstrapDateInput(language="pt-BR")
Any ideas?
The widget uses translation.get_language() to get the current language.
If you want to force a locale, you can set it manually, e.g.:
from django.utils import translation
translation.activate('pt-BR')
widget=BootstrapDateInput()
If you only use one language, set it in your settings.py:
LANGUAGE_CODE = 'pt-br'
In django-bootstrap-toolkit's versions before 2.11.5 there was an issue with the widget, which caused the widget to always use the same language-specific JS file, instead of using the one appropriate for the current language. This means that most likely, only the language set in settings.LANGUAGE_CODE would be supported by the widget, and it would default to English otherwise.
The issue has been fixed in version 2.11.5.

Can i use an other language instead of english for default django translation

Can I use another language instead of english(say, french) for default django translation.
For example, instead for doing this:
messages.error(request, _('My message in english'))
I do this:
messages.error(request, _('Mon message en francais'))
Yeah, you could do that, and it would mostly work, but better would be to write them in English and then provide French translations (via the standard i18n approach), and to set the project's LANGUAGE_CODE to 'fr' as well.
That way, your code will be more easily reusable in other languages, and - perhaps more usefully to you if you're not worried about that - you'll be able to cleanly use French/other language translations already available in any third-party apps you want to add to your site, else you'll be mixing what Django thinks is default English (but is French) and thinks is French (and is French)
Allez! ;o)