Buckets:

download
raw
4.14 kB
# Copyright (c) 2025-2026 Yutaro Maeda. All rights reserved.
# Licensed under the Apache License 2.0. See LICENSE file for details.
"""Simple internationalization framework without gettext dependency.
Provides message translation for supported languages. Defaults to English
so existing behaviour is unchanged.
Usage::
from faultray.i18n import t, set_language
set_language("ja")
print(t("resilience_score")) # "レジリエンススコア"
print(t("scan_complete", count=5)) # "スキャン完了: 5個のコンポーネントを検出"
"""
from __future__ import annotations
MESSAGES: dict[str, dict[str, str]] = {
"en": {
"resilience_score": "Resilience Score",
"critical_findings": "Critical Findings",
"warning_findings": "Warnings",
"passed_scenarios": "Passed",
"no_issues": "No issues found",
"scan_complete": "Scan complete: {count} components discovered",
"simulation_running": "Running chaos simulation...",
"simulation_complete": "Simulation complete",
"error_recovery": "Error recovered: {detail}",
"telemetry_disabled": "Telemetry is disabled",
"telemetry_enabled": "Telemetry is enabled",
"loading_model": "Loading infrastructure model...",
"model_saved": "Model saved to {path}",
# Console report (reporter/report.py)
"infrastructure_overview": "Infrastructure Overview",
"metric": "Metric",
"value": "Value",
"components": "Components",
"dependencies": "Dependencies",
"report_title": "FaultRay Chaos Simulation Report",
"scenarios_tested": "Scenarios tested",
"critical": "Critical",
"warning": "Warning",
"passed": "Passed",
"cascade_path": "Cascade path:",
"passed_with_low_risk": "{count} scenarios passed with low risk",
},
"ja": {
"resilience_score": "レジリエンススコア",
"critical_findings": "重大な発見",
"warning_findings": "警告",
"passed_scenarios": "合格",
"no_issues": "問題は見つかりませんでした",
"scan_complete": "スキャン完了: {count}個のコンポーネントを検出",
"simulation_running": "カオスシミュレーションを実行中...",
"simulation_complete": "シミュレーション完了",
"error_recovery": "エラー回復: {detail}",
"telemetry_disabled": "テレメトリは無効です",
"telemetry_enabled": "テレメトリは有効です",
"loading_model": "インフラモデルを読み込み中...",
"model_saved": "モデルを{path}に保存しました",
# Console report (reporter/report.py)
"infrastructure_overview": "インフラ概要",
"metric": "項目",
"value": "値",
"components": "コンポーネント",
"dependencies": "依存関係",
"report_title": "FaultRay カオスシミュレーションレポート",
"scenarios_tested": "テスト済みシナリオ",
"critical": "重大",
"warning": "警告",
"passed": "合格",
"cascade_path": "カスケード経路:",
"passed_with_low_risk": "{count}件のシナリオが低リスクで合格",
},
}
_current_lang = "en"
def set_language(lang: str) -> None:
"""Set the active language.
Falls back to English if the requested language is not supported.
"""
global _current_lang
_current_lang = lang if lang in MESSAGES else "en"
def get_language() -> str:
"""Return the currently active language code."""
return _current_lang
def available_languages() -> list[str]:
"""Return list of supported language codes."""
return sorted(MESSAGES.keys())
def t(key: str, **kwargs) -> str:
"""Translate a message key.
Keyword arguments are interpolated into the message via ``str.format()``.
Returns the key itself if no translation is found.
"""
msg = MESSAGES.get(_current_lang, MESSAGES["en"]).get(key, key)
return msg.format(**kwargs) if kwargs else msg

Xet Storage Details

Size:
4.14 kB
·
Xet hash:
7861708830a8e425068d1fb0c485b7ac7ac0f9d6b8df66a3feaaced187af557f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.