mirror of
https://github.com/pretix/pretix.git
synced 2026-05-13 16:33:59 +00:00
Added examples to i18n documentation, run doctests
This commit is contained in:
@@ -1,28 +1,12 @@
|
||||
before_script:
|
||||
tests:
|
||||
stage: test
|
||||
script:
|
||||
- git submodule init
|
||||
- git submodule update
|
||||
- virtualenv-3.4 env
|
||||
- source env/bin/activate
|
||||
- cd src
|
||||
- XDG_CACHE_HOME=/cache pip3 install -r requirements.txt -r requirements/dev.txt -r requirements/py34.txt
|
||||
- flake8 --ignore=E123,F403,F401,N802,C901,W503 .
|
||||
- isort -c -rc .
|
||||
- python3 manage.py check
|
||||
- make
|
||||
- make compress
|
||||
- coverage run -m py.test tests
|
||||
- pip install -U pip wheel setuptools
|
||||
- XDG_CACHE_HOME=/cache bash .travis.sh style
|
||||
- XDG_CACHE_HOME=/cache bash .travis.sh tests
|
||||
- XDG_CACHE_HOME=/cache bash .travis.sh doctests
|
||||
tags:
|
||||
- python3
|
||||
- selenium
|
||||
build:
|
||||
type: deploy
|
||||
script:
|
||||
- cd deployment/docker/standalone/
|
||||
- docker login -u ciuser -p $DOCKERPW -e admin@rami.io docker.rami.io
|
||||
- docker build -t pretix/standalone .
|
||||
- docker tag -f pretix/standalone docker.rami.io/pretix/standalone:$CI_BUILD_REF_NAME
|
||||
- docker push docker.rami.io/pretix/standalone:$CI_BUILD_REF_NAME
|
||||
tags:
|
||||
- docker
|
||||
|
||||
31
.travis.sh
Executable file
31
.travis.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -x
|
||||
|
||||
echo "Executing job $1"
|
||||
|
||||
if [ "$1" == "style" ]; then
|
||||
XDG_CACHE_HOME=/cache pip3 install -Ur src/requirements.txt -r src/requirements/dev.txt -r src/requirements/py34.txt
|
||||
cd src
|
||||
flake8 --ignore=E123,F403,F401,N802,C901,W503,E402 .
|
||||
isort -c -rc .
|
||||
fi
|
||||
if [ "$1" == "doctests" ]; then
|
||||
XDG_CACHE_HOME=/cache pip3 install -Ur doc/requirements.txt -r src/requirements/py34.txt
|
||||
cd doc
|
||||
make doctest
|
||||
fi
|
||||
if [ "$1" == "tests" ]; then
|
||||
pip3 install -r src/requirements.txt -Ur src/requirements/dev.txt -r src/requirements/py34.txt
|
||||
cd src
|
||||
python manage.py check
|
||||
make all compress
|
||||
coverage run -m py.test tests && coverage report
|
||||
fi
|
||||
if [ "$1" == "tests-cov" ]; then
|
||||
pip3 install -r src/requirements.txt -Ur src/requirements/dev.txt -r src/requirements/py34.txt
|
||||
cd src
|
||||
python manage.py check
|
||||
make all compress
|
||||
coverage run -m py.test tests && coveralls
|
||||
fi
|
||||
16
.travis.yml
16
.travis.yml
@@ -4,18 +4,12 @@ python:
|
||||
- "3.4"
|
||||
install:
|
||||
- pip install -U pip wheel setuptools
|
||||
- pip install -q -U -r src/requirements.txt -r src/requirements/dev.txt -r src/requirements/py34.txt
|
||||
before_script:
|
||||
- cd src
|
||||
script:
|
||||
- flake8 --ignore=E123,F403,F401,N802,C901,W503,E402 .
|
||||
- isort -c -rc .
|
||||
- python manage.py check
|
||||
- make
|
||||
- make compress
|
||||
- coverage run -m py.test tests
|
||||
after_success:
|
||||
- coveralls
|
||||
- bash .travis.sh $JOB
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/pip
|
||||
env:
|
||||
- JOB=style
|
||||
- JOB=doctests
|
||||
- JOB=tests-cov
|
||||
|
||||
@@ -29,6 +29,73 @@ Whenever you interact with those fields, you will either provide or receive an i
|
||||
.. autoclass:: pretix.base.i18n.LazyI18nString
|
||||
:members: __init__, localize, __str__
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
The following examples are given to illustrate how you can work with ``LazyI18nString``.
|
||||
|
||||
.. testsetup:: *
|
||||
|
||||
from pretix.base.i18n import LazyI18nString, language
|
||||
|
||||
To create a LazyI18nString, we can cast a simple string:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> naive = LazyI18nString('Naive untranslated string')
|
||||
>>> naive
|
||||
<LazyI18nString: 'Naive untranslated string'>
|
||||
|
||||
Or we can provide a dictionary with multiple translations:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> translated = LazyI18nString({'en': 'English String', 'de': 'Deutscher String'})
|
||||
|
||||
We can use ``localize`` to get the string in a specific language:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> translated.localize('de')
|
||||
'Deutscher String'
|
||||
|
||||
>>> translated.localize('en')
|
||||
'English String'
|
||||
|
||||
If we try a locale that does not exist for the string, we might get a it either in a similar locale or in the system's default language:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> translated.localize('de-AT')
|
||||
'Deutscher String'
|
||||
|
||||
>>> translated.localize('zh')
|
||||
'English String'
|
||||
|
||||
>>> naive.localize('de')
|
||||
'Naive untranslated string'
|
||||
|
||||
If we cast a ``LazyI18nString`` to ``str``, ``localize`` will be called with the currently active language:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> from django.utils import translation
|
||||
>>> str(translated)
|
||||
'English String'
|
||||
>>> translation.activate('de')
|
||||
>>> str(translated)
|
||||
'Deutscher String'
|
||||
|
||||
You can also use our handy context manager to set the locale temporarily:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> translation.activate('en')
|
||||
>>> with language('de'):
|
||||
... str(translated)
|
||||
'Deutscher String'
|
||||
>>> str(translated)
|
||||
'English String'
|
||||
|
||||
Forms
|
||||
-----
|
||||
|
||||
@@ -7,7 +7,7 @@ pep8-naming
|
||||
flake8
|
||||
coveralls
|
||||
coverage
|
||||
pytest
|
||||
pytest==2.9.*
|
||||
pytest-django
|
||||
isort
|
||||
pytest-mock
|
||||
|
||||
Reference in New Issue
Block a user