diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2013-07-04 15:41:16 +0200 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2013-07-04 15:41:16 +0200 |
commit | 874e39cb47cbba9b458b7bfe28fd4a4fc4d91844 (patch) | |
tree | 4e92d12640104c57e0b7388714b3ea20ff5793de /docs | |
parent | a1318b5cd7640520a5a6ec5e88658e432f2438db (diff) | |
download | babel-874e39cb47cbba9b458b7bfe28fd4a4fc4d91844.tar.gz |
Moved doc to docs
Diffstat (limited to 'docs')
39 files changed, 2790 insertions, 0 deletions
diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..c8c4f28 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Babel.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Babel.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/Babel" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Babel" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/_static/logo.pdf b/docs/_static/logo.pdf Binary files differnew file mode 100644 index 0000000..5385fd0 --- /dev/null +++ b/docs/_static/logo.pdf diff --git a/docs/_static/logo.png b/docs/_static/logo.png Binary files differnew file mode 100644 index 0000000..8060875 --- /dev/null +++ b/docs/_static/logo.png diff --git a/docs/_static/logo_small.png b/docs/_static/logo_small.png Binary files differnew file mode 100644 index 0000000..b9eddbd --- /dev/null +++ b/docs/_static/logo_small.png diff --git a/docs/_templates/sidebar-about.html b/docs/_templates/sidebar-about.html new file mode 100644 index 0000000..48a0e7b --- /dev/null +++ b/docs/_templates/sidebar-about.html @@ -0,0 +1,4 @@ +<h3>About</h3> +<p> + Babel is a collection of tools for internationalizing Python applications. +</p> diff --git a/docs/_templates/sidebar-links.html b/docs/_templates/sidebar-links.html new file mode 100644 index 0000000..91c486d --- /dev/null +++ b/docs/_templates/sidebar-links.html @@ -0,0 +1,6 @@ +<h3>Useful Links</h3> +<ul> + <li><a href="http://pypi.python.org/pypi/Babel">Babel @ PyPI</a></li> + <li><a href="http://github.com/mitsuhiko/babel">Babel @ github</a></li> + <li><a href="http://github.com/mitsuhiko/babel/issues">Issue Tracker</a></li> +</ul> diff --git a/docs/_templates/sidebar-logo.html b/docs/_templates/sidebar-logo.html new file mode 100644 index 0000000..6d5b051 --- /dev/null +++ b/docs/_templates/sidebar-logo.html @@ -0,0 +1,3 @@ +<p class="logo"><a href="{{ pathto(master_doc) }}"> + <img class="logo" src="{{ pathto('_static/logo_small.png', 1) }}" alt="Logo"/> +</a></p> diff --git a/docs/_themes/LICENSE b/docs/_themes/LICENSE new file mode 100644 index 0000000..8daab7e --- /dev/null +++ b/docs/_themes/LICENSE @@ -0,0 +1,37 @@ +Copyright (c) 2010 by Armin Ronacher. + +Some rights reserved. + +Redistribution and use in source and binary forms of the theme, with or +without modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +* The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +We kindly ask you to only use these themes in an unmodified manner just +for Flask and Flask-related products, not for unrelated projects. If you +like the visual style and want to use it for your own projects, please +consider making some larger changes to the themes (such as changing +font faces, sizes, colors or margins). + +THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/docs/_themes/README b/docs/_themes/README new file mode 100644 index 0000000..b3292bd --- /dev/null +++ b/docs/_themes/README @@ -0,0 +1,31 @@ +Flask Sphinx Styles +=================== + +This repository contains sphinx styles for Flask and Flask related +projects. To use this style in your Sphinx documentation, follow +this guide: + +1. put this folder as _themes into your docs folder. Alternatively + you can also use git submodules to check out the contents there. +2. add this to your conf.py: + + sys.path.append(os.path.abspath('_themes')) + html_theme_path = ['_themes'] + html_theme = 'flask' + +The following themes exist: + +- 'flask' - the standard flask documentation theme for large + projects +- 'flask_small' - small one-page theme. Intended to be used by + very small addon libraries for flask. + +The following options exist for the flask_small theme: + + [options] + index_logo = '' filename of a picture in _static + to be used as replacement for the + h1 in the index.rst file. + index_logo_height = 120px height of the index logo + github_fork = '' repository name on github for the + "fork me" badge diff --git a/docs/_themes/babel/layout.html b/docs/_themes/babel/layout.html new file mode 100644 index 0000000..1fd054e --- /dev/null +++ b/docs/_themes/babel/layout.html @@ -0,0 +1,27 @@ +{%- extends "basic/layout.html" %} +{%- block extrahead %} + {{ super() }} + {% if theme_touch_icon %} + <link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" /> + {% endif %} + <link media="only screen and (max-device-width: 480px)" href="{{ + pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" /> + <link href="//fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet" type="text/css"> + <link href="//fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css"> +{% endblock %} +{%- block relbar2 %}{% endblock %} +{% block header %} + {{ super() }} + {% if pagename == 'index' %} + <div class=indexwrapper> + {% endif %} +{% endblock %} +{%- block footer %} + <div class="footer"> + © Copyright {{ copyright }}. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>. + </div> + {% if pagename == 'index' %} + </div> + {% endif %} +{%- endblock %} diff --git a/docs/_themes/babel/relations.html b/docs/_themes/babel/relations.html new file mode 100644 index 0000000..3bbcde8 --- /dev/null +++ b/docs/_themes/babel/relations.html @@ -0,0 +1,19 @@ +<h3>Related Topics</h3> +<ul> + <li><a href="{{ pathto(master_doc) }}">Documentation overview</a><ul> + {%- for parent in parents %} + <li><a href="{{ parent.link|e }}">{{ parent.title }}</a><ul> + {%- endfor %} + {%- if prev %} + <li>Previous: <a href="{{ prev.link|e }}" title="{{ _('previous chapter') + }}">{{ prev.title }}</a></li> + {%- endif %} + {%- if next %} + <li>Next: <a href="{{ next.link|e }}" title="{{ _('next chapter') + }}">{{ next.title }}</a></li> + {%- endif %} + {%- for parent in parents %} + </ul></li> + {%- endfor %} + </ul></li> +</ul> diff --git a/docs/_themes/babel/static/babel.css_t b/docs/_themes/babel/static/babel.css_t new file mode 100644 index 0000000..924284a --- /dev/null +++ b/docs/_themes/babel/static/babel.css_t @@ -0,0 +1,409 @@ +/* + * babel.css_t + * ~~~~~~~~~~~~ + * + * :copyright: Copyright 2010 by Armin Ronacher. + * :license: Flask Design License, see LICENSE for details. + */ + +{% set page_width = '940px' %} +{% set sidebar_width = '220px' %} +{% set text_font = "'Open Sans', Verdana, Helvetica, sans-serif" %} +{% set title_font = "'Bree Serif', Georgia, serif" %} +{% set link_color = '#b00' %} +{% set hover_color = '#FC5E1E' %} + +@import url("basic.css"); + +/* -- page layout ----------------------------------------------------------- */ + +body { + font-family: {{ text_font }}; + font-size: 17px; + background-color: white; + color: #000; + margin: 0; + padding: 0; +} + +div.document { + width: {{ page_width }}; + margin: 30px auto 0 auto; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 {{ sidebar_width }}; +} + +div.sphinxsidebar { + width: {{ sidebar_width }}; +} + +hr { + border: 1px solid #B1B4B6; +} + +div.body { + background-color: #ffffff; + color: #3E4349; + padding: 0 30px 0 30px; +} + +img.floatingflask { + padding: 0 0 10px 10px; + float: right; +} + +div.footer { + width: {{ page_width }}; + margin: 20px auto 30px auto; + font-size: 14px; + color: #888; + text-align: right; +} + +div.footer a { + color: #888; +} + +div.related { + display: none; +} + +div.sphinxsidebar a { + color: #444; + text-decoration: none; + border-bottom: 1px dotted #999; +} + +div.sphinxsidebar a:hover { + border-bottom: 1px solid #999; +} + +div.sphinxsidebar { + font-size: 14px; + line-height: 1.5; +} + +div.sphinxsidebarwrapper { + padding: 10px; +} + +div.sphinxsidebarwrapper p.logo { + padding: 0 0 20px 0; + margin: 0; + text-align: center; +} + +div.sphinxsidebarwrapper img.logo { + margin-bottom: 20px; +} + +div.sphinxsidebar h3, +div.sphinxsidebar h4 { + font-family: {{ title_font }}; + color: #444; + font-size: 24px; + font-weight: normal; + margin: 0 0 5px 0; + padding: 0; +} + +div.sphinxsidebar h4 { + font-size: 20px; +} + +div.sphinxsidebar h3 a { + color: #444; +} + +div.sphinxsidebar p.logo a, +div.sphinxsidebar h3 a, +div.sphinxsidebar p.logo a:hover, +div.sphinxsidebar h3 a:hover { + border: none; +} + +div.sphinxsidebar p { + color: #555; + margin: 10px 0; +} + +div.sphinxsidebar ul { + margin: 10px 0; + padding: 0; + color: #000; +} + +div.sphinxsidebar input { + border: 1px solid #ccc; + font-family: {{ text_font }}; + font-size: 1em; +} + +/* -- body styles ----------------------------------------------------------- */ + +a { + color: {{ link_color }}; + text-decoration: underline; +} + +a:hover { + color: {{ hover_color }}; + text-decoration: underline; +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: {{ title_font }}; + font-weight: normal; + margin: 30px 0px 10px 0px; + padding: 0; +} + +{% if theme_index_logo %} +div.indexwrapper h1 { + text-indent: -999999px; + background: url({{ theme_index_logo }}) no-repeat center center; + height: {{ theme_index_logo_height }}; +} +{% endif %} + +div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } +div.body h2 { font-size: 180%; } +div.body h3 { font-size: 150%; } +div.body h4 { font-size: 130%; } +div.body h5 { font-size: 100%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: #ddd; + padding: 0 4px; + text-decoration: none; +} + +a.headerlink:hover { + color: #444; + background: #eaeaea; +} + +div.body p, div.body dd, div.body li { + line-height: 1.4em; +} + +div.admonition { + background: #fafafa; + margin: 20px -30px; + padding: 10px 30px; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; +} + +div.admonition tt.xref, div.admonition a tt { + border-bottom: 1px solid #fafafa; +} + +dd div.admonition { + margin-left: -60px; + padding-left: 60px; +} + +div.admonition p.admonition-title { + font-family: {{ title_font }}; + font-weight: normal; + font-size: 24px; + margin: 0 0 10px 0; + padding: 0; + line-height: 1; +} + +div.admonition p.last { + margin-bottom: 0; +} + +div.highlight { + background-color: white; +} + +dt:target, .highlight { + background: #FAF3E8; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.topic { + background-color: #eee; +} + +p.admonition-title { + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +pre, tt { + font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; + font-size: 0.9em; +} + +img.screenshot { +} + +tt.descname, tt.descclassname { + font-size: 0.95em; +} + +tt.descname { + padding-right: 0.08em; +} + +img.screenshot { + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils { + border: 1px solid #888; + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils td, table.docutils th { + border: 1px solid #888; + padding: 0.25em 0.7em; +} + +table.field-list, table.footnote { + border: none; + -moz-box-shadow: none; + -webkit-box-shadow: none; + box-shadow: none; +} + +table.footnote { + margin: 15px 0; + width: 100%; + border: 1px solid #eee; + background: #fdfdfd; + font-size: 0.9em; +} + +table.footnote + table.footnote { + margin-top: -15px; + border-top: none; +} + +table.field-list th { + padding: 0 0.8em 0 0; +} + +table.field-list td { + padding: 0; +} + +table.footnote td.label { + width: 0px; + padding: 0.3em 0 0.3em 0.5em; +} + +table.footnote td { + padding: 0.3em 0.5em; +} + +dl { + margin: 0; + padding: 0; +} + +dl dd { + margin-left: 30px; +} + +blockquote { + margin: 0 0 0 30px; + padding: 0; +} + +ul, ol { + margin: 10px 0 10px 30px; + padding: 0; +} + +pre { + background: #eee; + padding: 7px 30px; + margin: 15px -30px; + line-height: 1.3em; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; +} + +dl pre, blockquote pre, li pre { + margin-left: -60px; + padding-left: 60px; +} + +dl dl pre { + margin-left: -90px; + padding-left: 90px; +} + +tt { + background-color: #ecf0f3; + color: #222; + padding: 3px 6px; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; +} + +tt.xref, a tt { + background-color: #FBFBFB; + border-bottom: 1px solid white; +} + +a.reference { + text-decoration: none; + border-bottom: 1px dotted {{ link_color }}; +} + +a.reference:hover { + border-bottom: 1px solid {{ hover_color }}; +} + +a.footnote-reference { + text-decoration: none; + font-size: 0.7em; + vertical-align: top; + border-bottom: 1px dotted {{ link_color }}; +} + +a.footnote-reference:hover { + border-bottom: 1px solid {{ hover_color }}; +} + +a:hover tt { + background: #EEE; +} diff --git a/docs/_themes/babel/static/small_babel.css b/docs/_themes/babel/static/small_babel.css new file mode 100644 index 0000000..fdfee9c --- /dev/null +++ b/docs/_themes/babel/static/small_babel.css @@ -0,0 +1,70 @@ +/* + * small_babel.css_t + * ~~~~~~~~~~~~~~~~~ + * + * :copyright: Copyright 2010 by Armin Ronacher. + * :license: Flask Design License, see LICENSE for details. + */ + +body { + margin: 0; + padding: 20px 30px; +} + +div.documentwrapper { + float: none; + background: white; +} + +div.sphinxsidebar { + display: block; + float: none; + width: 102.5%; + margin: 50px -30px -20px -30px; + padding: 10px 20px; + background: #333; + color: white; +} + +div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, +div.sphinxsidebar h3 a { + color: white; +} + +div.sphinxsidebar a { + color: #aaa; +} + +div.sphinxsidebar p.logo { + display: none; +} + +div.document { + width: 100%; + margin: 0; +} + +div.related { + display: block; + margin: 0; + padding: 10px 0 20px 0; +} + +div.related ul, +div.related ul li { + margin: 0; + padding: 0; +} + +div.footer { + display: none; +} + +div.bodywrapper { + margin: 0; +} + +div.body { + min-height: 0; + padding: 0; +} diff --git a/docs/_themes/babel/theme.conf b/docs/_themes/babel/theme.conf new file mode 100644 index 0000000..81422ed --- /dev/null +++ b/docs/_themes/babel/theme.conf @@ -0,0 +1,8 @@ +[theme] +inherit = basic +stylesheet = babel.css + +[options] +index_logo = 'logo.png' +index_logo_height = 190px +touch_icon = diff --git a/docs/api/babel.core.rst b/docs/api/babel.core.rst new file mode 100644 index 0000000..acc63af --- /dev/null +++ b/docs/api/babel.core.rst @@ -0,0 +1,6 @@ +========== +babel.core +========== + +.. automodule:: babel.core + :members: diff --git a/docs/api/babel.dates.rst b/docs/api/babel.dates.rst new file mode 100644 index 0000000..639b279 --- /dev/null +++ b/docs/api/babel.dates.rst @@ -0,0 +1,6 @@ +=========== +babel.dates +=========== + +.. automodule:: babel.dates + :members: diff --git a/docs/api/babel.localedata.rst b/docs/api/babel.localedata.rst new file mode 100644 index 0000000..bdca426 --- /dev/null +++ b/docs/api/babel.localedata.rst @@ -0,0 +1,6 @@ +================ +babel.localedata +================ + +.. automodule:: babel.localedata + :members: diff --git a/docs/api/babel.messages.catalog.rst b/docs/api/babel.messages.catalog.rst new file mode 100644 index 0000000..b6edb49 --- /dev/null +++ b/docs/api/babel.messages.catalog.rst @@ -0,0 +1,6 @@ +====================== +babel.messages.catalog +====================== + +.. automodule:: babel.messages.catalog + :members: diff --git a/docs/api/babel.messages.checkers.rst b/docs/api/babel.messages.checkers.rst new file mode 100644 index 0000000..2d58631 --- /dev/null +++ b/docs/api/babel.messages.checkers.rst @@ -0,0 +1,6 @@ +======================= +babel.messages.checkers +======================= + +.. automodule:: babel.messages.checkers + :members: diff --git a/docs/api/babel.messages.extract.rst b/docs/api/babel.messages.extract.rst new file mode 100644 index 0000000..e846f38 --- /dev/null +++ b/docs/api/babel.messages.extract.rst @@ -0,0 +1,6 @@ +====================== +babel.messages.extract +====================== + +.. automodule:: babel.messages.extract + :members: diff --git a/docs/api/babel.messages.frontend.rst b/docs/api/babel.messages.frontend.rst new file mode 100644 index 0000000..0ca45ca --- /dev/null +++ b/docs/api/babel.messages.frontend.rst @@ -0,0 +1,6 @@ +======================= +babel.messages.frontend +======================= + +.. automodule:: babel.messages.frontend + :members: diff --git a/docs/api/babel.messages.mofile.rst b/docs/api/babel.messages.mofile.rst new file mode 100644 index 0000000..57919e7 --- /dev/null +++ b/docs/api/babel.messages.mofile.rst @@ -0,0 +1,6 @@ +===================== +babel.messages.mofile +===================== + +.. automodule:: babel.messages.mofile + :members: diff --git a/docs/api/babel.messages.plurals.rst b/docs/api/babel.messages.plurals.rst new file mode 100644 index 0000000..38ee7c6 --- /dev/null +++ b/docs/api/babel.messages.plurals.rst @@ -0,0 +1,6 @@ +====================== +babel.messages.plurals +====================== + +.. automodule:: babel.messages.plurals + :members: diff --git a/docs/api/babel.messages.pofile.rst b/docs/api/babel.messages.pofile.rst new file mode 100644 index 0000000..8d3cc3f --- /dev/null +++ b/docs/api/babel.messages.pofile.rst @@ -0,0 +1,6 @@ +===================== +babel.messages.pofile +===================== + +.. automodule:: babel.messages.pofile + :members: diff --git a/docs/api/babel.messages.rst b/docs/api/babel.messages.rst new file mode 100644 index 0000000..4bc9ef1 --- /dev/null +++ b/docs/api/babel.messages.rst @@ -0,0 +1,6 @@ +============== +babel.messages +============== + +.. automodule:: babel.messages + :members: diff --git a/docs/api/babel.numbers.rst b/docs/api/babel.numbers.rst new file mode 100644 index 0000000..8ac643d --- /dev/null +++ b/docs/api/babel.numbers.rst @@ -0,0 +1,6 @@ +============= +babel.numbers +============= + +.. automodule:: babel.numbers + :members: diff --git a/docs/api/babel.support.rst b/docs/api/babel.support.rst new file mode 100644 index 0000000..58d0b98 --- /dev/null +++ b/docs/api/babel.support.rst @@ -0,0 +1,6 @@ +============= +babel.support +============= + +.. automodule:: babel.support + :members: diff --git a/docs/api/babel.util.rst b/docs/api/babel.util.rst new file mode 100644 index 0000000..fa59470 --- /dev/null +++ b/docs/api/babel.util.rst @@ -0,0 +1,6 @@ +========== +babel.util +========== + +.. automodule:: babel.util + :members: diff --git a/docs/cmdline.rst b/docs/cmdline.rst new file mode 100644 index 0000000..dd93c2c --- /dev/null +++ b/docs/cmdline.rst @@ -0,0 +1,177 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +====================== +Command-Line Interface +====================== + +Babel includes a command-line interface for working with message catalogs, +similar to the various GNU ``gettext`` tools commonly available on Linux/Unix +systems. + + +When properly installed, Babel provides a script called ``pybabel``:: + + $ pybabel --help + usage: pybabel command [options] [args] + + options: + --version show program's version number and exit + -h, --help show this help message and exit + --list-locales print all known locales and exit + -v, --verbose print as much as possible + -q, --quiet print as little as possible + + commands: + compile compile message catalogs to MO files + extract extract messages from source files and generate a POT file + init create new message catalogs from a POT file + update update existing message catalogs from a POT file + +The ``pybabel`` script provides a number of sub-commands that do the actual +work. Those sub-commands are described below. + + +compile +======= + +The ``compile`` sub-command can be used to compile translation catalogs into +binary MO files:: + + $ pybabel compile --help + usage: pybabel compile [options] + + compile message catalogs to MO files + + options: + -h, --help show this help message and exit + -D DOMAIN, --domain=DOMAIN + domain of MO and PO files (default 'messages') + -d DIR, --directory=DIR + base directory of catalog files + -l LOCALE, --locale=LOCALE + locale of the catalog + -i FILE, --input-file=FILE + name of the input file + -o FILE, --output-file=FILE + name of the output file (default + '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo') + -f, --use-fuzzy also include fuzzy translations (default False) + --statistics print statistics about translations + +If ``directory`` is specified, but ``output-file`` is not, the default filename +of the output file will be:: + + <directory>/<locale>/LC_MESSAGES/<domain>.mo + +If neither the ``input_file`` nor the ``locale`` option is set, this command +looks for all catalog files in the base directory that match the given domain, +and compiles each of them to MO files in the same directory. + + +extract +======= + +The ``extract`` sub-command can be used to extract localizable messages from +a collection of source files:: + + $ pybabel extract --help + usage: pybabel extract [options] dir1 <dir2> ... + + extract messages from source files and generate a POT file + + options: + -h, --help show this help message and exit + --charset=CHARSET charset to use in the output (default "utf-8") + -k KEYWORDS, --keyword=KEYWORDS + keywords to look for in addition to the defaults. You + can specify multiple -k flags on the command line. + --no-default-keywords + do not include the default keywords + -F MAPPING_FILE, --mapping=MAPPING_FILE + path to the extraction mapping file + --no-location do not include location comments with filename and + line number + --omit-header do not include msgid "" entry in header + -o OUTPUT, --output=OUTPUT + path to the output POT file + -w WIDTH, --width=WIDTH + set output line width (default 76) + --no-wrap do not break long message lines, longer than the + output line width, into several lines + --sort-output generate sorted output (default False) + --sort-by-file sort output by file location (default False) + --msgid-bugs-address=EMAIL@ADDRESS + set report address for msgid + --copyright-holder=COPYRIGHT_HOLDER + set copyright holder in output + -c TAG, --add-comments=TAG + place comment block with TAG (or those preceding + keyword lines) in output file. One TAG per argument + call + + +init +==== + +The `init` sub-command creates a new translations catalog based on a PO +template file:: + + $ pybabel init --help + usage: pybabel init [options] + + create new message catalogs from a POT file + + options: + -h, --help show this help message and exit + -D DOMAIN, --domain=DOMAIN + domain of PO file (default 'messages') + -i FILE, --input-file=FILE + name of the input file + -d DIR, --output-dir=DIR + path to output directory + -o FILE, --output-file=FILE + name of the output file (default + '<output_dir>/<locale>/LC_MESSAGES/<domain>.po') + -l LOCALE, --locale=LOCALE + locale for the new localized catalog + + +update +====== + +The `update` sub-command updates an existing new translations catalog based on +a PO template file:: + + $ pybabel update --help + usage: pybabel update [options] + + update existing message catalogs from a POT file + + options: + -h, --help show this help message and exit + -D DOMAIN, --domain=DOMAIN + domain of PO file (default 'messages') + -i FILE, --input-file=FILE + name of the input file + -d DIR, --output-dir=DIR + path to output directory + -o FILE, --output-file=FILE + name of the output file (default + '<output_dir>/<locale>/LC_MESSAGES/<domain>.po') + -l LOCALE, --locale=LOCALE + locale of the translations catalog + --ignore-obsolete do not include obsolete messages in the output + (default False) + -N, --no-fuzzy-matching + do not use fuzzy matching (default False) + --previous keep previous msgids of translated messages (default + False) + +If ``output_dir`` is specified, but ``output-file`` is not, the default +filename of the output file will be:: + + <directory>/<locale>/LC_MESSAGES/<domain>.mo + +If neither the ``output_file`` nor the ``locale`` option is set, this command +looks for all catalog files in the base directory that match the given domain, +and updates each of them. diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..9e3d306 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,251 @@ +# -*- coding: utf-8 -*- +# +# Babel documentation build configuration file, created by +# sphinx-quickstart on Wed Jul 3 17:53:01 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('..')) +sys.path.append(os.path.abspath('_themes')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Babel' +copyright = u'2013, Edgewall Software' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.0' +# The full version, including alpha/beta/rc tags. +release = '1.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'babel' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +html_theme_path = ['_themes'] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +html_sidebars = { + 'index': ['sidebar-about.html', 'localtoc.html', 'sidebar-links.html', + 'searchbox.html'], + '**': ['sidebar-logo.html', 'localtoc.html', 'relations.html', + 'searchbox.html'] +} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +html_show_sourcelink = False + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Babeldoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Needed for unicode symbol conversion. +'fontpkg': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'Babel.tex', u'Babel Documentation', + u'Edgewall Software', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +latex_logo = '_static/logo.png' + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index_', 'babel', u'Babel Documentation', + [u'Edgewall Software'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index_', 'Babel', u'Babel Documentation', + u'Edgewall Software', 'Babel', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/docs/dates.rst b/docs/dates.rst new file mode 100644 index 0000000..e58c772 --- /dev/null +++ b/docs/dates.rst @@ -0,0 +1,327 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +=============== +Date Formatting +=============== + + +When working with date and time information in Python, you commonly use the +classes ``date``, ``datetime`` and/or ``time`` from the `datetime`_ package. +Babel provides functions for locale-specific formatting of those objects in its +``dates`` module: + +.. _`datetime`: http://docs.python.org/lib/module-datetime.html + +.. code-block:: pycon + + >>> from datetime import date, datetime, time + >>> from babel.dates import format_date, format_datetime, format_time + + >>> d = date(2007, 4, 1) + >>> format_date(d, locale='en') + u'Apr 1, 2007' + >>> format_date(d, locale='de_DE') + u'01.04.2007' + +As this example demonstrates, Babel will automatically choose a date format +that is appropriate for the requested locale. + +The ``format_*()`` functions also accept an optional ``format`` argument, which +allows you to choose between one of four format variations: + + * ``short``, + * ``medium`` (the default), + * ``long``, and + * ``full``. + +For example: + +.. code-block:: pycon + + >>> format_date(d, format='short', locale='en') + u'4/1/07' + >>> format_date(d, format='long', locale='en') + u'April 1, 2007' + >>> format_date(d, format='full', locale='en') + u'Sunday, April 1, 2007' + + +Pattern Syntax +============== + +While Babel makes it simple to use the appropriate date/time format for a given +locale, you can also force it to use custom patterns. Note that Babel uses +different patterns for specifying number and date formats compared to the +Python equivalents (such as ``time.strftime()``), which have mostly been +inherited from C and POSIX. The patterns used in Babel are based on the +`Locale Data Markup Language specification`_ (LDML), which defines them as +follows: + + A date/time pattern is a string of characters, where specific strings of + characters are replaced with date and time data from a calendar when formatting + or used to generate data for a calendar when parsing. […] + + Characters may be used multiple times. For example, if ``y`` is used for the + year, ``yy`` might produce "99", whereas ``yyyy`` produces "1999". For most + numerical fields, the number of characters specifies the field width. For + example, if ``h`` is the hour, ``h`` might produce "5", but ``hh`` produces + "05". For some characters, the count specifies whether an abbreviated or full + form should be used […] + + Two single quotes represent a literal single quote, either inside or outside + single quotes. Text within single quotes is not interpreted in any way (except + for two adjacent single quotes). + +For example: + +.. code-block:: pycon + + >>> d = date(2007, 4, 1) + >>> format_date(d, "EEE, MMM d, ''yy", locale='en') + u"Sun, Apr 1, '07" + >>> format_date(d, "EEEE, d.M.yyyy", locale='de') + u'Sonntag, 1.4.2007' + + >>> t = time(15, 30) + >>> format_time(t, "hh 'o''clock' a", locale='en') + u"03 o'clock PM" + >>> format_time(t, 'H:mm a', locale='de') + u'15:30 nachm.' + + >>> dt = datetime(2007, 4, 1, 15, 30) + >>> format_datetime(dt, "yyyyy.MMMM.dd GGG hh:mm a", locale='en') + u'02007.April.01 AD 03:30 PM' + +The syntax for custom datetime format patterns is described in detail in the +the `Locale Data Markup Language specification`_. The following table is just a +relatively brief overview. + + .. _`Locale Data Markup Language specification`: http://unicode.org/reports/tr35/#Date_Format_Patterns + +Date Fields +----------- + + +----------+--------+--------------------------------------------------------+ + | Field | Symbol | Description | + +==========+========+========================================================+ + | Era | ``G`` | Replaced with the era string for the current date. One | + | | | to three letters for the abbreviated form, four | + | | | lettersfor the long form, five for the narrow form | + +----------+--------+--------------------------------------------------------+ + | Year | ``y`` | Replaced by the year. Normally the length specifies | + | | | the padding, but for two letters it also specifies the | + | | | maximum length. | + | +--------+--------------------------------------------------------+ + | | ``Y`` | Same as ``y`` but uses the ISO year-week calendar. | + | +--------+--------------------------------------------------------+ + | | ``u`` | ?? | + +----------+--------+--------------------------------------------------------+ + | Quarter | ``Q`` | Use one or two for the numerical quarter, three for | + | | | the abbreviation, or four for the full name. | + | +--------+--------------------------------------------------------+ + | | ``q`` | Use one or two for the numerical quarter, three for | + | | | the abbreviation, or four for the full name. | + +----------+--------+--------------------------------------------------------+ + | Month | ``M`` | Use one or two for the numerical month, three for the | + | | | abbreviation, or four for the full name, or five for | + | | | the narrow name. | + | +--------+--------------------------------------------------------+ + | | ``L`` | Use one or two for the numerical month, three for the | + | | | abbreviation, or four for the full name, or 5 for the | + | | | narrow name. | + +----------+--------+--------------------------------------------------------+ + | Week | ``w`` | Week of year. | + | +--------+--------------------------------------------------------+ + | | ``W`` | Week of month. | + +----------+--------+--------------------------------------------------------+ + | Day | ``d`` | Day of month. | + | +--------+--------------------------------------------------------+ + | | ``D`` | Day of year. | + | +--------+--------------------------------------------------------+ + | | ``F`` | Day of week in month. | + | +--------+--------------------------------------------------------+ + | | ``g`` | ?? | + +----------+--------+--------------------------------------------------------+ + | Week day | ``E`` | Day of week. Use one through three letters for the | + | | | short day, or four for the full name, or five for the | + | | | narrow name. | + | +--------+--------------------------------------------------------+ + | | ``e`` | Local day of week. Same as E except adds a numeric | + | | | value that will depend on the local starting day of | + | | | the week, using one or two letters. | + | +--------+--------------------------------------------------------+ + | | ``c`` | ?? | + +----------+--------+--------------------------------------------------------+ + +Time Fields +----------- + + +----------+--------+--------------------------------------------------------+ + | Field | Symbol | Description | + +==========+========+========================================================+ + | Period | ``a`` | AM or PM | + +----------+--------+--------------------------------------------------------+ + | Hour | ``h`` | Hour [1-12]. | + | +--------+--------------------------------------------------------+ + | | ``H`` | Hour [0-23]. | + | +--------+--------------------------------------------------------+ + | | ``K`` | Hour [0-11]. | + | +--------+--------------------------------------------------------+ + | | ``k`` | Hour [1-24]. | + +----------+--------+--------------------------------------------------------+ + | Minute | ``m`` | Use one or two for zero places padding. | + +----------+--------+--------------------------------------------------------+ + | Second | ``s`` | Use one or two for zero places padding. | + | +--------+--------------------------------------------------------+ + | | ``S`` | Fractional second, rounds to the count of letters. | + | +--------+--------------------------------------------------------+ + | | ``A`` | Milliseconds in day. | + +----------+--------+--------------------------------------------------------+ + | Timezone | ``z`` | Use one to three letters for the short timezone or | + | | | four for the full name. | + | +--------+--------------------------------------------------------+ + | | ``Z`` | Use one to three letters for RFC 822, four letters for | + | | | GMT format. | + | +--------+--------------------------------------------------------+ + | | ``v`` | Use one letter for short wall (generic) time, four for | + | | | long wall time. | + | +--------+--------------------------------------------------------+ + | | ``V`` | Same as ``z``, except that timezone abbreviations | + | | | should be used regardless of whether they are in | + | | | common use by the locale. | + +----------+--------+--------------------------------------------------------+ + + +Time Delta Formatting +===================== + +In addition to providing functions for formatting localized dates and times, +the ``babel.dates`` module also provides a function to format the difference +between two times, called a ''time delta''. These are usually represented as +``datetime.timedelta`` objects in Python, and it's also what you get when you +subtract one ``datetime`` object from an other. + +The ``format_timedelta`` function takes a ``timedelta`` object and returns a +human-readable representation. This happens at the cost of precision, as it +chooses only the most significant unit (such as year, week, or hour) of the +difference, and displays that: + +.. code-block:: pycon + + >>> from datetime import timedelta + >>> from babel.dates import format_timedelta + >>> delta = timedelta(days=6) + >>> format_timedelta(delta, locale='en_US') + u'1 week' + +The resulting strings are based from the CLDR data, and are properly +pluralized depending on the plural rules of the locale and the calculated +number of units. + +The function provides parameters for you to influence how this most significant +unit is chosen: with ``threshold`` you set the value after which the +presentation switches to the next larger unit, and with ``granularity`` you +can limit the smallest unit to display: + +.. code-block:: pycon + + >>> delta = timedelta(days=6) + >>> format_timedelta(delta, threshold=1.2, locale='en_US') + u'6 days' + >>> format_timedelta(delta, granularity='month', locale='en_US') + u'1 month' + + +Time-zone Support +================= + +Many of the verbose time formats include the time-zone, but time-zone +information is not by default available for the Python ``datetime`` and +``time`` objects. The standard library includes only the abstract ``tzinfo`` +class, which you need appropriate implementations for to actually use in your +application. Babel includes a ``tzinfo`` implementation for UTC (Universal +Time). + +For real time-zone support, it is strongly recommended that you use the +third-party package `pytz`_, which includes the definitions of practically all +of the time-zones used on the world, as well as important functions for +reliably converting from UTC to local time, and vice versa: + +.. code-block:: pycon + + >>> from datetime import time + >>> from pytz import timezone, utc + >>> dt = datetime(2007, 04, 01, 15, 30, tzinfo=utc) + >>> eastern = timezone('US/Eastern') + >>> format_datetime(dt, 'H:mm Z', tzinfo=eastern, locale='en_US') + u'11:30 -0400' + +The recommended approach to deal with different time-zones in a Python +application is to always use UTC internally, and only convert from/to the users +time-zone when accepting user input and displaying date/time data, respectively. +You can use Babel together with ``pytz`` to apply a time-zone to any +``datetime`` or ``time`` object for display, leaving the original information +unchanged: + +.. code-block:: pycon + + >>> british = timezone('Europe/London') + >>> format_datetime(dt, 'H:mm zzzz', tzinfo=british, locale='en_US') + u'16:30 British Summer Time' + +Here, the given UTC time is adjusted to the "Europe/London" time-zone, and +daylight savings time is taken into account. Daylight savings time is also +applied to ``format_time``, but because the actual date is unknown in that +case, the current day is assumed to determine whether DST or standard time +should be used. + + .. _`pytz`: http://pytz.sourceforge.net/ + + +Localized Time-zone Names +------------------------- + +While the ``Locale`` class provides access to various locale display names +related to time-zones, the process of building a localized name of a time-zone +is actually quite complicated. Babel implements it in separately usable +functions in the ``babel.dates`` module, most importantly the +``get_timezone_name`` function: + +.. code-block:: pycon + + >>> from pytz import timezone + >>> from babel import Locale + >>> from babel.dates import get_timezone_name + + >>> tz = timezone('Europe/Berlin') + >>> get_timezone_name(tz, locale=Locale.parse('pt_PT')) + u'Hor\xe1rio Alemanha' + +You can pass the function either a ``datetime.tzinfo`` object, or a +``datetime.date`` or ``datetime.datetime`` object. If you pass an actual date, +the function will be able to take daylight savings time into account. If you +pass just the time-zone, Babel does not know whether daylight savings time is +in effect, so it uses a generic representation, which is useful for example to +display a list of time-zones to the user. + +.. code-block:: pycon + + >>> from datetime import datetime + + >>> dt = tz.localize(datetime(2007, 8, 15)) + >>> get_timezone_name(dt, locale=Locale.parse('de_DE')) + u'Mitteleurop\xe4ische Sommerzeit' + >>> get_timezone_name(tz, locale=Locale.parse('de_DE')) + u'Deutschland' + + +Parsing Dates +============= + +Babel can also parse date and time information in a locale-sensitive manner: + +.. code-block:: pycon + + >>> from babel.dates import parse_date, parse_datetime, parse_time + +.. note:: Date/time parsing is not properly implemented yet diff --git a/docs/display.rst b/docs/display.rst new file mode 100644 index 0000000..1fa3865 --- /dev/null +++ b/docs/display.rst @@ -0,0 +1,79 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +==================== +Locale Display Names +==================== + + +Introduction +============ + +While `message catalogs <messages.html>`_ allow you to localize any messages +in your application, there are a number of strings that are used in many +applications for which translations are readily available. + +Imagine for example you have a list of countries that users can choose from, +and you'd like to display the names of those countries in the language the +user prefers. Instead of translating all those country names yourself in your +application, you can make use of the translations provided by the locale data +included with Babel, which is based on the `Common Locale Data Repository +(CLDR) <http://unicode.org/cldr/>`_ developed and maintained by the `Unicode +Consortium <http://unicode.org/>`_. + + +The ``Locale`` Class +==================== + +You normally access such locale data through the `Locale`_ class provided +by Babel: + +.. code-block:: pycon + + >>> from babel import Locale + >>> locale = Locale('en', 'US') + >>> locale.territories['US'] + u'United States' + >>> locale = Locale('es', 'MX') + >>> locale.territories['US'] + u'Estados Unidos' + +.. _`Locale`: api/babel.core.Locale-class.html + +In addition to country/territory names, the locale data also provides access to +names of languages, scripts, variants, time zones, and more. Some of the data +is closely related to number and date formatting. + +Most of the corresponding ``Locale`` properties return dictionaries, where the +key is a code such as the ISO country and language codes. Consult the API +documentation for references to the relevant specifications. + + +Calender Display Names +====================== + +The `Locale`_ class provides access to many locale display names related to +calendar display, such as the names of week days or months. + +These display names are of course used for date formatting, but can also be +used, for example, to show a list of months to the user in their preferred +language: + +.. code-block:: pycon + + >>> locale = Locale('es') + >>> month_names = locale.months['format']['wide'].items() + >>> month_names.sort() + >>> for idx, name in month_names: + ... print name + enero + febrero + marzo + abril + mayo + junio + julio + agosto + septiembre + octubre + noviembre + diciembre diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..f5e7f65 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,58 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +===== +Babel +===== + +------------------ +User Documentation +------------------ + +Babel is an integrated collection of utilities that assist in +internationalizing and localizing Python applications, with an emphasis on +web-based applications. + +.. toctree:: + :maxdepth: 1 + + intro + display + dates + numbers + messages + cmdline + setup + support + + +----------- +Quick Links +----------- + +* `Frequently asked questions`_ +* `Plugins and extensions for Babel`_ + +.. _Frequently asked questions: http://babel.edgewall.org/wiki/BabelFaq +.. _Plugins and extensions for Babel: http://babel.edgewall.org/wiki/BabelPlugins + +------------- +API Reference +------------- + +.. toctree:: + :maxdepth: 1 + + api/babel.core + api/babel.dates + api/babel.localedata + api/babel.messages + api/babel.messages.catalog + api/babel.messages.checkers + api/babel.messages.extract + api/babel.messages.frontend + api/babel.messages.mofile + api/babel.messages.plurals + api/babel.messages.pofile + api/babel.numbers + api/babel.support + api/babel.util diff --git a/docs/intro.rst b/docs/intro.rst new file mode 100644 index 0000000..0de1a5d --- /dev/null +++ b/docs/intro.rst @@ -0,0 +1,57 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +============ +Introduction +============ + +The functionality Babel provides for internationalization (I18n) and +localization (L10N) can be separated into two different aspects: + + * tools to build and work with ``gettext`` message catalogs, and + * a Python interface to the CLDR (Common Locale Data Repository), providing + access to various locale display names, localized number and date + formatting, etc. + + +Message Catalogs +================ + +While the Python standard library includes a +`gettext <http://docs.python.org/lib/module-gettext.html>`_ module that enables +applications to use message catalogs, it requires developers to build these +catalogs using GNU tools such as ``xgettext``, ``msgmerge``, and ``msgfmt``. +And while ``xgettext`` does have support for extracting messages from Python +files, it does not know how to deal with other kinds of files commonly found +in Python web-applications, such as templates, nor does it provide an easy +extensibility mechanism to add such support. + +Babel addresses this by providing a framework where various extraction methods +can be plugged in to a larger message extraction framework, and also removes +the dependency on the GNU ``gettext`` tools for common tasks, as these aren't +necessarily available on all platforms. See `Working with Message Catalogs`_ +for details on this aspect of Babel. + +.. _`Working with Message Catalogs`: messages.html + + +Locale Data +=========== + +Furthermore, while the Python standard library does include support for basic +localization with respect to the formatting of numbers and dates (the +`locale <http://docs.python.org/lib/module-locale.html>`_ module, among others), +this support is based on the assumption that there will be only one specific +locale used per process (at least simultaneously.) Also, it doesn't provide +access to other kinds of locale data, such as the localized names of countries, +languages, or time-zones, which are frequently needed in web-based applications. + +For these requirements, Babel includes data extracted from the `Common Locale +Data Repository (CLDR) <http://unicode.org/cldr/>`_, and provides a number of +convenient methods for accessing and using this data. See `Locale Display +Names`_, `Date Formatting`_, and `Number Formatting`_ for more information on +this aspect of Babel. + + +.. _`Locale Display Names`: display.html +.. _`Date Formatting`: dates.html +.. _`Number Formatting`: numbers.html diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..5d07f01 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^<target^>` where ^<target^> is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Babel.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Babel.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/docs/messages.rst b/docs/messages.rst new file mode 100644 index 0000000..9f4bfab --- /dev/null +++ b/docs/messages.rst @@ -0,0 +1,312 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +============================= +Working with Message Catalogs +============================= + + +Introduction +============ + +The ``gettext`` translation system enables you to mark any strings used in your +application as subject to localization, by wrapping them in functions such as +``gettext(str)`` and ``ngettext(singular, plural, num)``. For brevity, the +``gettext`` function is often aliased to ``_(str)``, so you can write: + +.. code-block:: python + + print _("Hello") + +instead of just: + +.. code-block:: python + + print "Hello" + +to make the string "Hello" localizable. + +Message catalogs are collections of translations for such localizable messages +used in an application. They are commonly stored in PO (Portable Object) and MO +(Machine Object) files, the formats of which are defined by the GNU `gettext`_ +tools and the GNU `translation project`_. + + .. _`gettext`: http://www.gnu.org/software/gettext/ + .. _`translation project`: http://sourceforge.net/projects/translation + +The general procedure for building message catalogs looks something like this: + + * use a tool (such as ``xgettext``) to extract localizable strings from the + code base and write them to a POT (PO Template) file. + * make a copy of the POT file for a specific locale (for example, "en_US") + and start translating the messages + * use a tool such as ``msgfmt`` to compile the locale PO file into an binary + MO file + * later, when code changes make it necessary to update the translations, you + regenerate the POT file and merge the changes into the various + locale-specific PO files, for example using ``msgmerge`` + +Python provides the `gettext module`_ as part of the standard library, which +enables applications to work with appropriately generated MO files. + + .. _`gettext module`: http://docs.python.org/lib/module-gettext.html + +As ``gettext`` provides a solid and well supported foundation for translating +application messages, Babel does not reinvent the wheel, but rather reuses this +infrastructure, and makes it easier to build message catalogs for Python +applications. + + +Message Extraction +================== + +Babel provides functionality similar to that of the ``xgettext`` program, +except that only extraction from Python source files is built-in, while support +for other file formats can be added using a simple extension mechanism. + +Unlike ``xgettext``, which is usually invoked once for every file, the routines +for message extraction in Babel operate on directories. While the per-file +approach of ``xgettext`` works nicely with projects using a ``Makefile``, +Python projects rarely use ``make``, and thus a different mechanism is needed +for extracting messages from the heterogeneous collection of source files that +many Python projects are composed of. + +When message extraction is based on directories instead of individual files, +there needs to be a way to configure which files should be treated in which +manner. For example, while many projects may contain ``.html`` files, some of +those files may be static HTML files that don't contain localizable message, +while others may be `Django`_ templates, and still others may contain `Genshi`_ +markup templates. Some projects may even mix HTML files for different templates +languages (for whatever reason). Therefore the way in which messages are +extracted from source files can not only depend on the file extension, but +needs to be controllable in a precise manner. + +.. _`Django`: http://www.djangoproject.com/ +.. _`Genshi`: http://genshi.edgewall.org/ + +Babel accepts a configuration file to specify this mapping of files to +extraction methods, which is described below. + + +.. _`frontends`: + +---------- +Front-Ends +---------- + +Babel provides two different front-ends to access its functionality for working +with message catalogs: + + * A `Command-line interface <cmdline.html>`_, and + * `Integration with distutils/setuptools <setup.html>`_ + +Which one you choose depends on the nature of your project. For most modern +Python projects, the distutils/setuptools integration is probably more +convenient. + + +.. _`mapping`: + +------------------------------------------- +Extraction Method Mapping and Configuration +------------------------------------------- + +The mapping of extraction methods to files in Babel is done via a configuration +file. This file maps extended glob patterns to the names of the extraction +methods, and can also set various options for each pattern (which options are +available depends on the specific extraction method). + +For example, the following configuration adds extraction of messages from both +Genshi markup templates and text templates: + +.. code-block:: ini + + # Extraction from Python source files + + [python: **.py] + + # Extraction from Genshi HTML and text templates + + [genshi: **/templates/**.html] + ignore_tags = script,style + include_attrs = alt title summary + + [genshi: **/templates/**.txt] + template_class = genshi.template:TextTemplate + encoding = ISO-8819-15 + + # Extraction from JavaScript files + + [javascript: **.js] + extract_messages = $._, jQuery._ + +The configuration file syntax is based on the format commonly found in ``.INI`` +files on Windows systems, and as supported by the ``ConfigParser`` module in +the Python standard library. Section names (the strings enclosed in square +brackets) specify both the name of the extraction method, and the extended glob +pattern to specify the files that this extraction method should be used for, +separated by a colon. The options in the sections are passed to the extraction +method. Which options are available is specific to the extraction method used. + +The extended glob patterns used in this configuration are similar to the glob +patterns provided by most shells. A single asterisk (``*``) is a wildcard for +any number of characters (except for the pathname component separator "/"), +while a question mark (``?``) only matches a single character. In addition, +two subsequent asterisk characters (``**``) can be used to make the wildcard +match any directory level, so the pattern ``**.txt`` matches any file with the +extension ``.txt`` in any directory. + +Lines that start with a ``#`` or ``;`` character are ignored and can be used +for comments. Empty lines are ignored, too. + +.. note:: if you're performing message extraction using the command Babel + provides for integration into ``setup.py`` scripts, you can also + provide this configuration in a different way, namely as a keyword + argument to the ``setup()`` function. See `Distutils/Setuptools + Integration`_ for more information. + +.. _`distutils/setuptools integration`: setup.html + + +Default Extraction Methods +-------------------------- + +Babel comes with a few builtin extractors: ``python`` (which extracts +messages from Python source files), ``javascript``, and ``ignore`` (which +extracts nothing). + +The ``python`` extractor is by default mapped to the glob pattern ``**.py``, +meaning it'll be applied to all files with the ``.py`` extension in any +directory. If you specify your own mapping configuration, this default mapping +is discarded, so you need to explicitly add it to your mapping (as shown in the +example above.) + + +.. _`referencing extraction methods`: + +Referencing Extraction Methods +------------------------------ + +To be able to use short extraction method names such as “genshi”, you need to +have `pkg_resources`_ installed, and the package implementing that extraction +method needs to have been installed with its meta data (the `egg-info`_). + +If this is not possible for some reason, you need to map the short names to +fully qualified function names in an extract section in the mapping +configuration. For example: + +.. code-block:: ini + + # Some custom extraction method + + [extractors] + custom = mypackage.module:extract_custom + + [custom: **.ctm] + some_option = foo + +Note that the builtin extraction methods ``python`` and ``ignore`` are available +by default, even if `pkg_resources`_ is not installed. You should never need to +explicitly define them in the ``[extractors]`` section. + +.. _`egg-info`: http://peak.telecommunity.com/DevCenter/PythonEggs +.. _`pkg_resources`: http://peak.telecommunity.com/DevCenter/PkgResources + + +-------------------------- +Writing Extraction Methods +-------------------------- + +Adding new methods for extracting localizable methods is easy. First, you'll +need to implement a function that complies with the following interface: + +.. code-block:: python + + def extract_xxx(fileobj, keywords, comment_tags, options): + """Extract messages from XXX files. + + :param fileobj: the file-like object the messages should be extracted + from + :param keywords: a list of keywords (i.e. function names) that should + be recognized as translation functions + :param comment_tags: a list of translator tags to search for and + include in the results + :param options: a dictionary of additional options (optional) + :return: an iterator over ``(lineno, funcname, message, comments)`` + tuples + :rtype: ``iterator`` + """ + +.. note:: Any strings in the tuples produced by this function must be either + ``unicode`` objects, or ``str`` objects using plain ASCII characters. + That means that if sources contain strings using other encodings, it + is the job of the extractor implementation to do the decoding to + ``unicode`` objects. + +Next, you should register that function as an entry point. This requires your +``setup.py`` script to use `setuptools`_, and your package to be installed with +the necessary metadata. If that's taken care of, add something like the +following to your ``setup.py`` script: + +.. code-block:: python + + def setup(... + + entry_points = """ + [babel.extractors] + xxx = your.package:extract_xxx + """, + +That is, add your extraction method to the entry point group +``babel.extractors``, where the name of the entry point is the name that people +will use to reference the extraction method, and the value being the module and +the name of the function (separated by a colon) implementing the actual +extraction. + +.. note:: As shown in `Referencing Extraction Methods`_, declaring an entry + point is not strictly required, as users can still reference the + extraction function directly. But whenever possible, the entry point + should be declared to make configuration more convenient. + +.. _`setuptools`: http://peak.telecommunity.com/DevCenter/setuptools + + +------------------- +Translator Comments +------------------- + +First of all what are comments tags. Comments tags are excerpts of text to +search for in comments, only comments, right before the `python gettext`_ +calls, as shown on the following example: + + .. _`python gettext`: http://docs.python.org/lib/module-gettext.html + +.. code-block:: python + + # NOTE: This is a comment about `Foo Bar` + _('Foo Bar') + +The comments tag for the above example would be ``NOTE:``, and the translator +comment for that tag would be ``This is a comment about `Foo Bar```. + +The resulting output in the catalog template would be something like:: + + #. This is a comment about `Foo Bar` + #: main.py:2 + msgid "Foo Bar" + msgstr "" + +Now, you might ask, why would I need that? + +Consider this simple case; you have a menu item called “manual”. You know what +it means, but when the translator sees this they will wonder did you mean: + +1. a document or help manual, or +2. a manual process? + +This is the simplest case where a translation comment such as +“The installation manual” helps to clarify the situation and makes a translator +more productive. + +.. note:: Whether translator comments can be extracted depends on the extraction + method in use. The Python extractor provided by Babel does implement + this feature, but others may not. diff --git a/docs/numbers.rst b/docs/numbers.rst new file mode 100644 index 0000000..2800472 --- /dev/null +++ b/docs/numbers.rst @@ -0,0 +1,108 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +========================== +Number Formatting +========================== + + +Support for locale-specific formatting and parsing of numbers is provided by +the ``babel.numbers`` module: + +.. code-block:: pycon + + >>> from babel.numbers import format_number, format_decimal, format_percent + +Examples: + +.. code-block:: pycon + + >>> format_decimal(1.2345, locale='en_US') + u'1.234' + >>> format_decimal(1.2345, locale='sv_SE') + u'1,234' + >>> format_decimal(12345, locale='de_DE') + u'12.345' + + +Pattern Syntax +============== + +While Babel makes it simple to use the appropriate number format for a given +locale, you can also force it to use custom patterns. As with date/time +formatting patterns, the patterns Babel supports for number formatting are +based on the `Locale Data Markup Language specification`_ (LDML). + +Examples: + +.. code-block:: pycon + + >>> format_decimal(-1.2345, format='#,##0.##;-#', locale='en') + u'-1.23' + >>> format_decimal(-1.2345, format='#,##0.##;(#)', locale='en') + u'(1.23)' + +The syntax for custom number format patterns is described in detail in the +the specification. The following table is just a relatively brief overview. + + .. _`Locale Data Markup Language specification`: http://unicode.org/reports/tr35/#Number_Format_Patterns + + +----------+-----------------------------------------------------------------+ + | Symbol | Description | + +==========+=================================================================+ + | ``0`` | Digit | + +----------+-----------------------------------------------------------------+ + | ``1-9`` | '1' through '9' indicate rounding. | + +----------+-----------------------------------------------------------------+ + | ``@`` | Significant digit | + +----------+-----------------------------------------------------------------+ + | ``#`` | Digit, zero shows as absent | + +----------+-----------------------------------------------------------------+ + | ``.`` | Decimal separator or monetary decimal separator | + +----------+-----------------------------------------------------------------+ + | ``-`` | Minus sign | + +----------+-----------------------------------------------------------------+ + | ``,`` | Grouping separator | + +----------+-----------------------------------------------------------------+ + | ``E`` | Separates mantissa and exponent in scientific notation | + +----------+-----------------------------------------------------------------+ + | ``+`` | Prefix positive exponents with localized plus sign | + +----------+-----------------------------------------------------------------+ + | ``;`` | Separates positive and negative subpatterns | + +----------+-----------------------------------------------------------------+ + | ``%`` | Multiply by 100 and show as percentage | + +----------+-----------------------------------------------------------------+ + | ``‰`` | Multiply by 1000 and show as per mille | + +----------+-----------------------------------------------------------------+ + | ``¤`` | Currency sign, replaced by currency symbol. If doubled, | + | | replaced by international currency symbol. If tripled, uses the | + | | long form of the decimal symbol. | + +----------+-----------------------------------------------------------------+ + | ``'`` | Used to quote special characters in a prefix or suffix | + +----------+-----------------------------------------------------------------+ + | ``*`` | Pad escape, precedes pad character | + +----------+-----------------------------------------------------------------+ + + +Parsing Numbers +=============== + +Babel can also parse numeric data in a locale-sensitive manner: + +.. code-block:: pycon + + >>> from babel.numbers import parse_decimal, parse_number + +Examples: + +.. code-block:: pycon + + >>> parse_decimal('1,099.98', locale='en_US') + 1099.98 + >>> parse_decimal('1.099,98', locale='de') + 1099.98 + >>> parse_decimal('2,109,998', locale='de') + Traceback (most recent call last): + ... + NumberFormatError: '2,109,998' is not a valid decimal number + +.. note:: Number parsing is not properly implemented yet diff --git a/docs/setup.rst b/docs/setup.rst new file mode 100644 index 0000000..6bb2a02 --- /dev/null +++ b/docs/setup.rst @@ -0,0 +1,337 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +================================ +Distutils/Setuptools Integration +================================ + +Babel provides commands for integration into ``setup.py`` scripts, based on +either the ``distutils`` package that is part of the Python standard library, +or the third-party ``setuptools`` package. + +These commands are available by default when Babel has been properly installed, +and ``setup.py`` is using ``setuptools``. For projects that use plain old +``distutils``, the commands need to be registered explicitly, for example: + +.. code-block:: python + + from distutils.core import setup + from babel.messages import frontend as babel + + setup( + ... + cmdclass = {'compile_catalog': babel.compile_catalog, + 'extract_messages': babel.extract_messages, + 'init_catalog': babel.init_catalog, + 'update_catalog': babel.update_catalog} + ) + + +compile_catalog +=============== + +The ``compile_catalog`` command is similar to the GNU ``msgfmt`` tool, in that +it takes a message catalog from a PO file and compiles it to a binary MO file. + +If the command has been correctly installed or registered, a project's +``setup.py`` script should allow you to use the command:: + + $ ./setup.py compile_catalog --help + Global options: + --verbose (-v) run verbosely (default) + --quiet (-q) run quietly (turns verbosity off) + --dry-run (-n) don't actually do anything + --help (-h) show detailed help message + + Options for 'compile_catalog' command: + ... + +Running the command will produce a binary MO file:: + + $ ./setup.py compile_catalog --directory foobar/locale --locale pt_BR + running compile_catalog + compiling catalog to foobar/locale/pt_BR/LC_MESSAGES/messages.mo + + +Options +------- + +The ``compile_catalog`` command accepts the following options: + + +-----------------------------+---------------------------------------------+ + | Option | Description | + +=============================+=============================================+ + | ``--domain`` | domain of the PO file (defaults to | + | | lower-cased project name) | + +-----------------------------+---------------------------------------------+ + | ``--directory`` (``-d``) | name of the base directory | + +-----------------------------+---------------------------------------------+ + | ``--input-file`` (``-i``) | name of the input file | + +-----------------------------+---------------------------------------------+ + | ``--output-file`` (``-o``) | name of the output file | + +-----------------------------+---------------------------------------------+ + | ``--locale`` (``-l``) | locale for the new localized string | + +-----------------------------+---------------------------------------------+ + | ``--use-fuzzy`` (``-f``) | also include "fuzzy" translations | + +-----------------------------+---------------------------------------------+ + | ``--statistics`` | print statistics about translations | + +-----------------------------+---------------------------------------------+ + +If ``directory`` is specified, but ``output-file`` is not, the default filename +of the output file will be:: + + <directory>/<locale>/LC_MESSAGES/<domain>.mo + +If neither the ``input_file`` nor the ``locale`` option is set, this command +looks for all catalog files in the base directory that match the given domain, +and compiles each of them to MO files in the same directory. + +These options can either be specified on the command-line, or in the +``setup.cfg`` file. + + +extract_messages +================ + +The ``extract_messages`` command is comparable to the GNU ``xgettext`` program: +it can extract localizable messages from a variety of difference source files, +and generate a PO (portable object) template file from the collected messages. + +If the command has been correctly installed or registered, a project's +``setup.py`` script should allow you to use the command:: + + $ ./setup.py extract_messages --help + Global options: + --verbose (-v) run verbosely (default) + --quiet (-q) run quietly (turns verbosity off) + --dry-run (-n) don't actually do anything + --help (-h) show detailed help message + + Options for 'extract_messages' command: + ... + +Running the command will produce a PO template file:: + + $ ./setup.py extract_messages --output-file foobar/locale/messages.pot + running extract_messages + extracting messages from foobar/__init__.py + extracting messages from foobar/core.py + ... + writing PO template file to foobar/locale/messages.pot + + +Method Mapping +-------------- + +The mapping of file patterns to extraction methods (and options) can be +specified using a configuration file that is pointed to using the +``--mapping-file`` option shown above. Alternatively, you can configure the +mapping directly in ``setup.py`` using a keyword argument to the ``setup()`` +function: + +.. code-block:: python + + setup(... + + message_extractors = { + 'foobar': [ + ('**.py', 'python', None), + ('**/templates/**.html', 'genshi', None), + ('**/templates/**.txt', 'genshi', { + 'template_class': 'genshi.template:TextTemplate' + }) + ], + }, + + ... + ) + + +Options +------- + +The ``extract_messages`` command accepts the following options: + + +-----------------------------+----------------------------------------------+ + | Option | Description | + +=============================+==============================================+ + | ``--charset`` | charset to use in the output file | + +-----------------------------+----------------------------------------------+ + | ``--keywords`` (``-k``) | space-separated list of keywords to look for | + | | in addition to the defaults | + +-----------------------------+----------------------------------------------+ + | ``--no-default-keywords`` | do not include the default keywords | + +-----------------------------+----------------------------------------------+ + | ``--mapping-file`` (``-F``) | path to the mapping configuration file | + +-----------------------------+----------------------------------------------+ + | ``--no-location`` | do not include location comments with | + | | filename and line number | + +-----------------------------+----------------------------------------------+ + | ``--omit-header`` | do not include msgid "" entry in header | + +-----------------------------+----------------------------------------------+ + | ``--output-file`` (``-o``) | name of the output file | + +-----------------------------+----------------------------------------------+ + | ``--width`` (``-w``) | set output line width (default 76) | + +-----------------------------+----------------------------------------------+ + | ``--no-wrap`` | do not break long message lines, longer than | + | | the output line width, into several lines | + +-----------------------------+----------------------------------------------+ + | ``--input-dirs`` | directories that should be scanned for | + | | messages | + +-----------------------------+----------------------------------------------+ + | ``--sort-output`` | generate sorted output (default False) | + +-----------------------------+----------------------------------------------+ + | ``--sort-by-file`` | sort output by file location (default False) | + +-----------------------------+----------------------------------------------+ + | ``--msgid-bugs-address`` | set email address for message bug reports | + +-----------------------------+----------------------------------------------+ + | ``--copyright-holder`` | set copyright holder in output | + +-----------------------------+----------------------------------------------+ + | ``--add-comments (-c)`` | place comment block with TAG (or those | + | | preceding keyword lines) in output file. | + | | Separate multiple TAGs with commas(,) | + +-----------------------------+----------------------------------------------+ + +These options can either be specified on the command-line, or in the +``setup.cfg`` file. In the latter case, the options above become entries of the +section ``[extract_messages]``, and the option names are changed to use +underscore characters instead of dashes, for example: + +.. code-block:: ini + + [extract_messages] + keywords = _ gettext ngettext + mapping_file = babel.cfg + width = 80 + +This would be equivalent to invoking the command from the command-line as +follows:: + + $ setup.py extract_messages -k _ -k gettext -k ngettext -F mapping.cfg -w 80 + +Any path names are interpreted relative to the location of the ``setup.py`` +file. For boolean options, use "true" or "false" values. + + +init_catalog +============ + +The ``init_catalog`` command is basically equivalent to the GNU ``msginit`` +program: it creates a new translation catalog based on a PO template file (POT). + +If the command has been correctly installed or registered, a project's +``setup.py`` script should allow you to use the command:: + + $ ./setup.py init_catalog --help + Global options: + --verbose (-v) run verbosely (default) + --quiet (-q) run quietly (turns verbosity off) + --dry-run (-n) don't actually do anything + --help (-h) show detailed help message + + Options for 'init_catalog' command: + ... + +Running the command will produce a PO file:: + + $ ./setup.py init_catalog -l fr -i foobar/locales/messages.pot \ + -o foobar/locales/fr/messages.po + running init_catalog + creating catalog 'foobar/locales/fr/messages.po' based on 'foobar/locales/messages.pot' + + +Options +------- + +The ``init_catalog`` command accepts the following options: + + +-----------------------------+---------------------------------------------+ + | Option | Description | + +=============================+=============================================+ + | ``--domain`` | domain of the PO file (defaults to | + | | lower-cased project name) | + +-----------------------------+---------------------------------------------+ + | ``--input-file`` (``-i``) | name of the input file | + +-----------------------------+---------------------------------------------+ + | ``--output-dir`` (``-d``) | name of the output directory | + +-----------------------------+---------------------------------------------+ + | ``--output-file`` (``-o``) | name of the output file | + +-----------------------------+---------------------------------------------+ + | ``--locale`` | locale for the new localized string | + +-----------------------------+---------------------------------------------+ + +If ``output-dir`` is specified, but ``output-file`` is not, the default filename +of the output file will be:: + + <output_dir>/<locale>/LC_MESSAGES/<domain>.po + +These options can either be specified on the command-line, or in the +``setup.cfg`` file. + + +update_catalog +============== + +The ``update_catalog`` command is basically equivalent to the GNU ``msgmerge`` +program: it updates an existing translations catalog based on a PO template +file (POT). + +If the command has been correctly installed or registered, a project's +``setup.py`` script should allow you to use the command:: + + $ ./setup.py update_catalog --help + Global options: + --verbose (-v) run verbosely (default) + --quiet (-q) run quietly (turns verbosity off) + --dry-run (-n) don't actually do anything + --help (-h) show detailed help message + + Options for 'update_catalog' command: + ... + +Running the command will update a PO file:: + + $ ./setup.py update_catalog -l fr -i foobar/locales/messages.pot \ + -o foobar/locales/fr/messages.po + running update_catalog + updating catalog 'foobar/locales/fr/messages.po' based on 'foobar/locales/messages.pot' + + +Options +------- + +The ``update_catalog`` command accepts the following options: + + +-------------------------------------+-------------------------------------+ + | Option | Description | + +=====================================+=====================================+ + | ``--domain`` | domain of the PO file (defaults to | + | | lower-cased project name) | + +-------------------------------------+-------------------------------------+ + | ``--input-file`` (``-i``) | name of the input file | + +-------------------------------------+-------------------------------------+ + | ``--output-dir`` (``-d``) | name of the output directory | + +-------------------------------------+-------------------------------------+ + | ``--output-file`` (``-o``) | name of the output file | + +-------------------------------------+-------------------------------------+ + | ``--locale`` | locale for the new localized string | + +-------------------------------------+-------------------------------------+ + | ``--ignore-obsolete`` | do not include obsolete messages in | + | | the output | + +-------------------------------------+-------------------------------------+ + | ``--no-fuzzy-matching`` (``-N``) | do not use fuzzy matching | + +-------------------------------------+-------------------------------------+ + | ``--previous`` | keep previous msgids of translated | + | | messages | + +-------------------------------------+-------------------------------------+ + +If ``output-dir`` is specified, but ``output-file`` is not, the default filename +of the output file will be:: + + <output_dir>/<locale>/LC_MESSAGES/<domain>.po + +If neither the ``input_file`` nor the ``locale`` option is set, this command +looks for all catalog files in the base directory that match the given domain, +and updates each of them. + +These options can either be specified on the command-line, or in the +``setup.cfg`` file. diff --git a/docs/support.rst b/docs/support.rst new file mode 100644 index 0000000..baafc54 --- /dev/null +++ b/docs/support.rst @@ -0,0 +1,43 @@ +.. -*- mode: rst; encoding: utf-8 -*- + +============================= +Support Classes and Functions +============================= + +The ``babel.support`` modules contains a number of classes and functions that +can help with integrating Babel, and internationalization in general, into your +application or framework. The code in this module is not used by Babel itself, +but instead is provided to address common requirements of applications that +should handle internationalization. + + +--------------- +Lazy Evaluation +--------------- + +One such requirement is lazy evaluation of translations. Many web-based +applications define some localizable message at the module level, or in general +at some level where the locale of the remote user is not yet known. For such +cases, web frameworks generally provide a "lazy" variant of the ``gettext`` +functions, which basically translates the message not when the ``gettext`` +function is invoked, but when the string is accessed in some manner. + + +--------------------------- +Extended Translations Class +--------------------------- + +Many web-based applications are composed of a variety of different components +(possibly using some kind of plugin system), and some of those components may +provide their own message catalogs that need to be integrated into the larger +system. + +To support this usage pattern, Babel provides a ``Translations`` class that is +derived from the ``GNUTranslations`` class in the ``gettext`` module. This +class adds a ``merge()`` method that takes another ``Translations`` instance, +and merges the content of the latter into the main catalog: + +.. code-block:: python + + translations = Translations.load('main') + translations.merge(Translations.load('plugin1')) |