@@ -657,9 +657,15 @@ Nesting arguments and more complex examples::
657657Template strings
658658----------------
659659
660- Templates provide simpler string substitutions as described in :pep: `292 `.
661- Instead of the normal ``% ``\ -based substitutions, Templates support ``$ ``\
662- -based substitutions, using the following rules:
660+ Template strings provide simpler string substitutions as described in
661+ :pep: `292 `. A primary use case for template strings is for
662+ internationalization (i18n) since in that context, the simpler syntax and
663+ functionality makes it easier to translate than other built-in string
664+ formatting facilities in Python. As an example of a library built on template
665+ strings for i18n, see the
666+ `flufl.i18n <http://flufli18n.readthedocs.io/en/latest/ >`_ package.
667+
668+ Template strings support ``$ ``-based substitutions, using the following rules:
663669
664670* ``$$ `` is an escape; it is replaced with a single ``$ ``.
665671
@@ -735,14 +741,17 @@ Here is an example of how to use a Template::
735741 >>> Template('$who likes $what').safe_substitute(d)
736742 'tim likes $what'
737743
738- Advanced usage: you can derive subclasses of :class: `Template ` to customize the
739- placeholder syntax, delimiter character, or the entire regular expression used
740- to parse template strings. To do this, you can override these class attributes:
744+ Advanced usage: you can derive subclasses of :class: `Template ` to customize
745+ the placeholder syntax, delimiter character, or the entire regular expression
746+ used to parse template strings. To do this, you can override these class
747+ attributes:
741748
742- * *delimiter * -- This is the literal string describing a placeholder introducing
743- delimiter. The default value is ``$ ``. Note that this should *not * be a
744- regular expression, as the implementation will call :meth: `re.escape ` on this
745- string as needed.
749+ * *delimiter * -- This is the literal string describing a placeholder
750+ introducing delimiter. The default value is ``$ ``. Note that this should
751+ *not * be a regular expression, as the implementation will call
752+ :meth: `re.escape ` on this string as needed. Note further that you cannot
753+ change the delimiter after class creation (i.e. a different delimiter must
754+ be set in the subclass's class namespace).
746755
747756* *idpattern * -- This is the regular expression describing the pattern for
748757 non-braced placeholders (the braces will be added automatically as
@@ -787,4 +796,3 @@ Helper functions
787796 or ``None ``, runs of whitespace characters are replaced by a single space
788797 and leading and trailing whitespace are removed, otherwise *sep * is used to
789798 split and join the words.
790-
0 commit comments