mirror of
https://github.com/pretix/pretix.git
synced 2026-05-11 16:13:59 +00:00
Added examples to i18n documentation, run doctests
This commit is contained in:
@@ -1,28 +1,12 @@
|
|||||||
before_script:
|
before_script:
|
||||||
tests:
|
tests:
|
||||||
|
stage: test
|
||||||
script:
|
script:
|
||||||
- git submodule init
|
|
||||||
- git submodule update
|
|
||||||
- virtualenv-3.4 env
|
- virtualenv-3.4 env
|
||||||
- source env/bin/activate
|
- source env/bin/activate
|
||||||
- cd src
|
- pip install -U pip wheel setuptools
|
||||||
- XDG_CACHE_HOME=/cache pip3 install -r requirements.txt -r requirements/dev.txt -r requirements/py34.txt
|
- XDG_CACHE_HOME=/cache bash .travis.sh style
|
||||||
- flake8 --ignore=E123,F403,F401,N802,C901,W503 .
|
- XDG_CACHE_HOME=/cache bash .travis.sh tests
|
||||||
- isort -c -rc .
|
- XDG_CACHE_HOME=/cache bash .travis.sh doctests
|
||||||
- python3 manage.py check
|
|
||||||
- make
|
|
||||||
- make compress
|
|
||||||
- coverage run -m py.test tests
|
|
||||||
tags:
|
tags:
|
||||||
- python3
|
- 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"
|
- "3.4"
|
||||||
install:
|
install:
|
||||||
- pip install -U pip wheel setuptools
|
- 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:
|
script:
|
||||||
- flake8 --ignore=E123,F403,F401,N802,C901,W503,E402 .
|
- bash .travis.sh $JOB
|
||||||
- isort -c -rc .
|
|
||||||
- python manage.py check
|
|
||||||
- make
|
|
||||||
- make compress
|
|
||||||
- coverage run -m py.test tests
|
|
||||||
after_success:
|
|
||||||
- coveralls
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.cache/pip
|
- $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
|
.. autoclass:: pretix.base.i18n.LazyI18nString
|
||||||
:members: __init__, localize, __str__
|
: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
|
Forms
|
||||||
-----
|
-----
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pep8-naming
|
|||||||
flake8
|
flake8
|
||||||
coveralls
|
coveralls
|
||||||
coverage
|
coverage
|
||||||
pytest
|
pytest==2.9.*
|
||||||
pytest-django
|
pytest-django
|
||||||
isort
|
isort
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
|||||||
Reference in New Issue
Block a user