Skip to content
Snippets Groups Projects
Commit 199929ea authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

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

Fixes #3179
parent c2dd22b6
No related branches found
No related tags found
1 merge request!2176Prepend the system locales to the locales used for default audio and default subtitles
Pipeline #580265 passed with stage
in 5 minutes
......@@ -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
}
......
......@@ -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
}
......
......@@ -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())
}
......
......@@ -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
}
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment