From bc662a546ed9028d93482f79314e64beae19a1d6 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 1 Jul 2010 01:45:39 +0200 Subject: [PATCH] Added a section about unicode and editors. This fixes #74 --- docs/_themes | 2 +- docs/unicode.rst | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/_themes b/docs/_themes index b8e0f4f1..21cf0743 160000 --- a/docs/_themes +++ b/docs/_themes @@ -1 +1 @@ -Subproject commit b8e0f4f1bfc7c89fffb5440fcdf60edaa033c836 +Subproject commit 21cf07433147212ee6c8ab203dfa648a9239c66f diff --git a/docs/unicode.rst b/docs/unicode.rst index e9259d12..7db462b8 100644 --- a/docs/unicode.rst +++ b/docs/unicode.rst @@ -54,6 +54,8 @@ unicode. What does working with unicode in Python 2.x mean? UTF-8 for this purpose. To tell the interpreter your encoding you can put the ``# -*- coding: utf-8 -*-`` into the first or second line of your Python source file. +- Jinja is configured to decode the template files from UTF08. So make + sure to tell your editor to save the file as UTF-8 there as well. Encoding and Decoding Yourself ------------------------------ @@ -79,3 +81,27 @@ To go from unicode into a specific charset such as UTF-8 you can use the def write_file(filename, contents, charset='utf-8'): with open(filename, 'w') as f: f.write(contents.encode(charset)) + +Configuring Editors +------------------- + +Most editors save as UTF-8 by default nowadays but in case your editor is +not configured to do this you have to change it. Here some common ways to +set your editor to store as UTF-8: + +- Vim: put ``set enc=utf-8`` to your ``.vimrc`` file. + +- Emacs: either use an encoding cookie or put this into your ``.emacs`` + file:: + + (prefer-coding-system 'utf-8) + (setq default-buffer-file-coding-system 'utf-8) + +- Notepad++: + + 1. Go to *Settings -> Preferences ...* + 2. Select the "New Document/Default Directory" tab + 3. Select "UTF-8 without BOM" as encoding + + It is also recommended to use the Unix newline format, you can select + it in the same panel but this not a requirement.