ciyidogan commited on
Commit
7af98e7
·
verified ·
1 Parent(s): 7bcb660

Update locale_manager.py

Browse files
Files changed (1) hide show
  1. 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
- if not locale_file.exists():
33
- # Try language code without region (tr-TR -> tr)
34
- if '-' in language:
35
- language = language.split('-')[0]
36
- locale_file = base_path / f"{language}.json"
37
 
38
  if locale_file.exists():
39
- with open(locale_file, 'r', encoding='utf-8') as f:
40
- return json.load(f)
41
- else:
42
- # Return English as fallback
43
- fallback_file = base_path / "en.json"
44
- if fallback_file.exists():
 
 
 
 
 
 
45
  with open(fallback_file, 'r', encoding='utf-8') as f:
46
- return json.load(f)
47
- else:
48
- # Minimal fallback if no locale files exist
49
- return {
50
- "code": "en",
51
- "name": "English",
52
- "english_name": "English"
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]: