aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/__init__.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-03-22 14:17:23 -0500
committerAstounds <kirito@disroot.org>2026-03-22 14:17:23 -0500
commit84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759 (patch)
treea4021823e3e29d1efb57271dda5024825983bacf /youtube/__init__.py
parented4b05d9b616c688afc6ef03dc404009c4abfc0f (diff)
downloadyt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.lz
yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.xz
yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.zip
yt-dlp
Diffstat (limited to 'youtube/__init__.py')
-rw-r--r--youtube/__init__.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/youtube/__init__.py b/youtube/__init__.py
index 0072f74..d52ea98 100644
--- a/youtube/__init__.py
+++ b/youtube/__init__.py
@@ -7,12 +7,36 @@ import settings
import traceback
import re
from sys import exc_info
+from flask_babel import Babel
+
yt_app = flask.Flask(__name__)
yt_app.config['TEMPLATES_AUTO_RELOAD'] = True
yt_app.url_map.strict_slashes = False
# yt_app.jinja_env.trim_blocks = True
# yt_app.jinja_env.lstrip_blocks = True
+# Configure Babel for i18n
+import os
+yt_app.config['BABEL_DEFAULT_LOCALE'] = 'en'
+# Use absolute path for translations directory to avoid issues with package structure changes
+_app_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+yt_app.config['BABEL_TRANSLATION_DIRECTORIES'] = os.path.join(_app_root, 'translations')
+
+def get_locale():
+ """Determine the best locale based on user preference or browser settings"""
+ # Check if user has a language preference in settings
+ if hasattr(settings, 'language') and settings.language:
+ locale = settings.language
+ print(f'[i18n] Using user preference: {locale}')
+ return locale
+ # Otherwise, use browser's Accept-Language header
+ # Only match languages with available translations
+ locale = request.accept_languages.best_match(['en', 'es'])
+ print(f'[i18n] Using browser language: {locale}')
+ return locale or 'en'
+
+babel = Babel(yt_app, locale_selector=get_locale)
+
yt_app.add_url_rule('/settings', 'settings_page', settings.settings_page, methods=['POST', 'GET'])