[Android] Add a language equivalency for preferred subtitle resolution

Nicolas Pomepuy git at videolan.org
Tue Dec 19 16:26:24 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Dec 14 09:16:53 2023 +0100| [370353c7ab22a85a209de0b76a711950e466899a] | committer: Duncan McNamara

Add a language equivalency for preferred subtitle resolution

Fixes #2987

> https://code.videolan.org/videolan/vlc-android/commit/370353c7ab22a85a209de0b76a711950e466899a
---

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt        | 5 +++--
 application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt  | 9 +++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 2ca471aef1..c8570ed906 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -117,6 +117,7 @@ import org.videolan.vlc.repository.SlaveRepository
 import org.videolan.vlc.util.*
 import org.videolan.vlc.util.FileUtils
 import org.videolan.vlc.util.FileUtils.getUri
+import org.videolan.vlc.util.LocaleUtil.localeEquivalent
 import org.videolan.vlc.viewmodels.BookmarkModel
 import org.videolan.vlc.viewmodels.PlaylistModel
 import java.io.File
@@ -1442,9 +1443,9 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                                     service.spuTracks?.iterator()?.let { spuTracks ->
                                         while (spuTracks.hasNext()) {
                                             val next = spuTracks.next()
-                                            val realTrack = allTracks.find {it.id.toString() == next.getId() }
+                                            val realTrack = allTracks.find { it.id.toString() == next.getId() }
                                             if (LocaleUtil.getLocaleFromVLC(realTrack?.language
-                                                            ?: "") == preferredSpuLang) {
+                                                            ?: "") in preferredSpuLang.localeEquivalent()) {
                                                 preferredTrack = next.getId()
                                                 break
                                             }
diff --git a/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt b/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
index e5eca49e3a..c1f200ab0b 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
@@ -28,12 +28,12 @@ import com.squareup.moshi.Json
 import com.squareup.moshi.JsonAdapter
 import com.squareup.moshi.Moshi
 import com.squareup.moshi.Types
-import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.libvlc.MediaPlayer
+import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.resources.AppContextProvider
 import org.videolan.tools.firstLetterUppercase
 import org.videolan.vlc.R
-import java.util.*
+import java.util.Locale
 
 /**
  * This is a temporary workaround to translate [IMedia.Track.language] sent by libvlc as a string to a real locale.
@@ -113,6 +113,11 @@ object LocaleUtil {
 
     }
 
+    fun String.localeEquivalent():Array<String> = when (this.lowercase()) {
+        "in" -> arrayOf("in", "id")
+        else -> arrayOf(this)
+    }
+
     /**
      * VLC locale object
      * @param language: the language VLC uses



More information about the Android mailing list