adding a custom language to django - python

I'm translating my website into the 24 languages of the European Union. These include the "Malti" language, that is not listed in django default supported languages.
I would like to know if there is a way to add a custom language to django so it can work with the native i18n url function.
Thanks!

I found the solution, you have to manually add a folder in /django/conf/locale/ with the language extension you want. Actually you can just copy past the en (english) folder and name it after the missing language (in my case mt).
In this folder you can also edit the file formats.py to localize the dates, numbers etc.
Restart django and your language will be natively supported.

Related

Is there difference between _xx.html and xx.html?

When I read the source code of a project:
I find there is some _xxx.html, why the author give the _? is there extraordinary should pay attention?
EDIT
This is in the Python Django project.
The template files are probably partials, or rather templates that aren't meant to be served directly, but rather within another template. Django doesn't seem to have anything specific about how to name your partials, but it does look like it's common practice in MVC frameworks to use _xx.html as a naming convention.
ASP.Net: ASP.NET MVC3 Partial View naming convention
RoR: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
Django: https://oncampus.oberlin.edu/webteam/2012/09/architecture-django-templates

Which languages are supported by django as part I18N, Localization

I'm trying to do Internationalization using Django. I've followed through docs and able to set it up right.
My questions here are
i) What are all the language supported by django?
ii) I've created '.po', '.mo' message files for the languages 'de' , 'de-at' but when trying to access those resources from API I'm only able to get resources from 'de' for both the cases. Does Django overrides 'de-at' by 'de' message file resources. Why is it so?
I've created message files using below commands by executing in project directory.
django-admin.py makemessages -l de
After running above command. I've added resources for both the languages corresponding in their '.po' file
django-admin.py compilemessages
Any help would be appreciated.
de-at is not supported by Django. So by default Django takes de message files.
Django documentation says :
In each of these places, the language preference is expected to be in the standard language format, as a string. For example, Brazilian Portuguese is pt-br.
If a base language is available but the sublanguage specified is not, Django uses the base language. For example, if a user specifies de-at (Austrian German) but Django only has de available, Django uses de.
Hence It returns messages inside a file 'de'
If the question is actual this might help you.
I had task to translate website both to de and de-at.
Django supports de-at language.
List of supported languages:
https://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
Or you can find on git language_info, I saw list of supported languages there too.
If you created in languages de-at - dash is separator and folder in locale named de_AT ( makemessages de_AT) it is enough. Django defines them as different languages. Problem may be in form you are using on front-end side. In my case form that I got from django documentation crashes on sublanguages so try to change your front-end form, you can find them in another stackoverflow questions.

How to manage system languages from django admin site?

Is there some way to enable/disable or add/delete system languages from django admin interface? Since Django says:
"It reads metadata in your model to provide a powerful and production-ready interface that content producers can immediately use to start adding content to the site."
And django book tells us:
"This is a Web-based interface, limited to trusted site administrators, that enables the adding, editing and deletion of site content."
I assume that main point is the power of manage content site. Then if my language setting enables content in some language in my site, why does django not allows me to modify it? (add/delete language to site).
I would have something like this:
Do you mean to translate the Admin interface itself? If so, this might help. Do you expect to have translation files in DB, in the admin/i18n? I don't think this is not how Django works, it works with .po/.mo files.
The internationalization documentation is really good, maybe a bit too big to digest when you just start, but Django has several switches to control what you want.
A good place to understand what switch to use for your need (at least I found it very interesting) is the implementation notes paragraph in there, and how Django discovers translations which gives a HLD of the logic.
Sorry if my answer look off-topic, but as Lara, I feel like I don't completely understand your question.

Django: allow safe html tags

Im looking into XSS with various frameworks and CMS and whether they provide methods in protecting against it (not just programmaticly avoiding the situation).
I know that in Djangos templating language you can specify a variable as |safe I want to be able to allow actually safe html tags so the user can format text (simple things like etc), but strip such things as , onload attributes etc.
I would like to know whether Django recommends a method in doing this, not just using Python. I hope this makes sense
Jason
One of the core concepts of Django is that it's Python, and any Python lib should be usable with Django. They won't recreate the wheel unless there is good reason to. I believe HTML scrubbing/sanitizing is one of the things they've decided not to recreate.
BeautifulSoup is the python library you want to look into for any scrubbing/sanitizing though.

Untrusted templates in Python - what is a safe library to use?

I am building a library that will be used in several Python applications. It get multilingual e-mail templates from an RMDBS, and then variable replacement will be performed on the template in Python before the e-mail is sent.
In addition to variable replacement, I need the template library to support if, elif, and for statements in the templates.
I use Mako for most my projects, and also looked at Tempita as it doesn't provide a lot of features I don't need.
The concern I have is untrusted code execution - can someone point me at a template solution for Python that either does not support code execution, or will allow me to disable it?
From the Django book:
For that reason, it’s impossible to call Python code directly within Django templates. All “programming” is fundamentally limited to the scope of what template tags can do. It is possible to write custom template tags that do arbitrary things, but the out-of-the-box Django template tags intentionally do not allow for arbitrary Python code execution.
Give Django templates a try. It's a little tricky to set up outside of a Django app -- something to do with DJANGO_SETTINGS_MODULE, search around -- but may be trusted.
Have you checked out Jinja2? It's pretty much what you're talking about, and it's a great mix of powerful while keeping things simple and not giving the designer too much power. :)
If you've used Django's template system, it's very similar (if not based off of?) Jinja.

Categories

Resources