From 02598691693a872b89775812be80a2ca68e57d25 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:05:42 +0900 Subject: [PATCH] fix(YouTube - Translations): Patch exception thrown when the patch option `String resources to keep` is empty https://github.com/inotia00/ReVanced_Extended/issues/2778 --- .../shared/translations/BaseTranslationsPatch.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/translations/BaseTranslationsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/translations/BaseTranslationsPatch.kt index a58bccf92..82ca978e6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/translations/BaseTranslationsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/translations/BaseTranslationsPatch.kt @@ -118,7 +118,12 @@ fun ResourcePatchContext.baseTranslationsPatch( if (!isYouTube) return filteredAppLanguages = filteredAppLanguages.map { language -> - language.subSequence(0,2).toString().uppercase() + val hyphenIndex = language.indexOf("-") - 1 + if (hyphenIndex > 2) { + language.subSequence(0, hyphenIndex).toString().uppercase() + } else { + language.uppercase() + } }.toHashSet().toTypedArray() // Remove unselected app languages from RVX Settings @@ -140,7 +145,9 @@ fun ResourcePatchContext.baseTranslationsPatch( val item = itemNodes.item(j) as? Element ?: continue val text = item.textContent val length = text.length - if (!text.endsWith("DEFAULT") && text.subSequence(length - 2, length) !in filteredAppLanguages) { + if (!text.endsWith("DEFAULT") && + length >= 2 && + text.subSequence(length - 2, length) !in filteredAppLanguages) { nodesToRemove.add(item) } }