Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11714 - Document a few of the i18n function that can be used o…

…utside views and templates. Thanks, Jarek Zgoda and Ramiro Morales.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12473 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0d4726f5189ff2d138435fed223b91e6af167777 1 parent 84f8213
Jannis Leidel authored February 21, 2010
33  docs/howto/i18n.txt
@@ -70,3 +70,36 @@ The easiest way out is to store applications that are not part of the project
70 70
 ``django-admin.py makemessages`` on the project level will only translate
71 71
 strings that are connected to your explicit project and not strings that are
72 72
 distributed independently.
  73
+
  74
+Using translations outside views and templates
  75
+==============================================
  76
+
  77
+While Django provides a rich set of i18n tools for use in views and templates,
  78
+it does not restrict the usage to Django-specific code. The Django translation
  79
+mechanisms can be used to translate arbitrary texts to any language that is
  80
+supported by Django (as long as an appropriate translation catalog exists, of
  81
+course). You can load a translation catalog, activate it and translate text to
  82
+language of your choice, but remember to switch back to original language, as
  83
+activating a translation catalog is done on per-thread basis and such change
  84
+will affect code running in the same thread.
  85
+
  86
+For example::
  87
+
  88
+    from django.utils import translation
  89
+    def welcome_translated(language):
  90
+        cur_language = translation.get_language()
  91
+        try:
  92
+            translation.activate(language)
  93
+            text = translation.ugettext('welcome')
  94
+        finally:
  95
+            translation.activate(cur_language)
  96
+        return text
  97
+
  98
+Calling this function with the value 'de' will give you ``"Willkommen"``,
  99
+regardless of :setting:`LANGUAGE_CODE` and language set by middleware.
  100
+
  101
+Functions of particular interest are ``django.utils.translation.get_language()``
  102
+which returns the language used in the current thread,
  103
+``django.utils.translation.activate()`` which activates a translation catalog
  104
+for the current thread, and ``django.utils.translation.check_for_language()``
  105
+which checks if the given language is supported by Django.
4  docs/topics/i18n/index.txt
@@ -18,11 +18,11 @@ Essentially, Django does two things:
18 18
       to their language preferences.
19 19
 
20 20
 The complete process can be seen as divided in three stages. It is also possible
21  
-to identify an identical number of roles with very well defined responsabilities
  21
+to identify an identical number of roles with very well defined responsibilities
22 22
 associated with each of these tasks (although it's perfectly normal if you
23 23
 find yourself performing more than one of these roles):
24 24
 
25  
-    * For applicacion authors wishing to make sure their Django apps can be
  25
+    * For application authors wishing to make sure their Django apps can be
26 26
       used in different locales: :ref:`topics-i18n-internationalization`.
27 27
     * For translators wanting to translate Django apps: :ref:`topics-i18n-localization`.
28 28
     * For system administrators/final users setting up internationalized apps or
7  docs/topics/i18n/localization.txt
@@ -237,8 +237,7 @@ test or compile a changed message file, you will need the ``gettext`` utilities:
237 237
 .. _mirrors: http://ftp.gnome.org/pub/GNOME/MIRRORS
238 238
 
239 239
 You may also use ``gettext`` binaries you have obtained elsewhere, so long as
240  
-the ``xgettext --version`` command works properly. Some version 0.14.4 binaries
241  
-have been found to not support this command. Do not attempt to use Django
  240
+the ``xgettext --version`` command works properly. Do not attempt to use Django
242 241
 translation utilities with a ``gettext`` package if the command ``xgettext
243 242
 --version`` entered at a Windows command prompt causes a popup window saying
244 243
 "xgettext.exe has generated errors and will be closed by Windows".
@@ -248,7 +247,7 @@ translation utilities with a ``gettext`` package if the command ``xgettext
248 247
 Format localization
249 248
 ===================
250 249
 
251  
-Django's formatting system is disabled by default. To enable it, it's necessay
  250
+Django's formatting system is disabled by default. To enable it, it's necessary
252 251
 to set :setting:`USE_L10N = True <USE_L10N>` in your settings file.
253 252
 
254 253
 When using Django's formatting system, dates and numbers on templates will be
@@ -271,7 +270,7 @@ or because you want to overwrite some of the values.
271 270
 
272 271
 To use custom formats, first thing to do, is to specify the path where you'll
273 272
 place format files. To do that, just set your :setting:`FORMAT_MODULE_PATH`
274  
-setting to the the path (in the format ``'foo.bar.baz``) where format files
  273
+setting to the path (in the format ``'foo.bar.baz``) where format files
275 274
 will exists.
276 275
 
277 276
 Files are not placed directly in this directory, but in a directory named as

0 notes on commit 0d4726f

Please sign in to comment.
Something went wrong with that request. Please try again.