Skip to content

Commit

Permalink
fix(YouTube - Translations): A patch exception is thrown when the `St…
Browse files Browse the repository at this point in the history
…ring resources to keep` option is empty
  • Loading branch information
anddea committed Feb 13, 2025
1 parent 8269299 commit 9032a3f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 9032a3f

Please sign in to comment.