Spaces:
Building
Building
Update locale_manager.py
Browse files- locale_manager.py +33 -20
locale_manager.py
CHANGED
@@ -25,32 +25,45 @@ class LocaleManager:
|
|
25 |
|
26 |
@classmethod
|
27 |
def _load_locale(cls, language: str) -> Dict:
|
28 |
-
"""Load locale from file"""
|
29 |
base_path = Path(__file__).parent / "locales"
|
|
|
|
|
30 |
locale_file = base_path / f"{language}.json"
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
locale_file = base_path / f"{language}.json"
|
37 |
|
38 |
if locale_file.exists():
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
with open(fallback_file, 'r', encoding='utf-8') as f:
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
@classmethod
|
56 |
def list_available_locales(cls) -> List[str]:
|
|
|
25 |
|
26 |
@classmethod
|
27 |
def _load_locale(cls, language: str) -> Dict:
|
28 |
+
"""Load locale from file - accepts both 'tr' and 'tr-TR' formats"""
|
29 |
base_path = Path(__file__).parent / "locales"
|
30 |
+
|
31 |
+
# First try exact match
|
32 |
locale_file = base_path / f"{language}.json"
|
33 |
|
34 |
+
# If not found and has region code, try without region (tr-TR -> tr)
|
35 |
+
if not locale_file.exists() and '-' in language:
|
36 |
+
language_code = language.split('-')[0]
|
37 |
+
locale_file = base_path / f"{language_code}.json"
|
|
|
38 |
|
39 |
if locale_file.exists():
|
40 |
+
try:
|
41 |
+
with open(locale_file, 'r', encoding='utf-8') as f:
|
42 |
+
data = json.load(f)
|
43 |
+
log_debug(f"✅ Loaded locale file: {locale_file.name}")
|
44 |
+
return data
|
45 |
+
except Exception as e:
|
46 |
+
log_error(f"Failed to load locale file {locale_file}", e)
|
47 |
+
|
48 |
+
# Try English fallback
|
49 |
+
fallback_file = base_path / "en.json"
|
50 |
+
if fallback_file.exists():
|
51 |
+
try:
|
52 |
with open(fallback_file, 'r', encoding='utf-8') as f:
|
53 |
+
data = json.load(f)
|
54 |
+
log_warning(f"⚠️ Using English fallback for locale: {language}")
|
55 |
+
return data
|
56 |
+
except:
|
57 |
+
pass
|
58 |
+
|
59 |
+
# Minimal fallback if no locale files exist
|
60 |
+
log_warning(f"⚠️ No locale files found, using minimal fallback")
|
61 |
+
return {
|
62 |
+
"code": "tr",
|
63 |
+
"locale_tag": "tr-TR",
|
64 |
+
"name": "Türkçe",
|
65 |
+
"english_name": "Turkish"
|
66 |
+
}
|
67 |
|
68 |
@classmethod
|
69 |
def list_available_locales(cls) -> List[str]:
|