Skip to content

Commit 1b23646

Browse files
committed
fix tests not running
1 parent 793ab83 commit 1b23646

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

cli/commands/analyze.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ def analyze_command(file, all, json_output, LANG_FILE):
2323

2424
# dictionary for the stats
2525
stats_labels = {
26-
"line_count": messages.get("line_count_option", "Line Count"),
27-
"function_count": messages.get("function_count_option", "Function Count"),
28-
"comment_line_count": messages.get("comment_line_count_option", "Comment Line Count"),
29-
"inline_comment_count": messages.get("inline_comment_count_option", "Inline Comment Count"),
30-
"indentation_level": messages.get("indentation_level_option", "Indentation Analysis")
26+
"line_count": get_translation("line_count_option"),
27+
"function_count": get_translation("function_count_option"),
28+
"comment_line_count": get_translation("comment_line_count_option"),
29+
"inline_comment_count": get_translation("inline_comment_count_option"),
30+
"indentation_level": get_translation("indentation_level_option")
3131
}
3232

3333
# If --all flag is used, skip the selection menu and use all stats

cli/commands/export/export.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def export_results(results, format_type, output_file, messages):
3232
with open(output_file, "w", encoding="utf-8", newline="") as f:
3333
writer = csv.writer(f)
3434
# Write header
35-
writer.writerow(["Metric", "Value"])
35+
writer.writerow([get_translation("metric"), get_translation("value")])
3636
# Write data
3737
for key, value in results.items():
3838
if isinstance(value, (int, float, str)):
@@ -80,22 +80,20 @@ def export_results(results, format_type, output_file, messages):
8080
return True
8181

8282
except Exception as e:
83-
print(f"{messages.get('export_error', 'Export error')}: {str(e)}")
83+
print(f"[red]{get_translation('error')}[/]: {str(e)}")
8484
return False
8585

8686
def export_command(file, format_type, output, LANG_FILE):
8787
"""
8888
Export analysis results to a file.
8989
"""
90-
# Load translations
91-
messages = get_translation(LANG_FILE)
9290
console = Console()
9391

9492
# Validate format type
9593
valid_formats = ["json", "csv", "markdown", "html"]
9694
if format_type not in valid_formats:
97-
console.print(f"[red]{messages.get('invalid_format', 'Invalid format')}[/] {format_type}")
98-
console.print(f"{messages.get('valid_formats', 'Valid formats')}: {', '.join(valid_formats)}")
95+
console.print(f"[red]{get_translation('invalid_format')}[/] {format_type}")
96+
console.print(f"{get_translation('valid_formats')}: {', '.join(valid_formats)}")
9997
return
10098

10199
try:
@@ -109,12 +107,12 @@ def export_command(file, format_type, output, LANG_FILE):
109107
output = f"{base_name}_analysis.{format_type}"
110108

111109
# Export results
112-
success = export_results(results, format_type, output, messages)
110+
success = export_results(results, format_type, output, None)
113111

114112
if success:
115-
console.print(f"[green]{messages.get('export_success', 'Export successful')}[/]: {output}")
113+
console.print(f"[green]{get_translation('export_success')}[/]: {output}")
116114
else:
117-
console.print(f"[red]{messages.get('export_failed', 'Export failed')}[/]")
115+
console.print(f"[red]{get_translation('export_failed')}[/]")
118116

119117
except Exception as e:
120-
console.print(f"[red]{messages.get('error', 'Error')}[/]: {str(e)}")
118+
console.print(f"[red]{get_translation('error')}[/]: {str(e)}")

cli/commands/hello.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55

66
def hello_command(LANG_FILE):
7-
8-
# load translations
9-
messages = get_translation(LANG_FILE)
10-
117
# print the hello message
12-
print(messages["welcome"])
13-
print(messages["description"])
8+
print(get_translation("welcome"))
9+
print(get_translation("description"))

cli/commands/version.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ def version_command(LANG_FILE, CURRENT_DIR):
99
Display the current version of the application.
1010
"""
1111

12-
# load translations
13-
messages = get_translation(LANG_FILE)
14-
1512
try:
1613
# Get the path to setup.py in the parent directory
1714
setup_path = os.path.join(os.path.dirname(CURRENT_DIR), "setup.py")
1815

1916
# Check if setup.py exists
2017
if not os.path.exists(setup_path):
21-
print(f"[red]{messages.get('setup_not_found', 'Error: setup.py not found.')}")
18+
print(f"[red]{get_translation('setup_not_found')}")
2219
return
2320

2421
# Read setup.py to extract version
@@ -33,9 +30,9 @@ def version_command(LANG_FILE, CURRENT_DIR):
3330

3431
# Display version information
3532
if version_info:
36-
print(f"[green]{messages.get('version_info', 'SpiceCode Version:')}[/] {version_info}")
33+
print(f"[green]{get_translation('version_info')}[/] {version_info}")
3734
else:
38-
print(f"[yellow]{messages.get('version_not_found', 'Version information not found in setup.py')}")
35+
print(f"[yellow]{get_translation('version_not_found')}")
3936

4037
except Exception as e:
41-
print(f"[red]{messages.get('error', 'Error:')}[/] {e}")
38+
print(f"[red]{get_translation('error')}[/] {e}")

utils/get_translation.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@
22
import os
33

44
# this will load the translations
5-
def get_translation(LANG_FILE):
5+
def get_translation(key):
6+
"""
7+
Get a translated message for the given key.
8+
9+
Args:
10+
key (str): The message key to translate
11+
12+
Returns:
13+
str: The translated message
14+
"""
15+
# read the lang file to see what language was set by user
16+
LANG_FILE = os.path.join(os.path.dirname(os.path.dirname(__file__)), "cli", "lang.txt")
617

7-
# read the lang file to see what langague was set by user
818
if os.path.exists(LANG_FILE):
9-
1019
# open the lang file
1120
with open(LANG_FILE, "r") as file:
12-
13-
# read the lang file
14-
lang = file.read().strip()
15-
16-
17-
if not lang:
18-
lang = 'en' # if file is empty, default to english
19-
21+
# read the lang file
22+
lang = file.read().strip()
23+
24+
if not lang:
25+
lang = 'en' # if file is empty, default to english
2026
else:
21-
lang = 'en' # default to English if there is not file but there will always be a file this is just in case ALSO THIS IS SO @icrcode DOESNT COMPLAIN ABOUT MY CODE NOT BEING CLEAN AND WHATEVER
27+
lang = 'en' # default to English if there is no file
2228

2329
# this is actually import the translations
2430
try:
25-
return importlib.import_module(f"cli.translations.{lang}").messages
31+
messages = importlib.import_module(f"cli.translations.{lang}").messages
2632
except ModuleNotFoundError:
27-
return importlib.import_module("cli.translations.en").messages # default to English if any errors
33+
messages = importlib.import_module("cli.translations.en").messages # default to English if any errors
34+
35+
# Return the specific message for the key, or the key itself if not found
36+
return messages.get(key, key)

0 commit comments

Comments
 (0)