add default language configuration
This commit is contained in:
parent
571bec6363
commit
9f65eae024
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -22,3 +22,4 @@ cps/static/[0-9]*
|
||||||
.idea/
|
.idea/
|
||||||
*.bak
|
*.bak
|
||||||
*.log.*
|
*.log.*
|
||||||
|
tags
|
||||||
|
|
|
@ -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())
|
APP_DB_ROOT = check_setting_str(CFG, 'General', 'APP_DB_ROOT', os.getcwd())
|
||||||
MAIN_DIR = check_setting_str(CFG, 'General', 'MAIN_DIR', os.getcwd())
|
MAIN_DIR = check_setting_str(CFG, 'General', 'MAIN_DIR', os.getcwd())
|
||||||
LOG_DIR = check_setting_str(CFG, 'General', 'LOG_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)
|
NEWEST_BOOKS = check_setting_str(CFG, 'General', 'NEWEST_BOOKS', 60)
|
||||||
RANDOM_BOOKS = check_setting_int(CFG, 'General', 'RANDOM_BOOKS', 4)
|
RANDOM_BOOKS = check_setting_int(CFG, 'General', 'RANDOM_BOOKS', 4)
|
||||||
|
DEFAULT_LANG = check_setting_str(CFG, 'General', 'DEFAULT_LANG', "")
|
||||||
|
|
||||||
CheckSection('Advanced')
|
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+')
|
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,
|
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,
|
"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):
|
def save_config(configval):
|
||||||
|
@ -85,6 +86,7 @@ def save_config(configval):
|
||||||
new_config['General']['LOG_DIR'] = configval["LOG_DIR"]
|
new_config['General']['LOG_DIR'] = configval["LOG_DIR"]
|
||||||
new_config['General']['PORT'] = configval["PORT"]
|
new_config['General']['PORT'] = configval["PORT"]
|
||||||
new_config['General']['NEWEST_BOOKS'] = configval["NEWEST_BOOKS"]
|
new_config['General']['NEWEST_BOOKS'] = configval["NEWEST_BOOKS"]
|
||||||
|
new_config['General']['DEFAULT_LANG'] = configval["DEFAULT_LANG"]
|
||||||
new_config['Advanced'] = {}
|
new_config['Advanced'] = {}
|
||||||
new_config['Advanced']['TITLE_REGEX'] = configval["TITLE_REGEX"]
|
new_config['Advanced']['TITLE_REGEX'] = configval["TITLE_REGEX"]
|
||||||
new_config['Advanced']['DEVELOPMENT'] = int(configval["DEVELOPMENT"])
|
new_config['Advanced']['DEVELOPMENT'] = int(configval["DEVELOPMENT"])
|
||||||
|
|
|
@ -165,7 +165,8 @@ LANGUAGES = {
|
||||||
'en': 'English',
|
'en': 'English',
|
||||||
'de': 'Deutsch',
|
'de': 'Deutsch',
|
||||||
'fr': 'Français',
|
'fr': 'Français',
|
||||||
'es': 'Español'
|
'es': 'Español',
|
||||||
|
'zh_Hans_CN': '简体中文'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,9 +174,14 @@ LANGUAGES = {
|
||||||
def get_locale():
|
def get_locale():
|
||||||
# if a user is logged in, use the locale from the user settings
|
# if a user is logged in, use the locale from the user settings
|
||||||
user = getattr(g, 'user', None)
|
user = getattr(g, 'user', None)
|
||||||
|
translations = babel.list_translations() + [LC('en')]
|
||||||
if user is not None and hasattr(user, "locale"):
|
if user is not None and hasattr(user, "locale"):
|
||||||
|
if user.locale == 'zh':
|
||||||
|
return 'zh_Hans_CN'
|
||||||
return user.locale
|
return user.locale
|
||||||
preferred = [x.replace('-', '_') for x in request.accept_languages.values()]
|
preferred = [x.replace('-', '_') for x in request.accept_languages.values()]
|
||||||
|
if config.DEFAULT_LANG:
|
||||||
|
return config.DEFAULT_LANG
|
||||||
return negotiate_locale(preferred, LANGUAGES.keys())
|
return negotiate_locale(preferred, LANGUAGES.keys())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user