Implementing i18n and Improving Playwright Stability on WSL
Author: miracle777Created Mar 17, 2025Updated Sep 25, 2026
Labelsinactive
Summary
This PR implements the following two major improvements:
- Added support for multilingual (i18n) functionality
- Improved browser operation stability in WSL environments
Implementation Details
1. Multilingual Support (i18n)
Structure
Created the app/i18n/ directory
- messages.py: Defines multilingual messages
- utils.py: Language management utilities
- init.py: Package initialization
Key Features
- Language switching via the OPENMANUS_LANG environment variable
- Fallback to the default language (English)
- Type-safe message management
- Categorized message organization
Usage Example
# Set language (environment variable)
export OPENMANUS_LANG=ja # Japanese
export OPENMANUS_LANG=en # English (default)
# Usage in code
from app.i18n.utils import i18n
message = i18n.get_message("prompts", "enter_prompt") 2. Browser Operation Improvements
Implemented Enhancements
- Proper installation and configuration of Playwright
- Verified functionality in WSL environments
- Optimized browser launch parameters
Environment Setup Instructions 1.Create and activate a virtual environment
conda create -n open_manus python=3.12
conda activate open_manus 2.Install required packages
pip install -r requirements.txt
playwright install chromium Verified Functionalities
- Displaying multilingual messages
- Rendering Google Maps in a browser
- Accessing websites such as Yahoo! Weather
- Running browser operations in WSL environments
Related Issues
#747 Issue with browser access in WSL environments
app/i18n/init.py
"""
Internationalization (i18n) support for OpenManus.
This package provides multi-language support for messages and user interface text.
"""
from .utils import i18n
__all__ = ["i18n"]app/i18n/messages.py
from typing import Any, Dict
# メッセージの定義
MESSAGES: Dict[str, Dict[str, Dict[str, str]]] = {
"en": {
"prompts": {
"enter_prompt": "Enter your prompt: ",
"empty_input": "❌ Empty input provided.",
"processing": " Processing your request...",
"completed": "✅ Processing completed.",
"results_header": " Execution Results:",
"browser_complete": " • Browser operation: Complete",
"data_complete": " • Data processing: Complete",
"file_save_complete": " • File saving: Complete",
"interrupted": "⚠️ Operation interrupted.",
"error_occurred": "❌ Error occurred: {}",
"session_ended": " Session ended.",
}
},
"ja": {
"prompts": {
"enter_prompt": "指示を入力してください: ",
"empty_input": "❌ 入力が空です。",
"processing": " リクエストを処理中...",
"completed": "✅ 処理が完了しました。",
"results_header": " 実行結果:",
"browser_complete": " • ブラウザ操作: 完了",
"data_complete": " • データ処理: 完了",
"file_save_complete": " • ファイル保存: 完了",
"interrupted": "⚠️ 操作が中断されました。",
"error_occurred": "❌ エラーが発生しました: {}",
"session_ended": " セッションを終了しました。",
}
},
}
app/i18n/utils.py
import os
from typing import Any, Optional
from .messages import MESSAGES
class I18nManager:
def __init__(self):
self._language = self._get_default_language()
def _get_default_language(self) -> str:
"""
Retrieves the default system language.
Returns 'en' if the environment variable OPENMANUS_LANG is not set.
"""
return os.environ.get("OPENMANUS_LANG", "en")
def set_language(self, language: str) -> None:
"""
Sets the language to be used.
"""
if language in MESSAGES:
self._language = language
def get_message(self, category: str, key: str, *args: Optional[Any]) -> str:
"""
Retrieves the message corresponding to the specified category and key.
"""
try:
message = MESSAGES[self._language][category][key]
return message.format(*args) if args else message
except KeyError:
# Fallback: Return the message in English
try:
message = MESSAGES["en"][category][key]
return message.format(*args) if args else message
except KeyError:
return f"Message not found: {category}.{key}"
# Global instance of I18nManager
i18n = I18nManager()
main.py
import asyncio
import os
from app.agent.manus import Manus
from app.i18n.utils import i18n
from app.logger import logger
async def main():
# Load language configuration from environment variable (fallback to English)
i18n.set_language(os.environ.get("OPENMANUS_LANG", "en"))
agent = Manus()
try:
prompt = input(i18n.get_message("prompts", "enter_prompt"))
if not prompt.strip():
logger.warning(i18n.get_message("prompts", "empty_input"))
return
logger.warning(i18n.get_message("prompts", "processing"))
await agent.run(prompt)
logger.info(i18n.get_message("prompts", "completed"))
# Show execution results
logger.info(i18n.get_message("prompts", "results_header"))
logger.info(i18n.get_message("prompts", "browser_complete"))
logger.info(i18n.get_message("prompts", "data_complete"))
if "save" in prompt.lower() or "download" in prompt.lower():
logger.info(i18n.get_message("prompts", "file_save_complete"))
except KeyboardInterrupt:
logger.warning(i18n.get_message("prompts", "interrupted"))
except Exception as e:
logger.error(i18n.get_message("prompts", "error_occurred").format(str(e)))
finally:
await agent.cleanup()
logger.info(i18n.get_message("prompts", "session_ended"))
def run_main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(main())
finally:
pending = asyncio.all_tasks(loop)
for task in pending:
task.cancel()
loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
loop.close()
if __name__ == "__main__":
run_main()
Source: FoundationAgents/OpenManus