Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: the translate menu is offered only for songs in another language

My-Name-Is-Jeffe276aa2c10a4
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 885032e3..98216d25 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -134,7 +134,7 @@ Shared:
Intelligence's model (iOS 26 where it is on and speaks the language; permissive guardrails for changing
the user's own text, 12 lines a session, greedy and capped at 60 tokens a line, exactly one string a line by a generation schema; Translate retried once, as its first ask can fail while it loads), both in
OnDeviceTranslation.swift, the frameworks weak linked; and by Gemini on the user's own key (Keychain),
- whose prompt and menu item say the lyrics go to Google. Apple Intelligence's lines show and are saved a batch at a time, only lines without a translation are sent, and a batch it turns down is skipped (asking again sends only those lines). Every finished translation is kept by SavedTranslations.m in Caches/Vitrine/Translations, one JSON file a song and language mapping each line's text to its translation, the newest 200, applied when the song's lines are next shown; the Lyrics page's Saved translations row counts them and deletes them. Gemini's reply read and checked on the Mac
+ whose prompt and menu item say the lyrics go to Google. The translate items show only for a song NaturalLanguage finds in another language than the Lyrics page's (or the iPhone's). Apple Intelligence's lines show and are saved a batch at a time, only lines without a translation are sent, and a batch it turns down is skipped (asking again sends only those lines). Every finished translation is kept by SavedTranslations.m in Caches/Vitrine/Translations, one JSON file a song and language mapping each line's text to its translation, the newest 200, applied when the song's lines are next shown; the Lyrics page's Saved translations row counts them and deletes them. Gemini's reply read and checked on the Mac
against harness/lyrics-translation/
LockScreenLyrics/ the line being sung in the system's now playing, and on iOS 26 the lyrics as the lock screen's
full-screen artwork (LyricsArtwork.x): a new artwork ID per line, its 3:4 H.264 clip (the line and the
diff --git a/harness/lyrics/build.sh b/harness/lyrics/build.sh
index fbed510b..9cbed732 100755
--- a/harness/lyrics/build.sh
+++ b/harness/lyrics/build.sh
@@ -24,7 +24,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
$( [ -f "$SRC"/Shared/LyricsMeanings/Meanings.m ] && echo "$SRC"/Shared/LyricsMeanings/Meanings.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m ) \
"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGGlass.m \
$( [ -f "$SRC"/Redesigned/Lyrics/SGRSingButton.m ] && echo "$SRC"/Redesigned/Lyrics/SGRSingButton.m "$SRC"/Redesigned/Kit/SGRGlass.m "$HERE"/../sing/button/sing-stubs.m ) \
- -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreText -framework Foundation -framework Symbols \
+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreText -framework Foundation -framework Symbols -framework NaturalLanguage \
-o "$APP/LyricsHarness"
cp "$HERE"/fixtures/*.ttml "$HERE"/fixtures/*.lrc "$HERE"/fixtures/*.json "$HERE"/fixtures/*.txt "$APP/"
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
index d9a4062c..849990d9 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
@@ -7,6 +7,7 @@
// Apple Music lights such a line, unless the Lyrics page's "Simulate word-by-word timing" asks for
// its estimated words to be swept; lyrics with no timing at all are shown as plain text, every line
// lit, nothing following the clock.
+#import <NaturalLanguage/NaturalLanguage.h>
#import "Core/SGCore.h"
#import "SGRKaraokeView.h"
#import "LyricsText.h"
@@ -1282,7 +1283,8 @@ typedef struct {
CFTimeInterval _stillSince; // when the position stopped moving, 0 while it moves
SGRKaraokeStyle *_style; // how the lines were laid out
BOOL _hasSpoken, _hasTranslation; // whether the song has any line with either
- BOOL _untranslated; // whether a line with words has no translation, which Gemini can fill in
+ BOOL _untranslated; // whether a line with words has no translation, which a translator can fill in
+ BOOL _foreign; // whether the song is in a language other than the one translations are asked in
NSArray<SGKaraokeLine *> *_passedOver; // lines kept for the song that changed nothing here, not looked at again
UIView *_extrasBox; // the Kit's glass and _extras over it, which holds none, so its alpha can fade
UIButton *_extras;
@@ -1722,6 +1724,16 @@ static NSArray<NSString *> *textsOf(NSArray<SGKaraokeLine *> *lines) {
return texts;
}
+// Whether the song's words are mostly in a language other than `language`. A song too short to tell counts as one.
+static BOOL inAnotherLanguage(NSArray<SGKaraokeLine *> *lines, NSString *language) {
+ NSMutableString *words = [NSMutableString string];
+ for (SGKaraokeLine *line in lines) if (hasWords(line)) [words appendFormat:@"%@\n", SGKaraokeLineText(line)];
+ NSString *found = [NLLanguageRecognizer dominantLanguageForString:words];
+ if (!found.length || [found isEqualToString:NLLanguageUndetermined]) return YES;
+ NSString *(^code)(NSString *) = ^NSString *(NSString *tag) { return [tag componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]].firstObject.lowercaseString; };
+ return ![code(found) isEqualToString:code(language)];
+}
+
// Whether a line with words is still without a translation.
static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
for (SGKaraokeLine *line in lines) if (!line.translation.length && hasWords(line)) return YES;
@@ -1739,6 +1751,7 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
_hasSpoken = _hasTranslation = _untranslated = NO;
_plain = SGKaraokeLinesTiming(_lines) == SGKaraokeTimingNone;
if (!_sample) SGLyricsApplySavedTranslation(_track, SGLyricsGeminiLanguage(), _lines);
+ _foreign = inAnotherLanguage(_lines, SGLyricsGeminiLanguage());
NSInteger sungTo = 0; // the top of the song counts as where the singing before the first line ends
for (NSUInteger i = 0; i < count; i++) {
SGKaraokeLine *line = _lines[i];
@@ -1833,7 +1846,9 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
NSString *language = SGLyricsGeminiLanguage();
BOOL gemini = SGGeminiKeySet(), onDevice = SGOnDeviceTranslation.translationAvailable;
BOOL intelligence = [SGOnDeviceTranslation appleIntelligenceAvailable:language];
- BOOL offered = _lines && !_sample && (_hasSpoken || _hasTranslation || gemini || onDevice || intelligence);
+ // A translator is offered only for a song in another language than the one it would translate into.
+ BOOL translatable = _foreign && _untranslated && (gemini || onDevice || intelligence);
+ BOOL offered = _lines && !_sample && (_hasSpoken || _hasTranslation || translatable);
if (!offered) {
_extrasBox.hidden = YES;
[self setNeedsLayout];
@@ -1881,7 +1896,7 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
}
// Also for a song a source translated in part, as Musixmatch's community often has: the rest is filled in.
// Said in each item: whether the song's words stay on the phone.
- if (_untranslated && !translating) {
+ if (translatable && !translating) {
__weak SGRKaraokeView *weakSelf = self;
void (^offer)(NSString *, NSString *, NSString *, SGRTranslator) = ^(NSString *title, NSString *glyph, NSString *subtitle, SGRTranslator translator) {
UIAction *action = [UIAction actionWithTitle:title image:[UIImage systemImageNamed:glyph] identifier:nil
diff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
index b02ce8bb..3c475d9a 100644
--- a/tweak/Sources/Shared/Lyrics/LyricsSettings.m
+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
@@ -39,7 +39,9 @@ SGModRow *SGLockScreenLyricsRow(void) {
SGModRow *SGLyricsTranslationLanguageRow(void) {
SGModRow *row = SGChoiceRow(@"Translation language", nil, SGKeyLyricsTranslationLanguage, SGLyricsTranslationLanguageNames(), 0);
row.choiceFooter = @"A language brings Musixmatch's community translations to lyrics that have none, "
- @"which sends Musixmatch each song's ID. Any shows the first translation the lyrics come with.";
+ @"which sends Musixmatch each song's ID. Any shows the first translation the lyrics come with. "
+ @"It is also the language the lyrics' translate menu translates into, offered only for songs in another one; "
+ @"with Any, the iPhone's own language.";
return row;
}