Browse Source

Prepend the system locales to the locales used for default audio and default subtitles

Fixes #3179
merge-requests/1594/merge
Nicolas Pomepuy 1 year ago
committed by Duncan McNamara
parent
commit
199929eaa8
  1. 4
      application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt
  2. 3
      application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesSubtitles.kt
  3. 34
      application/tools/src/main/java/org/videolan/tools/LocaleUtils.kt
  4. 4
      application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAudio.kt
  5. 3
      application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesSubtitles.kt

4
application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt

@ -43,9 +43,9 @@ import org.videolan.libvlc.util.AndroidUtil
import org.videolan.resources.VLCInstance
import org.videolan.tools.AUDIO_DUCKING
import org.videolan.tools.LocaleUtils
import org.videolan.tools.LocaleUtils.getLocales
import org.videolan.tools.RESUME_PLAYBACK
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.VlcMigrationHelper
@ -213,7 +213,7 @@ class PreferencesAudio : BasePreferenceFragment(), SharedPreferences.OnSharedPre
}
private fun prepareLocaleList() {
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference))
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference), activity.getLocales())
preferredAudioTrack.entries = localePair.localeEntries
preferredAudioTrack.entryValues = localePair.localeEntryValues
}

3
application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesSubtitles.kt

@ -43,6 +43,7 @@ import org.videolan.television.ui.COLOR_PICKER_SELECTED_COLOR
import org.videolan.television.ui.COLOR_PICKER_TITLE
import org.videolan.television.ui.ColorPickerActivity
import org.videolan.tools.LocaleUtils
import org.videolan.tools.LocaleUtils.getLocales
import org.videolan.tools.Settings
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
@ -255,7 +256,7 @@ class PreferencesSubtitles : BasePreferenceFragment(), SharedPreferences.OnShare
private fun prepareLocaleList() {
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference))
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference), activity.getLocales())
preferredSubtitleTrack.entries = localePair.localeEntries
preferredSubtitleTrack.entryValues = localePair.localeEntryValues
}

34
application/tools/src/main/java/org/videolan/tools/LocaleUtils.kt

@ -4,13 +4,31 @@ import android.annotation.TargetApi
import android.content.Context
import android.content.ContextWrapper
import android.os.Build
import java.util.*
import kotlin.collections.ArrayList
import java.util.Locale
import java.util.TreeMap
object LocaleUtils {
fun Context.getLocales(): List<Locale> =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
ArrayList<Locale>().apply {
for (i in 0..resources.configuration.locales.size() - 1)
add(resources.configuration.locales[i])
} else
listOf(resources.configuration.locale)
/**
* Get locales used in project (the one the app has translations for), prepend the given locales if provided
*
* @param projectLocales project locales
* @param defaultLocaleText the default string to use for the default locale
* @param localesToPrepend locales to prepend to the list of project locales
* @return a [LocalePair] containing the entries and entry values for the list of locales
*/
fun getLocalesUsedInProject(
projectLocales: Array<String>,
defaultLocaleText: String
defaultLocaleText: String,
localesToPrepend: List<Locale>? = null
): LocalePair {
val localesEntry = arrayOfNulls<String>(projectLocales.size)
@ -47,6 +65,16 @@ object LocaleUtils {
i++
}
localesToPrepend?.reversed()?.forEach {
if (finalLocaleEntryValues.contains(it.language)) {
val indexToRemove = finalLocaleEntryValues.indexOf(it.language)
finalLocaleEntryValues.removeAt(indexToRemove)
finalLocaleEntries.removeAt(indexToRemove)
}
finalLocaleEntries.add(1, it.getDisplayLanguage(it).firstLetterUppercase())
finalLocaleEntryValues.add(1, it.language)
}
return LocalePair(finalLocaleEntries.toTypedArray(), finalLocaleEntryValues.toTypedArray())
}

4
application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAudio.kt

@ -43,9 +43,9 @@ import org.videolan.resources.AndroidDevices
import org.videolan.resources.VLCInstance
import org.videolan.tools.AUDIO_DUCKING
import org.videolan.tools.LocaleUtils
import org.videolan.tools.LocaleUtils.getLocales
import org.videolan.tools.RESUME_PLAYBACK
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.VlcMigrationHelper
@ -196,7 +196,7 @@ class PreferencesAudio : BasePreferenceFragment(), SharedPreferences.OnSharedPre
}
private fun prepareLocaleList() {
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference))
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference), requireActivity().getLocales())
preferredAudioTrack.entries = localePair.localeEntries
preferredAudioTrack.entryValues = localePair.localeEntryValues
}

3
application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesSubtitles.kt

@ -34,6 +34,7 @@ import com.jaredrummler.android.colorpicker.ColorPreferenceCompat
import kotlinx.coroutines.launch
import org.videolan.resources.VLCInstance
import org.videolan.tools.LocaleUtils
import org.videolan.tools.LocaleUtils.getLocales
import org.videolan.tools.Settings
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
@ -202,7 +203,7 @@ class PreferencesSubtitles : BasePreferenceFragment(), SharedPreferences.OnShare
}
private fun prepareLocaleList() {
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference))
val localePair = LocaleUtils.getLocalesUsedInProject(BuildConfig.TRANSLATION_ARRAY, getString(R.string.no_track_preference), requireActivity().getLocales())
preferredSubtitleTrack.entries = localePair.localeEntries
preferredSubtitleTrack.entryValues = localePair.localeEntryValues
}

Loading…
Cancel
Save