-
Notifications
You must be signed in to change notification settings - Fork 0
/
replace_texts_with_labels.py
30 lines (24 loc) · 1.15 KB
/
replace_texts_with_labels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import csv
def replace_in_file(source_file_path, csv_file_path, output_file_path):
# Load translations from CSV
translations = {}
with open(csv_file_path, encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
original_text = row[1]
translated_text = row[0]
translations['"' + original_text + '"'] = '"' + translated_text + '"'
# Read source code
with open(source_file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Replace the text with the labels
for original, translated in translations.items():
content = content.replace(original, translated)
# Save the modified content in a new file
with open(output_file_path, 'w', encoding='utf-8') as file:
file.write(content)
# Script options
source_code_path = 'project.gbsproj' # Change this to the path of your GB Studio project file (.gbsproj)
csv_path = 'translation_labels.csv' # Change this to the path of your CSV file
output_path = 'project.gbsproj.labeled' # Output file path
replace_in_file(source_code_path, csv_path, output_path)