@@ -70,14 +70,17 @@ def get_platform_names(translations):
7070# Create platform name translation mappings
7171PLATFORM_NAMES = get_platform_names (TRANSLATIONS )
7272
73- # Try to detect system language
73+ # Try to detect system language using newer APIs to avoid deprecation warning
7474try :
75- system_locale , _ = locale .getdefaultlocale ()
76- default_lang = "zh" if system_locale and system_locale .startswith ("zh" ) else "en"
75+ # Use setlocale() to get current locale and then getlocale()
76+ current_locale = locale .setlocale (locale .LC_ALL , '' )
77+ # Check if the locale contains a language code we can use
78+ default_lang = "zh" if current_locale and current_locale .startswith (("zh" , "Chinese" )) else "en"
79+
7780 if default_lang not in TRANSLATIONS :
7881 default_lang = "en" # Fallback to English if the detected language is not supported
79- except :
80- default_lang = "en"
82+ except Exception :
83+ default_lang = "en" # Default to English on error
8184
8285# Check environment variables for each API
8386available_apis = []
@@ -483,11 +486,15 @@ def update_visibility(platform, zhipu_model):
483486 outputs = [video_output , status_output , image_file , prompt ]
484487 )
485488
486- # Initialize UI with default language
487- demo .load (fn = update_ui_language , inputs = current_lang , outputs = [
488- page_title , subtitle , platform , aliyun_model , zhipu_model , prompt , image_file ,
489- ark_ratio , ark_duration , bailian_size , zhipu_quality , zhipu_audio , zhipu_size ,
490- zhipu_fps , submit_btn , clear_btn , video_output , status_output
491- ])
489+ # Initialize UI with default language within the Blocks context
490+ demo .load (
491+ fn = update_ui_language ,
492+ inputs = current_lang ,
493+ outputs = [
494+ page_title , subtitle , platform , aliyun_model , zhipu_model , prompt , image_file ,
495+ ark_ratio , ark_duration , bailian_size , zhipu_quality , zhipu_audio , zhipu_size ,
496+ zhipu_fps , submit_btn , clear_btn , video_output , status_output
497+ ]
498+ )
492499
493500demo .launch (server_name = "0.0.0.0" )
0 commit comments