| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 4 | # This is an app-specific example router |
|---|
| 5 | # |
|---|
| 6 | # This simple router is used for setting languages from app/languages directory |
|---|
| 7 | # as a part of the application path: app/<lang>/controller/function |
|---|
| 8 | # Language from default.py or 'en' (if the file is not found) is used as |
|---|
| 9 | # a default_language |
|---|
| 10 | # |
|---|
| 11 | # See <web2py-root-dir>/examples/routes.parametric.example.py for parameter's detail |
|---|
| 12 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 13 | |
|---|
| 14 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 15 | # To enable this route file you must do the steps: |
|---|
| 16 | # 1. rename <web2py-root-dir>/examples/routes.parametric.example.py to routes.py |
|---|
| 17 | # 2. rename this APP/routes.example.py to APP/routes.py (where APP - is your application directory) |
|---|
| 18 | # 3. restart web2py (or reload routes in web2py admin interface) |
|---|
| 19 | # |
|---|
| 20 | # YOU CAN COPY THIS FILE TO ANY APPLICATION'S ROOT DIRECTORY WITHOUT CHANGES! |
|---|
| 21 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 22 | |
|---|
| 23 | from gluon.fileutils import abspath |
|---|
| 24 | from gluon.languages import read_possible_languages |
|---|
| 25 | |
|---|
| 26 | possible_languages = read_possible_languages(abspath('applications', app)) |
|---|
| 27 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 28 | # NOTE! app - is an application based router's parameter with name of an application. E.g.'welcome' |
|---|
| 29 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 30 | |
|---|
| 31 | routers = { |
|---|
| 32 | app: dict( |
|---|
| 33 | default_language=possible_languages['default'][0], |
|---|
| 34 | languages=[lang for lang in possible_languages if lang != 'default'] |
|---|
| 35 | ) |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 39 | # NOTE! To change language in your application using these rules add this line in one of your models files: |
|---|
| 40 | # ---------------------------------------------------------------------------------------------------------------------- |
|---|
| 41 | # if request.uri_language: T.force(request.uri_language) |
|---|