Задать вопрос

Тел: +7 965 3737 888






<p>Changes <strong>all slugify calls</strong> to support translat automatically, behind the scenes. Using this one doesn't have to change any models or code to make it work everywhere.</p>
<p>Create new project, I call it myself <em>autoslugifytranslat</em>, and add the following to project's __init__.py file. It will automatically add translat slugify support for all default slugify calls.</p>
<p>This script is depending on the fact that slugify function in Django is always in <em>django.template.defaultfilters.slugify</em>.</p>
<p><strong>Note:</strong> The snippet is supposed to have "&#228;","&#196;" and "&#246;","&#214;" in the char_translat list, but djangosnippets does not let me put &#228;'s and &#246;'s to the code part!</p>

Вопрос полезен? Да0/Нет0

Ответы (2):

Ответ полезен? Да0/Нет0

Exogen, thanks! I didn't knew about AsciiDammit.py before.

Although it looks like (what I've found from google) that the translat table is hardcoded to python code in AsciiDammit.py. It is not good, after all it really isn't languages problem to handle such general things. I know better solution, using iconv and it's ratherly new feature translat to convert umlauts and friends to ASCII. Unfortunately I have no time to implement that.

And yes, this was more of intended as example how you can get rid of the "My 3rd party app (for example one in contrib) uses slugify function that does not support my umlauts blah blah..."

Ответ полезен? Да0/Нет0

The idea is good, it should be extended to do total ASCII replacement like AsciiDammit.py. Also, I recommend using re.sub for multiple replacements like this.