Skip to content

Commit 72d3711

Browse files
authored
add localization(添加本地化) (#35)
* add i18n * Add gui.py as target * update * Update extract_locale.py
1 parent 8143197 commit 72d3711

10 files changed

Lines changed: 419 additions & 199 deletions

File tree

extract_locale.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import re
3+
4+
# Define regular expression patterns
5+
pattern = r'i18n\([^)]*\)'
6+
7+
# Initialize the dictionary to store key-value pairs
8+
data = {}
9+
10+
# Extract labels from infer-webui.py
11+
with open('infer-web.py', 'r', encoding='utf-8') as f:
12+
contents = f.read()
13+
matches = re.findall(pattern, contents)
14+
for match in matches:
15+
key = match.strip('()"')
16+
data[key] = key
17+
18+
# Extract labels from gui.py
19+
with open('gui.py', 'r', encoding='utf-8') as f:
20+
contents = f.read()
21+
matches = re.findall(pattern, contents)
22+
for match in matches:
23+
key = match.strip('()"')
24+
data[key] = key
25+
26+
# Save as a JSON file
27+
with open('./locale/zh_CN.json', 'w', encoding='utf-8') as f:
28+
json.dump(data, f, ensure_ascii=False, indent=4)

gui.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from fairseq import checkpoint_utils
66
import librosa,torch,parselmouth,faiss,time,threading
77
import torch.nn.functional as F
8-
98
#import matplotlib.pyplot as plt
109
from infer_pack.models import SynthesizerTrnMs256NSFsid, SynthesizerTrnMs256NSFsid_nono
11-
from language import language_gui
10+
from webui_locale import I18nAuto
11+
i18n = I18nAuto()
1212

1313
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
1414

@@ -170,24 +170,24 @@ def launcher(self):
170170
sg.Frame(layout=[
171171
[sg.Text(i18n("输入设备/Input Device")),sg.Combo(input_devices,key='sg_input_device',default_value=input_devices[sd.default.device[0]])],
172172
[sg.Text(i18n("输出设备/Output Device")),sg.Combo(output_devices,key='sg_output_device',default_value=output_devices[sd.default.device[1]])]
173-
],title=i18n('音频设备(请使用同种类驱动)/Audio Devices'))
173+
],title=i18n("音频设备(请使用同种类驱动)/Audio Devices"))
174174
],
175175
[
176176
sg.Frame(layout=[
177-
[sg.Text(i18n('响应阈值/Silence Threhold')),sg.Slider(range=(-60,0),key='threhold',resolution=1,orientation='h',default_value=-30)],
177+
[sg.Text(i18n("响应阈值/Silence Threhold")),sg.Slider(range=(-60,0),key='threhold',resolution=1,orientation='h',default_value=-30)],
178178
[sg.Text(i18n("音调设置/Pitch Offset")),sg.Slider(range=(-24,24),key='pitch',resolution=1,orientation='h',default_value=12)]
179179

180-
],title=i18n('常规设置/Common')),
180+
],title=i18n("常规设置/Common")),
181181
sg.Frame(layout=[
182-
[sg.Text(i18n('采样长度/Sample Length')),sg.Slider(range=(0.1,3.0),key='block_time',resolution=0.1,orientation='h',default_value=1.0)],
183-
[sg.Text(i18n('淡入淡出长度/Crossfade Length')),sg.Slider(range=(0.01,0.15),key='crossfade_length',resolution=0.01,orientation='h',default_value=0.08)],
184-
[sg.Text(i18n('额外推理时长/Extra Length')),sg.Slider(range=(0.05,3.00),key='extra_time',resolution=0.01,orientation='h',default_value=0.05)]
185-
],title=i18n('性能设置/Performance'))
182+
[sg.Text(i18n("采样长度/Sample Length")),sg.Slider(range=(0.1,3.0),key='block_time',resolution=0.1,orientation='h',default_value=1.0)],
183+
[sg.Text(i18n("淡入淡出长度/Crossfade Length")),sg.Slider(range=(0.01,0.15),key='crossfade_length',resolution=0.01,orientation='h',default_value=0.08)],
184+
[sg.Text(i18n("额外推理时长/Extra Length")),sg.Slider(range=(0.05,3.00),key='extra_time',resolution=0.01,orientation='h',default_value=0.05)]
185+
],title=i18n("性能设置/Performance"))
186186
],
187-
[sg.Button(i18n('开始音频转换'),key='start_vc'),sg.Button(i18n('停止音频转换'),key='stop_vc')]
187+
[sg.Button(i18n("开始音频转换"),key='start_vc'),sg.Button(i18n("停止音频转换"),key='stop_vc')]
188188
]
189189

190-
self.window=sg.Window('RVC - GUI',layout=layout)
190+
self.window=sg.Window("RVC - GUI",layout=layout)
191191
self.event_handler()
192192

193193
def event_handler(self):
@@ -325,6 +325,4 @@ def set_devices(self,input_device,output_device):
325325
sd.default.device[0]=input_device_indices[input_devices.index(input_device)]
326326
sd.default.device[1]=output_device_indices[output_devices.index(output_device)]
327327
print("input device:"+str(sd.default.device[0])+":"+str(input_device))
328-
print("output device:"+str(sd.default.device[1])+":"+str(output_device))
329-
i18n = language_gui.I18nAuto()
330-
gui=GUI()
328+
print("output device:"+str(sd.default.device[1])+":"+str(output_device))

0 commit comments

Comments
 (0)