diff --git a/.gitignore b/.gitignore index 16abdd7a..4ed21c61 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ cps/static/[0-9]* .idea/ *.bak *.log.* +tags diff --git a/cps/config.py b/cps/config.py index ec3fbd9a..dd34ffef 100755 --- a/cps/config.py +++ b/cps/config.py @@ -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"]) diff --git a/cps/web.py b/cps/web.py index 281173e5..95fdab1f 100755 --- a/cps/web.py +++ b/cps/web.py @@ -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())