Spaces:
Runtime error
Runtime error
import os | |
import json | |
from uuid import uuid4 | |
def get_system_locale(): | |
"""Get system locale with fallback""" | |
return "zh-CN" | |
def load_locales(i18n_dir): | |
"""Minimal locale loading""" | |
try: | |
zh_file = os.path.join(i18n_dir, "zh.json") | |
if os.path.exists(zh_file): | |
with open(zh_file, 'r', encoding='utf-8') as f: | |
zh_data = json.load(f) | |
return {"zh-CN": zh_data} | |
except Exception: | |
pass | |
# Fallback minimal translations | |
return { | |
"zh-CN": { | |
"Language": "中文", | |
"Translation": { | |
"Basic Settings": "基础设置", | |
"Video Script Settings": "视频文案设置", | |
"Generate Video": "生成视频" | |
} | |
} | |
} | |
def get_uuid(): | |
"""Generate UUID""" | |
return str(uuid4()) | |
def to_json(obj): | |
"""Convert object to JSON string""" | |
try: | |
return json.dumps(obj, ensure_ascii=False, indent=2) | |
except Exception: | |
return str(obj) | |
def storage_dir(subdir="", create=False): | |
"""Get storage directory""" | |
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | |
storage_path = os.path.join(root_dir, "storage") | |
if subdir: | |
storage_path = os.path.join(storage_path, subdir) | |
if create and not os.path.exists(storage_path): | |
os.makedirs(storage_path, exist_ok=True) | |
return storage_path | |
def task_dir(task_id=""): | |
"""Get task directory""" | |
if task_id: | |
return os.path.join(storage_dir("tasks", create=True), task_id) | |
return storage_dir("tasks", create=True) | |