Skip to content

VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.

fix(mobile): bundle locale resources with explicit UTF-8

debpalashb2228477a259
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8be3b237b..35310fbd7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -77,7 +77,7 @@ metadata and the backend fallback mirror it.
### CI
-- Native licence notices keep their pinned hashes on Windows checkouts (#2969)
+- Phone build resources keep notice hashes and localized text intact on Windows (#2969)
- New `mobile-release` workflow builds signed Android and iOS apps and drafts a GitHub prerelease with the APK, AAB and IPAs (#2969)
- The `mobile` workflow builds the pinned on-device runtimes for both apps (#2969)
- Interactive release helper: pick stable or beta, draft or publish, and confirm by typing the tag (`scripts/release.py`) (#3187)
diff --git a/mobile/ios/scripts/prepare_resources.py b/mobile/ios/scripts/prepare_resources.py
index 1c3508952..3b00da0c0 100644
--- a/mobile/ios/scripts/prepare_resources.py
+++ b/mobile/ios/scripts/prepare_resources.py
@@ -27,7 +27,7 @@ def prepare_brand_assets(output):
artwork = output / "HomeArtwork.imageset"
artwork.mkdir(parents=True, exist_ok=True)
subprocess.run(["sips", "-s", "format", "png", str(ROOT / "electron/public/signal-field.webp"), "--out", str(artwork / "artwork.png")], check=True, stdout=subprocess.DEVNULL)
- (artwork / "Contents.json").write_text(json.dumps({"images": [{"filename": "artwork.png", "idiom": "universal"}], "info": {"version": 1, "author": "xcode"}}))
+ (artwork / "Contents.json").write_text(json.dumps({"images": [{"filename": "artwork.png", "idiom": "universal"}], "info": {"version": 1, "author": "xcode"}}), encoding="utf-8")
def merge(base, addition):
@@ -46,7 +46,7 @@ def lookup(catalog, key):
def validate_native_notices(directory, pins):
- manifest = json.loads((directory / "sources.json").read_text())
+ manifest = json.loads((directory / "sources.json").read_text(encoding="utf-8"))
expected = {"sherpa-onnx", "omnivoice.cpp", "omnivoice-ggml", "llama.cpp", "llama-ggml",
"espeak-ng-for-piper", "piper-phonemize", "kaldi-native-fbank", "kissfft",
"kaldi-decoder", "kaldifst", "openfst", "simple-sentencepiece", "json", "hclust-cpp", "eigen", "onnxruntime"}
@@ -82,7 +82,7 @@ def build_number(value):
def prepare(output, info):
output.mkdir(parents=True, exist_ok=True)
legal = IOS / "VoiceStudio/Resources/NativeLicences"
- validate_native_notices(legal,json.loads((ROOT / "mobile/native/pins.json").read_text()))
+ validate_native_notices(legal,json.loads((ROOT / "mobile/native/pins.json").read_text(encoding="utf-8")))
shutil.copytree(legal,output / "NativeLicences",dirs_exist_ok=True)
notices = ROOT / "mobile/native/ios/build/xcframeworks/Notices"
if notices.is_dir():
@@ -91,19 +91,19 @@ def prepare(output, info):
catalogs.mkdir(exist_ok=True)
source = ROOT / "electron/src/renderer/src/i18n/locales"
shutil.copy2(ROOT / "electron/src/shared/languages.json", catalogs / "languages.json")
- code_source = (ROOT / "electron/src/shared/utils/languages.js").read_text()
+ code_source = (ROOT / "electron/src/shared/utils/languages.js").read_text(encoding="utf-8")
codes = {label: code for code, label in re.findall(r"\{ code: '([^']+)', label: '([^']+)' \}", code_source)}
if not codes:
raise ValueError("Desktop LANG_CODES format changed")
- (catalogs / "language-codes.json").write_text(json.dumps(codes, ensure_ascii=True))
+ (catalogs / "language-codes.json").write_text(json.dumps(codes, ensure_ascii=True), encoding="utf-8")
model_catalogue = ROOT / "mobile/contract/models.json"
if not model_catalogue.is_file():
raise ValueError("Generate mobile/contract/models.json before building the app")
shutil.copy2(model_catalogue, catalogs / "models.json")
- english = json.loads((source / "en.json").read_text())
+ english = json.loads((source / "en.json").read_text(encoding="utf-8"))
additions = sorted((ROOT / "mobile/contract").glob("strings*.en.json"))
for path in additions:
- merge(english, json.loads(path.read_text()))
+ merge(english, json.loads(path.read_text(encoding="utf-8")))
shutil.copy2(path, catalogs / path.name)
permissions = {
"CFBundleDisplayName": ("mobile.ios.app_name",),
@@ -113,14 +113,14 @@ def prepare(output, info):
}
for path in sorted(source.glob("*.json")):
shutil.copy2(path, catalogs / path.name)
- locale = json.loads(path.read_text())
+ locale = json.loads(path.read_text(encoding="utf-8"))
localized = output / (path.stem + ".lproj")
localized.mkdir(exist_ok=True)
# JSON string syntax provides the escaping required by .strings files.
descriptions = {field: "\n".join(lookup(locale, key) or lookup(english, key) for key in keys) for field, keys in permissions.items()}
lines = [f'{json.dumps(k)} = {json.dumps(v, ensure_ascii=True)};' for k, v in descriptions.items()]
- (localized / "InfoPlist.strings").write_text("\n".join(lines) + "\n")
- version = json.loads((ROOT / "package.json").read_text())["version"]
+ (localized / "InfoPlist.strings").write_text("\n".join(lines) + "\n", encoding="utf-8")
+ version = json.loads((ROOT / "package.json").read_text(encoding="utf-8"))["version"]
data = plistlib.loads((IOS / "VoiceStudio/Info.plist").read_bytes())
data["CFBundleShortVersionString"] = marketing_version(version)
data["CFBundleVersion"] = build_number(os.environ.get("VOICESTUDIO_IOS_BUILD_NUMBER", "1"))
diff --git a/tests/test_ios_testflight.py b/tests/test_ios_testflight.py
index 437a2a3c0..b58ac2d5d 100644
--- a/tests/test_ios_testflight.py
+++ b/tests/test_ios_testflight.py
@@ -37,6 +37,24 @@ def test_build_number_comes_from_the_environment(tmp_path, monkeypatch):
assert prepare_resources.re.fullmatch(r"\d+\.\d+\.\d+", info["CFBundleShortVersionString"])
+def test_resource_catalogs_keep_utf8_under_a_windows_default_codec(tmp_path, monkeypatch):
+ read_text, write_text = Path.read_text, Path.write_text
+
+ def legacy_read(path, encoding=None, errors=None):
+ return read_text(path, encoding=encoding or "cp1252", errors=errors)
+
+ def legacy_write(path, data, encoding=None, errors=None):
+ return write_text(path, data, encoding=encoding or "cp1252", errors=errors)
+
+ monkeypatch.setattr(Path, "read_text", legacy_read)
+ monkeypatch.setattr(Path, "write_text", legacy_write)
+ prepare_resources.prepare(tmp_path / "bundle", tmp_path / "Info.plist")
+ french = prepare_resources.json.loads(read_text(ROOT / "electron/src/renderer/src/i18n/locales/fr.json", encoding="utf-8"))
+ expected = prepare_resources.json.dumps(french["permissions"]["microphone_why"])[1:-1]
+ actual = (tmp_path / "bundle/fr.lproj/InfoPlist.strings").read_bytes().decode("utf-8")
+ assert expected in actual
+
+
@pytest.mark.parametrize("value", ["", "1.2.3.4", "12a"])
def test_build_number_rejects_values_app_store_connect_refuses(value):
with pytest.raises(ValueError):