AIdeaText commited on
Commit
273abe1
·
verified ·
1 Parent(s): 6eff03a

Update translations/__init__.py

Browse files
Files changed (1) hide show
  1. translations/__init__.py +65 -64
translations/__init__.py CHANGED
@@ -1,64 +1,65 @@
1
- # translations/__init__.py
2
- import logging
3
- from importlib import import_module
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
- def get_translations(lang_code):
8
- # Asegurarse de que lang_code sea válido
9
- if lang_code not in ['es', 'en', 'fr', 'pt']:
10
- print(f"Invalid lang_code: {lang_code}. Defaulting to 'es'")
11
- lang_code = 'es'
12
-
13
- try:
14
- # Importar dinámicamente el módulo de traducción
15
- translation_module = import_module(f'.{lang_code}', package='translations')
16
- translations = getattr(translation_module, 'TRANSLATIONS', {})
17
- except ImportError:
18
- logger.warning(f"Translation module for {lang_code} not found. Falling back to English.")
19
- # Importar el módulo de inglés como fallback
20
- translation_module = import_module('.en', package='translations')
21
- translations = getattr(translation_module, 'TRANSLATIONS', {})
22
-
23
- def get_text(key, section='COMMON', default=''):
24
- return translations.get(section, {}).get(key, default)
25
-
26
- return {
27
- 'get_text': get_text,
28
- **translations.get('COMMON', {}),
29
- **translations.get('TABS', {}),
30
- **translations.get('MORPHOSYNTACTIC', {}),
31
- **translations.get('SEMANTIC', {}),
32
- **translations.get('DISCOURSE', {}),
33
- **translations.get('ACTIVITIES', {}),
34
- **translations.get('FEEDBACK', {}),
35
- **translations.get('TEXT_TYPES', {}),
36
- **translations.get('CURRENT_SITUATION', {}) # Añadir esta línea
37
- }
38
-
39
- # Nueva función para obtener traducciones específicas del landing page
40
- def get_landing_translations(lang_code):
41
- # Asegurarse de que lang_code sea válido
42
- if lang_code not in ['es', 'en', 'fr', 'pt']:
43
- print(f"Invalid lang_code: {lang_code}. Defaulting to 'es'")
44
- lang_code = 'es'
45
-
46
- try:
47
- # Importar dinámicamente el módulo de traducción del landing page
48
- from .landing_translations import LANDING_TRANSLATIONS
49
-
50
- # Asegurarse de que el idioma esté disponible, si no usar español como fallback
51
- if lang_code not in LANDING_TRANSLATIONS:
52
- logger.warning(f"Landing translations for {lang_code} not found. Falling back to Spanish.")
53
- lang_code = 'es'
54
-
55
- return LANDING_TRANSLATIONS[lang_code]
56
- except ImportError:
57
- logger.warning("Landing translations module not found. Using default translations.")
58
- # Crear un conjunto mínimo de traducciones por defecto
59
- return {
60
- 'select_language': 'Select language' if lang_code == 'en' else 'Selecciona tu idioma',
61
- 'login': 'Login' if lang_code == 'en' else 'Iniciar Sesión',
62
- 'register': 'Sign Up' if lang_code == 'en' else 'Registrarse',
63
- # Añadir más traducciones por defecto si es necesario
64
- }
 
 
1
+ # translations/__init__.py
2
+ import logging
3
+ from importlib import import_module
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ def get_translations(lang_code):
8
+ # Asegurarse de que lang_code sea válido
9
+ if lang_code not in ['es', 'en', 'fr', 'pt']:
10
+ print(f"Invalid lang_code: {lang_code}. Defaulting to 'es'")
11
+ lang_code = 'es'
12
+
13
+ try:
14
+ # Importar dinámicamente el módulo de traducción
15
+ translation_module = import_module(f'.{lang_code}', package='translations')
16
+ translations = getattr(translation_module, 'TRANSLATIONS', {})
17
+ except ImportError:
18
+ logger.warning(f"Translation module for {lang_code} not found. Falling back to English.")
19
+ # Importar el módulo de inglés como fallback
20
+ translation_module = import_module('.en', package='translations')
21
+ translations = getattr(translation_module, 'TRANSLATIONS', {})
22
+
23
+ def get_text(key, section='COMMON', default=''):
24
+ return translations.get(section, {}).get(key, default)
25
+
26
+ return {
27
+ 'get_text': get_text,
28
+ **translations.get('COMMON', {}),
29
+ **translations.get('TABS', {}),
30
+ **translations.get('MORPHOSYNTACTIC', {}),
31
+ **translations.get('SEMANTIC', {}),
32
+ **translations.get('DISCOURSE', {}),
33
+ **translations.get('ACTIVITIES', {}),
34
+ **translations.get('FEEDBACK', {}),
35
+ **translations.get('TEXT_TYPES', {}),
36
+ **translations.get('CURRENT_SITUATION', {}), # Añadir esta línea
37
+ **translations.get('GRAPH_LABELS', {})
38
+ }
39
+
40
+ # Nueva función para obtener traducciones específicas del landing page
41
+ def get_landing_translations(lang_code):
42
+ # Asegurarse de que lang_code sea válido
43
+ if lang_code not in ['es', 'en', 'fr', 'pt']:
44
+ print(f"Invalid lang_code: {lang_code}. Defaulting to 'es'")
45
+ lang_code = 'es'
46
+
47
+ try:
48
+ # Importar dinámicamente el módulo de traducción del landing page
49
+ from .landing_translations import LANDING_TRANSLATIONS
50
+
51
+ # Asegurarse de que el idioma esté disponible, si no usar español como fallback
52
+ if lang_code not in LANDING_TRANSLATIONS:
53
+ logger.warning(f"Landing translations for {lang_code} not found. Falling back to Spanish.")
54
+ lang_code = 'es'
55
+
56
+ return LANDING_TRANSLATIONS[lang_code]
57
+ except ImportError:
58
+ logger.warning("Landing translations module not found. Using default translations.")
59
+ # Crear un conjunto mínimo de traducciones por defecto
60
+ return {
61
+ 'select_language': 'Select language' if lang_code == 'en' else 'Selecciona tu idioma',
62
+ 'login': 'Login' if lang_code == 'en' else 'Iniciar Sesión',
63
+ 'register': 'Sign Up' if lang_code == 'en' else 'Registrarse',
64
+ # Añadir más traducciones por defecto si es necesario
65
+ }