init
This commit is contained in:
117
reelforge/i18n/__init__.py
Normal file
117
reelforge/i18n/__init__.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""
|
||||
International language support for ReelForge
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
_locales: Dict[str, dict] = {}
|
||||
_current_language: str = "zh_CN"
|
||||
|
||||
|
||||
def load_locales() -> Dict[str, dict]:
|
||||
"""Load all locale files from locales directory"""
|
||||
global _locales
|
||||
|
||||
locales_dir = Path(__file__).parent / "locales"
|
||||
|
||||
if not locales_dir.exists():
|
||||
logger.warning(f"Locales directory not found: {locales_dir}")
|
||||
return _locales
|
||||
|
||||
for json_file in locales_dir.glob("*.json"):
|
||||
lang_code = json_file.stem
|
||||
try:
|
||||
with open(json_file, "r", encoding="utf-8") as f:
|
||||
_locales[lang_code] = json.load(f)
|
||||
logger.debug(f"Loaded locale: {lang_code}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load locale {lang_code}: {e}")
|
||||
|
||||
logger.info(f"Loaded {len(_locales)} locales: {list(_locales.keys())}")
|
||||
return _locales
|
||||
|
||||
|
||||
def set_language(lang_code: str):
|
||||
"""Set current language"""
|
||||
global _current_language
|
||||
if lang_code in _locales:
|
||||
_current_language = lang_code
|
||||
logger.debug(f"Language set to: {lang_code}")
|
||||
else:
|
||||
logger.warning(f"Language {lang_code} not found, keeping {_current_language}")
|
||||
|
||||
|
||||
def get_language() -> str:
|
||||
"""Get current language"""
|
||||
return _current_language
|
||||
|
||||
|
||||
def tr(key: str, fallback: Optional[str] = None, **kwargs) -> str:
|
||||
"""
|
||||
Translate a key to current language
|
||||
|
||||
Args:
|
||||
key: Translation key (e.g., "app.title")
|
||||
fallback: Fallback text if key not found
|
||||
**kwargs: Format parameters for string interpolation
|
||||
|
||||
Returns:
|
||||
Translated text
|
||||
|
||||
Example:
|
||||
tr("app.title") # => "ReelForge - AI书单视频生成器"
|
||||
tr("error.missing_field", field="API Key") # => "请填写 API Key"
|
||||
"""
|
||||
locale = _locales.get(_current_language, {})
|
||||
translations = locale.get("t", {})
|
||||
|
||||
result = translations.get(key)
|
||||
|
||||
if result is None:
|
||||
# Try fallback parameter
|
||||
if fallback is not None:
|
||||
result = fallback
|
||||
# Try English fallback
|
||||
elif _current_language != "en_US" and "en_US" in _locales:
|
||||
en_locale = _locales["en_US"]
|
||||
result = en_locale.get("t", {}).get(key)
|
||||
|
||||
# Last resort: return the key itself
|
||||
if result is None:
|
||||
result = key
|
||||
logger.debug(f"Translation missing: {key}")
|
||||
|
||||
# Apply string interpolation if kwargs provided
|
||||
if kwargs:
|
||||
try:
|
||||
result = result.format(**kwargs)
|
||||
except (KeyError, ValueError) as e:
|
||||
logger.warning(f"Failed to format translation '{key}': {e}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_language_name(lang_code: Optional[str] = None) -> str:
|
||||
"""Get display name of a language"""
|
||||
if lang_code is None:
|
||||
lang_code = _current_language
|
||||
|
||||
locale = _locales.get(lang_code, {})
|
||||
return locale.get("language_name", lang_code)
|
||||
|
||||
|
||||
def get_available_languages() -> Dict[str, str]:
|
||||
"""Get all available languages with their display names"""
|
||||
return {
|
||||
code: locale.get("language_name", code)
|
||||
for code, locale in _locales.items()
|
||||
}
|
||||
|
||||
|
||||
# Auto-load locales on import
|
||||
load_locales()
|
||||
|
||||
159
reelforge/i18n/locales/en_US.json
Normal file
159
reelforge/i18n/locales/en_US.json
Normal file
@@ -0,0 +1,159 @@
|
||||
{
|
||||
"language_name": "English",
|
||||
"t": {
|
||||
"app.title": "🔨 ReelForge - Modular Video Creation Platform",
|
||||
"app.subtitle": "Forge your perfect reel engine",
|
||||
|
||||
"section.content_input": "📖 Content Input",
|
||||
"section.style_settings": "⚙️ Custom Settings",
|
||||
"section.video_generation": "🎬 Generate Video",
|
||||
|
||||
"input_mode.book": "📚 Book Name",
|
||||
"input_mode.topic": "💡 Topic",
|
||||
"input_mode.custom": "✍️ Custom Content",
|
||||
|
||||
"input.book_name": "Book Name",
|
||||
"input.book_name_placeholder": "e.g., Atomic Habits, How to Win Friends",
|
||||
"input.book_name_help": "Enter the book name, will fetch book info and generate video",
|
||||
|
||||
"input.topic": "Topic",
|
||||
"input.topic_placeholder": "e.g., How to build passive income, How to build good habits",
|
||||
"input.topic_help": "Enter a topic, AI will generate content based on it",
|
||||
|
||||
"input.content": "Content",
|
||||
"input.content_placeholder": "Enter your custom content here...",
|
||||
"input.content_help": "Provide your own content for video generation",
|
||||
|
||||
"input.title": "Title (Optional)",
|
||||
"input.title_placeholder": "Video title (auto-generated if empty)",
|
||||
|
||||
"book.search": "🔍 Search Book",
|
||||
"book.searching": "Searching book...",
|
||||
"book.found": "✅ Book found!",
|
||||
"book.not_found": "❌ Failed to fetch book: {error}",
|
||||
"book.name_required": "Please enter a book name",
|
||||
|
||||
"book.title": "Title",
|
||||
"book.author": "Author",
|
||||
"book.rating": "Rating",
|
||||
"book.summary": "📝 Summary",
|
||||
|
||||
"voice.title": "🎤 Voice Selection",
|
||||
"voice.male_professional": "🎤 Male-Professional",
|
||||
"voice.male_young": "🎙️ Male-Young",
|
||||
"voice.female_gentle": "🎵 Female-Gentle",
|
||||
"voice.female_energetic": "🎶 Female-Energetic",
|
||||
"voice.preview": "▶ Preview Voice",
|
||||
"voice.previewing": "Generating voice preview...",
|
||||
"voice.preview_failed": "Preview failed: {error}",
|
||||
|
||||
"style.title": "🎨 Illustration Style",
|
||||
"style.custom": "Custom",
|
||||
"style.description": "Style Description",
|
||||
"style.description_placeholder": "Describe the illustration style you want (any language)...",
|
||||
"style.preview": "🖼️ Preview Style",
|
||||
"style.previewing": "Generating style preview...",
|
||||
"style.preview_caption": "Style Preview",
|
||||
"style.preview_failed": "Preview failed: {error}",
|
||||
"style.generated_prompt": "Generated prompt: {prompt}",
|
||||
|
||||
"template.title": "📐 Storyboard Template",
|
||||
"template.classic": "Classic",
|
||||
"template.modern": "Modern",
|
||||
"template.neon": "Neon",
|
||||
|
||||
"video.title": "🎬 Video Settings",
|
||||
"video.frames": "Frames",
|
||||
"video.frames_help": "More frames = longer video",
|
||||
"video.frames_label": "Frames: {n}",
|
||||
|
||||
"bgm.title": "🎵 Background Music",
|
||||
"bgm.none": "🔇 No BGM",
|
||||
"bgm.preview": "▶ Preview Music",
|
||||
"bgm.preview_failed": "❌ Music file not found: {file}",
|
||||
|
||||
"btn.generate": "🎬 Generate Video",
|
||||
"btn.save_config": "💾 Save Configuration",
|
||||
"btn.reset_config": "🔄 Reset to Default",
|
||||
"btn.save_and_start": "Save and Start",
|
||||
"btn.test_connection": "Test Connection",
|
||||
|
||||
"status.initializing": "🔧 Initializing...",
|
||||
"status.generating": "🚀 Generating video...",
|
||||
"status.success": "✅ Video generated successfully!",
|
||||
"status.error": "❌ Generation failed: {error}",
|
||||
"status.video_generated": "✅ Video generated: {path}",
|
||||
"status.video_not_found": "Video file not found: {path}",
|
||||
"status.config_saved": "✅ Configuration saved",
|
||||
"status.config_reset": "✅ Configuration reset to default",
|
||||
"status.connection_success": "✅ Connected",
|
||||
"status.connection_failed": "❌ Connection failed",
|
||||
|
||||
"progress.generating_narrations": "Generating narrations...",
|
||||
"progress.generating_image_prompts": "Generating image prompts...",
|
||||
"progress.frame": "Frame {current}/{total}",
|
||||
"progress.frame_step": "Frame {current}/{total} - Step {step}/4: {action}",
|
||||
"progress.step_audio": "Generating audio",
|
||||
"progress.step_image": "Generating image",
|
||||
"progress.step_compose": "Composing frame",
|
||||
"progress.step_video": "Creating video segment",
|
||||
"progress.concatenating": "Concatenating video segments...",
|
||||
"progress.finalizing": "Finalizing...",
|
||||
|
||||
"error.input_required": "❌ Please provide book name, topic, or content",
|
||||
"error.api_key_required": "❌ Please enter API Key",
|
||||
"error.missing_field": "Please enter {field}",
|
||||
|
||||
"info.duration": "Duration",
|
||||
"info.file_size": "File Size",
|
||||
"info.frames": "Scenes",
|
||||
"info.scenes_unit": " scenes",
|
||||
"info.resolution": "Resolution",
|
||||
"info.video_information": "📊 Video Information",
|
||||
"info.no_video_yet": "Video preview will appear here after generation",
|
||||
|
||||
"settings.title": "⚙️ System Configuration (Required)",
|
||||
"settings.not_configured": "⚠️ Please complete system configuration before generating videos",
|
||||
"settings.llm.title": "🤖 Large Language Model",
|
||||
"settings.llm.quick_select": "Quick Select",
|
||||
"settings.llm.quick_select_help": "Choose a preset LLM or custom configuration",
|
||||
"settings.llm.get_api_key": "Get API Key",
|
||||
"settings.llm.api_key": "API Key",
|
||||
"settings.llm.api_key_help": "Enter your API Key",
|
||||
"settings.llm.base_url": "Base URL",
|
||||
"settings.llm.base_url_help": "API service address",
|
||||
"settings.llm.model": "Model",
|
||||
"settings.llm.model_help": "Model name",
|
||||
|
||||
"settings.tts.title": "🎤 Text-to-Speech",
|
||||
"settings.tts.provider": "Provider",
|
||||
"settings.tts.provider_help": "Select TTS service provider",
|
||||
"settings.tts.edge_info": "💡 Edge TTS is free and requires no configuration",
|
||||
|
||||
"settings.image.title": "🎨 Image Generation",
|
||||
"settings.image.local_title": "Local/Self-hosted ComfyUI",
|
||||
"settings.image.cloud_title": "RunningHub Cloud",
|
||||
"settings.image.comfyui_url": "ComfyUI Service URL",
|
||||
"settings.image.comfyui_url_help": "Local or remote ComfyUI service URL, default: http://127.0.0.1:8188",
|
||||
"settings.image.runninghub_api_key": "RunningHub API Key",
|
||||
"settings.image.runninghub_api_key_help": "Visit https://runninghub.ai to register and get API Key",
|
||||
|
||||
"settings.book.title": "📚 Book Information",
|
||||
"settings.book.provider": "Provider",
|
||||
"settings.book.provider_help": "Select book information source",
|
||||
|
||||
"welcome.first_time": "🎉 Welcome to ReelForge! Please complete basic configuration",
|
||||
"welcome.config_hint": "💡 First-time setup requires API Key configuration, you can modify it in advanced settings later",
|
||||
|
||||
"wizard.llm_required": "🤖 Large Language Model Configuration (Required)",
|
||||
"wizard.image_optional": "🎨 Image Generation Configuration (Optional)",
|
||||
"wizard.image_hint": "💡 If not configured, default template will be used (no AI image generation)",
|
||||
"wizard.configure_image": "Configure Image Generation (Recommended)",
|
||||
|
||||
"label.required": "(Required)",
|
||||
"label.optional": "(Optional)",
|
||||
|
||||
"language.select": "🌐 Language"
|
||||
}
|
||||
}
|
||||
|
||||
159
reelforge/i18n/locales/zh_CN.json
Normal file
159
reelforge/i18n/locales/zh_CN.json
Normal file
@@ -0,0 +1,159 @@
|
||||
{
|
||||
"language_name": "简体中文",
|
||||
"t": {
|
||||
"app.title": "🔨 ReelForge - 模块化视频创作平台",
|
||||
"app.subtitle": "打造专属你的视频创作引擎",
|
||||
|
||||
"section.content_input": "📖 内容输入",
|
||||
"section.style_settings": "⚙️ 自定义设置",
|
||||
"section.video_generation": "🎬 生成视频",
|
||||
|
||||
"input_mode.book": "📚 书名",
|
||||
"input_mode.topic": "💡 主题",
|
||||
"input_mode.custom": "✍️ 自定义内容",
|
||||
|
||||
"input.book_name": "书名",
|
||||
"input.book_name_placeholder": "例如:原子习惯、人性的弱点、Atomic Habits",
|
||||
"input.book_name_help": "输入书名,将自动获取书籍信息并生成视频",
|
||||
|
||||
"input.topic": "主题",
|
||||
"input.topic_placeholder": "例如:如何增加被动收入、How to build good habits",
|
||||
"input.topic_help": "输入一个主题,AI 将根据主题生成内容",
|
||||
|
||||
"input.content": "内容",
|
||||
"input.content_placeholder": "在此输入您的自定义内容...",
|
||||
"input.content_help": "提供您自己的内容用于视频生成",
|
||||
|
||||
"input.title": "标题(可选)",
|
||||
"input.title_placeholder": "视频标题(留空则自动生成)",
|
||||
|
||||
"book.search": "🔍 搜索书籍",
|
||||
"book.searching": "正在搜索书籍...",
|
||||
"book.found": "✅ 找到书籍!",
|
||||
"book.not_found": "❌ 获取书籍失败:{error}",
|
||||
"book.name_required": "请输入书名",
|
||||
|
||||
"book.title": "书名",
|
||||
"book.author": "作者",
|
||||
"book.rating": "评分",
|
||||
"book.summary": "📝 简介",
|
||||
|
||||
"voice.title": "🎤 语音选择",
|
||||
"voice.male_professional": "🎤 男声-专业",
|
||||
"voice.male_young": "🎙️ 男声-年轻",
|
||||
"voice.female_gentle": "🎵 女声-温柔",
|
||||
"voice.female_energetic": "🎶 女声-活力",
|
||||
"voice.preview": "▶ 试听语音",
|
||||
"voice.previewing": "正在生成语音预览...",
|
||||
"voice.preview_failed": "预览失败:{error}",
|
||||
|
||||
"style.title": "🎨 插图风格",
|
||||
"style.custom": "自定义",
|
||||
"style.description": "风格描述",
|
||||
"style.description_placeholder": "描述您想要的插图风格(任何语言)...",
|
||||
"style.preview": "🖼️ 预览风格",
|
||||
"style.previewing": "正在生成风格预览...",
|
||||
"style.preview_caption": "风格预览",
|
||||
"style.preview_failed": "预览失败:{error}",
|
||||
"style.generated_prompt": "生成的提示词:{prompt}",
|
||||
|
||||
"template.title": "📐 分镜模板",
|
||||
"template.classic": "Classic",
|
||||
"template.modern": "Modern",
|
||||
"template.neon": "Neon",
|
||||
|
||||
"video.title": "🎬 视频设置",
|
||||
"video.frames": "帧数",
|
||||
"video.frames_help": "更多帧数 = 更长视频",
|
||||
"video.frames_label": "帧数:{n}",
|
||||
|
||||
"bgm.title": "🎵 背景音乐",
|
||||
"bgm.none": "🔇 无背景音乐",
|
||||
"bgm.preview": "▶ 试听音乐",
|
||||
"bgm.preview_failed": "❌ 音乐文件未找到:{file}",
|
||||
|
||||
"btn.generate": "🎬 生成视频",
|
||||
"btn.save_config": "💾 保存配置",
|
||||
"btn.reset_config": "🔄 重置默认",
|
||||
"btn.save_and_start": "保存并开始",
|
||||
"btn.test_connection": "测试连接",
|
||||
|
||||
"status.initializing": "🔧 正在初始化...",
|
||||
"status.generating": "🚀 正在生成视频...",
|
||||
"status.success": "✅ 视频生成成功!",
|
||||
"status.error": "❌ 生成失败:{error}",
|
||||
"status.video_generated": "✅ 视频已生成:{path}",
|
||||
"status.video_not_found": "视频文件未找到:{path}",
|
||||
"status.config_saved": "✅ 配置已保存",
|
||||
"status.config_reset": "✅ 配置已重置为默认值",
|
||||
"status.connection_success": "✅ 连接成功",
|
||||
"status.connection_failed": "❌ 连接失败",
|
||||
|
||||
"progress.generating_narrations": "生成旁白...",
|
||||
"progress.generating_image_prompts": "生成图片提示词...",
|
||||
"progress.frame": "分镜 {current}/{total}",
|
||||
"progress.frame_step": "分镜 {current}/{total} - 步骤 {step}/4: {action}",
|
||||
"progress.step_audio": "生成语音",
|
||||
"progress.step_image": "生成插图",
|
||||
"progress.step_compose": "合成画面",
|
||||
"progress.step_video": "创建视频片段",
|
||||
"progress.concatenating": "拼接视频片段...",
|
||||
"progress.finalizing": "完成中...",
|
||||
|
||||
"error.input_required": "❌ 请提供书名、主题或内容",
|
||||
"error.api_key_required": "❌ 请填写 API Key",
|
||||
"error.missing_field": "请填写 {field}",
|
||||
|
||||
"info.duration": "时长",
|
||||
"info.file_size": "文件大小",
|
||||
"info.frames": "分镜数",
|
||||
"info.scenes_unit": "分镜",
|
||||
"info.resolution": "分辨率",
|
||||
"info.video_information": "📊 视频信息",
|
||||
"info.no_video_yet": "生成视频后,预览将显示在这里",
|
||||
|
||||
"settings.title": "⚙️ 系统配置(必需)",
|
||||
"settings.not_configured": "⚠️ 请先完成系统配置才能生成视频",
|
||||
"settings.llm.title": "🤖 大语言模型",
|
||||
"settings.llm.quick_select": "快速选择",
|
||||
"settings.llm.quick_select_help": "选择预置的 LLM 或自定义配置",
|
||||
"settings.llm.get_api_key": "获取 API Key",
|
||||
"settings.llm.api_key": "API Key",
|
||||
"settings.llm.api_key_help": "填入您的 API Key",
|
||||
"settings.llm.base_url": "Base URL",
|
||||
"settings.llm.base_url_help": "API 服务地址",
|
||||
"settings.llm.model": "Model",
|
||||
"settings.llm.model_help": "模型名称",
|
||||
|
||||
"settings.tts.title": "🎤 语音合成",
|
||||
"settings.tts.provider": "服务商",
|
||||
"settings.tts.provider_help": "选择 TTS 服务提供商",
|
||||
"settings.tts.edge_info": "💡 Edge TTS 是免费的,无需配置",
|
||||
|
||||
"settings.image.title": "🎨 图像生成",
|
||||
"settings.image.local_title": "本地/自建 ComfyUI",
|
||||
"settings.image.cloud_title": "RunningHub 云端",
|
||||
"settings.image.comfyui_url": "ComfyUI 服务地址",
|
||||
"settings.image.comfyui_url_help": "本地或远程 ComfyUI 服务地址,默认: http://127.0.0.1:8188",
|
||||
"settings.image.runninghub_api_key": "RunningHub API Key",
|
||||
"settings.image.runninghub_api_key_help": "访问 https://runninghub.ai 注册并获取 API Key",
|
||||
|
||||
"settings.book.title": "📚 书籍信息",
|
||||
"settings.book.provider": "服务商",
|
||||
"settings.book.provider_help": "选择书籍信息来源",
|
||||
|
||||
"welcome.first_time": "🎉 欢迎使用 ReelForge!请先完成基础配置",
|
||||
"welcome.config_hint": "💡 首次使用需要配置 API Key,后续可以在高级设置中修改",
|
||||
|
||||
"wizard.llm_required": "🤖 大语言模型配置(必需)",
|
||||
"wizard.image_optional": "🎨 图像生成配置(可选)",
|
||||
"wizard.image_hint": "💡 如果不配置图像生成,将使用默认模板(无 AI 生图)",
|
||||
"wizard.configure_image": "配置图像生成(推荐)",
|
||||
|
||||
"label.required": "(必需)",
|
||||
"label.optional": "(可选)",
|
||||
|
||||
"language.select": "🌐 语言"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user