Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
9f65eae0
Commit
9f65eae0
authored
Jan 09, 2017
by
idalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add default language configuration
parent
571bec63
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
.gitignore
.gitignore
+1
-0
config.py
cps/config.py
+4
-2
web.py
cps/web.py
+7
-1
No files found.
.gitignore
View file @
9f65eae0
...
...
@@ -22,3 +22,4 @@ cps/static/[0-9]*
.idea/
*.bak
*.log.*
tags
cps/config.py
View file @
9f65eae0
...
...
@@ -53,9 +53,10 @@ DB_ROOT = check_setting_str(CFG, 'General', 'DB_ROOT', "")
APP_DB_ROOT
=
check_setting_str
(
CFG
,
'General'
,
'APP_DB_ROOT'
,
os
.
getcwd
())
MAIN_DIR
=
check_setting_str
(
CFG
,
'General'
,
'MAIN_DIR'
,
os
.
getcwd
())
LOG_DIR
=
check_setting_str
(
CFG
,
'General'
,
'LOG_DIR'
,
os
.
getcwd
())
PORT
=
check_setting_int
(
CFG
,
'General'
,
'PORT'
,
8083
)
PORT
=
check_setting_int
(
CFG
,
'General'
,
'PORT'
,
8083
)
NEWEST_BOOKS
=
check_setting_str
(
CFG
,
'General'
,
'NEWEST_BOOKS'
,
60
)
RANDOM_BOOKS
=
check_setting_int
(
CFG
,
'General'
,
'RANDOM_BOOKS'
,
4
)
DEFAULT_LANG
=
check_setting_str
(
CFG
,
'General'
,
'DEFAULT_LANG'
,
""
)
CheckSection
(
'Advanced'
)
TITLE_REGEX
=
check_setting_str
(
CFG
,
'Advanced'
,
'TITLE_REGEX'
,
'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)
\
s+'
)
...
...
@@ -72,7 +73,7 @@ if DB_ROOT == "":
configval
=
{
"DB_ROOT"
:
DB_ROOT
,
"APP_DB_ROOT"
:
APP_DB_ROOT
,
"MAIN_DIR"
:
MAIN_DIR
,
"LOG_DIR"
:
LOG_DIR
,
"PORT"
:
PORT
,
"NEWEST_BOOKS"
:
NEWEST_BOOKS
,
"DEVELOPMENT"
:
DEVELOPMENT
,
"TITLE_REGEX"
:
TITLE_REGEX
,
"PUBLIC_REG"
:
PUBLIC_REG
,
"UPLOADING"
:
UPLOADING
,
"ANON_BROWSE"
:
ANON_BROWSE
}
"PUBLIC_REG"
:
PUBLIC_REG
,
"UPLOADING"
:
UPLOADING
,
"ANON_BROWSE"
:
ANON_BROWSE
,
"DEFAULT_LANG"
:
DEFAULT_LANG
}
def
save_config
(
configval
):
...
...
@@ -85,6 +86,7 @@ def save_config(configval):
new_config
[
'General'
][
'LOG_DIR'
]
=
configval
[
"LOG_DIR"
]
new_config
[
'General'
][
'PORT'
]
=
configval
[
"PORT"
]
new_config
[
'General'
][
'NEWEST_BOOKS'
]
=
configval
[
"NEWEST_BOOKS"
]
new_config
[
'General'
][
'DEFAULT_LANG'
]
=
configval
[
"DEFAULT_LANG"
]
new_config
[
'Advanced'
]
=
{}
new_config
[
'Advanced'
][
'TITLE_REGEX'
]
=
configval
[
"TITLE_REGEX"
]
new_config
[
'Advanced'
][
'DEVELOPMENT'
]
=
int
(
configval
[
"DEVELOPMENT"
])
...
...
cps/web.py
View file @
9f65eae0
...
...
@@ -165,7 +165,8 @@ LANGUAGES = {
'en'
:
'English'
,
'de'
:
'Deutsch'
,
'fr'
:
'Français'
,
'es'
:
'Español'
'es'
:
'Español'
,
'zh_Hans_CN'
:
'简体中文'
}
...
...
@@ -173,9 +174,14 @@ LANGUAGES = {
def
get_locale
():
# if a user is logged in, use the locale from the user settings
user
=
getattr
(
g
,
'user'
,
None
)
translations
=
babel
.
list_translations
()
+
[
LC
(
'en'
)]
if
user
is
not
None
and
hasattr
(
user
,
"locale"
):
if
user
.
locale
==
'zh'
:
return
'zh_Hans_CN'
return
user
.
locale
preferred
=
[
x
.
replace
(
'-'
,
'_'
)
for
x
in
request
.
accept_languages
.
values
()]
if
config
.
DEFAULT_LANG
:
return
config
.
DEFAULT_LANG
return
negotiate_locale
(
preferred
,
LANGUAGES
.
keys
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment