From f089cd027ebe1dc6088e3d7427e9d1c78352a815 Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 14 Feb 2020 18:19:35 +0100 Subject: [PATCH] Multiple localization fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the extractor PR, fixes title & description shown in the wrong language. Fixed views / spectators counts possibly in the wrong language Fixed live spectators not showing full count on detail page Fixed LIVE shown on players, it shows translated instead Fixed Videos string in search / three dots not available in Weblate (because it was videos, but there already was a plural string named videos, in Weblate) Subscriber count is always giving the short count. We can't get exact number since this YouTube update: https://support.google.com/youtube/thread/6543166 But only short count (B, M, k), so showing full number, eg for 1.9M: 1,900,000, is wrong because the number could be 1,923,490 or 1,897,789… Added a « sytem default » option to content language and country language selector. It's the one selected by default (not en-GB anymore then), and correspond to the language of the system / country of the system By system I mean phone, tablet, TV… Fixed russian showing - before time ago (eg 19hrs ago) This is a workaround fix, I opened an issue on prettytime library repo. Fixed russian plurals: other was used instead of many for videos and subscribers Fixed seek_duration english only --- app/build.gradle | 2 +- .../fragments/detail/VideoDetailFragment.java | 2 +- .../list/channel/ChannelFragment.java | 2 +- .../holder/StreamInfoItemHolder.java | 2 +- .../settings/VideoAudioSettingsFragment.java | 12 +++++++- .../org/schabi/newpipe/util/Localization.java | 29 ++++++++++++------- .../schabi/newpipe/util/ServiceHelper.java | 2 +- .../activity_player_queue_control.xml | 3 +- .../activity_main_player.xml | 3 +- .../main/res/layout/activity_main_player.xml | 3 +- .../layout/activity_player_queue_control.xml | 3 +- app/src/main/res/layout/player_popup.xml | 3 +- app/src/main/res/values-eo/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 4 +-- app/src/main/res/values/settings_keys.xml | 22 ++++++++------ app/src/main/res/values/strings.xml | 7 ++--- 16 files changed, 59 insertions(+), 42 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5da8c9ff0..10afbef31 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:9112a10' + implementation 'com.github.B0pol:NewPipeExtractor:a9c6beec1434f4edd4197fb655e5327bae94cc92' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 3c594bdfa..7dd98003a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1074,7 +1074,7 @@ public class VideoDetailFragment if (info.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) { videoCountView.setText(Localization.listeningCount(activity, info.getViewCount())); } else if (info.getStreamType().equals(StreamType.LIVE_STREAM)) { - videoCountView.setText(Localization.watchingCount(activity, info.getViewCount())); + videoCountView.setText(Localization.localizeWatchingCount(activity, info.getViewCount())); } else { videoCountView.setText(Localization.localizeViewCount(activity, info.getViewCount())); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index c20ff0fc2..7b7a08a48 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -370,7 +370,7 @@ public class ChannelFragment extends BaseListInfoFragment { headerSubscribersTextView.setVisibility(View.VISIBLE); if (result.getSubscriberCount() >= 0) { - headerSubscribersTextView.setText(Localization.localizeSubscribersCount(activity, result.getSubscriberCount())); + headerSubscribersTextView.setText(Localization.shortSubscriberCount(activity, result.getSubscriberCount())); } else { headerSubscribersTextView.setText(R.string.subscribers_count_not_available); } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java index c48934d10..1dfbbca3f 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java @@ -60,7 +60,7 @@ public class StreamInfoItemHolder extends StreamMiniInfoItemHolder { if (infoItem.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) { viewsAndDate = Localization.listeningCount(itemBuilder.getContext(), infoItem.getViewCount()); } else if (infoItem.getStreamType().equals(StreamType.LIVE_STREAM)) { - viewsAndDate = Localization.watchingCount(itemBuilder.getContext(), infoItem.getViewCount()); + viewsAndDate = Localization.shortWatchingCount(itemBuilder.getContext(), infoItem.getViewCount()); } else { viewsAndDate = Localization.shortViewCount(itemBuilder.getContext(), infoItem.getViewCount()); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index 7bb931309..21560ee55 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -4,9 +4,9 @@ import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.provider.Settings; -import android.view.View; import androidx.annotation.Nullable; +import androidx.preference.ListPreference; import com.google.android.material.snackbar.Snackbar; @@ -21,6 +21,16 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + String[] durationsDescriptions = getResources().getStringArray(R.array.seek_duration_description); + String[] durationsValues = getResources().getStringArray(R.array.seek_duration_value); + int currentDurationValue; + for (int i = 0; i < durationsDescriptions.length; i++) { + currentDurationValue = Integer.parseInt(durationsValues[i]) / 1000; + durationsDescriptions[i] = String.format(durationsDescriptions[i], currentDurationValue); + } + ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key)); + durations.setEntries(durationsDescriptions); + listener = (sharedPreferences, s) -> { // on M and above, if user chooses to minimise to popup player on exit and the app doesn't have diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 6149118cc..b24298f4e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -48,8 +48,8 @@ import java.util.Locale; public class Localization { - private static PrettyTime prettyTime; private static final String DOT_SEPARATOR = " • "; + private static PrettyTime prettyTime; private Localization() { } @@ -84,6 +84,9 @@ public class Localization { final String contentLanguage = PreferenceManager .getDefaultSharedPreferences(context) .getString(context.getString(R.string.content_language_key), context.getString(R.string.default_language_value)); + if (contentLanguage.equals("system")) { + return org.schabi.newpipe.extractor.localization.Localization.fromLocale(Locale.getDefault()); + } return org.schabi.newpipe.extractor.localization.Localization.fromLocalizationCode(contentLanguage); } @@ -91,6 +94,9 @@ public class Localization { final String contentCountry = PreferenceManager .getDefaultSharedPreferences(context) .getString(context.getString(R.string.content_country_key), context.getString(R.string.default_country_value)); + if (contentCountry.equals("system")) { + return new ContentCountry(Locale.getDefault().getCountry()); + } return new ContentCountry(contentCountry); } @@ -114,8 +120,7 @@ public class Localization { } public static String localizeNumber(Context context, long number) { - Locale locale = getPreferredLocale(context); - NumberFormat nf = NumberFormat.getInstance(locale); + NumberFormat nf = NumberFormat.getInstance(getAppLocale(context)); return nf.format(number); } @@ -132,14 +137,14 @@ public class Localization { return getQuantity(context, R.plurals.views, R.string.no_views, viewCount, localizeNumber(context, viewCount)); } - public static String localizeSubscribersCount(Context context, long subscriberCount) { - return getQuantity(context, R.plurals.subscribers, R.string.no_subscribers, subscriberCount, localizeNumber(context, subscriberCount)); - } - public static String localizeStreamCount(Context context, long streamCount) { return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, localizeNumber(context, streamCount)); } + public static String localizeWatchingCount(Context context, long watchingCount) { + return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, localizeNumber(context, watchingCount)); + } + public static String shortCount(Context context, long count) { if (count >= 1000000000) { return Long.toString(count / 1000000000) + context.getString(R.string.short_billion); @@ -156,7 +161,7 @@ public class Localization { return getQuantity(context, R.plurals.listening, R.string.no_one_listening, listeningCount, shortCount(context, listeningCount)); } - public static String watchingCount(Context context, long watchingCount) { + public static String shortWatchingCount(Context context, long watchingCount) { return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, shortCount(context, watchingCount)); } @@ -215,7 +220,9 @@ public class Localization { } public static String relativeTime(Calendar calendarTime) { - return getPrettyTime().formatUnrounded(calendarTime); + String time = getPrettyTime().formatUnrounded(calendarTime); + return time.startsWith("-") ? time.substring(1) : time; + //workaround fix for russian showing -1 day ago, -19hrs ago… } private static void changeAppLanguage(Locale loc, Resources res) { @@ -226,8 +233,8 @@ public class Localization { } public static Locale getAppLocale(Context context) { - SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context); - String lang = prefs.getString("app_language_key", "en"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + String lang = prefs.getString(context.getString(R.string.app_language_key), "en"); Locale loc; if (lang.equals("system")) { loc = Locale.getDefault(); diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index 8929cc654..6726e4cfc 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -44,7 +44,7 @@ public class ServiceHelper { public static String getTranslatedFilterString(String filter, Context c) { switch (filter) { case "all": return c.getString(R.string.all); - case "videos": return c.getString(R.string.videos); + case "videos": return c.getString(R.string.videos_string); case "channels": return c.getString(R.string.channels); case "playlists": return c.getString(R.string.playlists); case "tracks": return c.getString(R.string.tracks); diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index 7467a79cf..6468c6784 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -304,10 +304,9 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:gravity="center" - android:text="@string/duration_live_button" + android:text="@string/duration_live" android:textAllCaps="true" android:textColor="?attr/colorAccent" - android:maxLength="4" android:background="?attr/selectableItemBackground" android:visibility="gone"/> diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml index 98017b132..8e11b99f3 100644 --- a/app/src/main/res/layout-large-land/activity_main_player.xml +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -442,10 +442,9 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:gravity="center" - android:text="@string/duration_live_button" + android:text="@string/duration_live" android:textAllCaps="true" android:textColor="@android:color/white" - android:maxLength="4" android:visibility="gone" android:background="?attr/selectableItemBackground" tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> diff --git a/app/src/main/res/layout/activity_main_player.xml b/app/src/main/res/layout/activity_main_player.xml index ab9eb8a61..804434456 100644 --- a/app/src/main/res/layout/activity_main_player.xml +++ b/app/src/main/res/layout/activity_main_player.xml @@ -440,10 +440,9 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:gravity="center" - android:text="@string/duration_live_button" + android:text="@string/duration_live" android:textAllCaps="true" android:textColor="@android:color/white" - android:maxLength="4" android:visibility="gone" android:background="?attr/selectableItemBackground" tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> diff --git a/app/src/main/res/layout/activity_player_queue_control.xml b/app/src/main/res/layout/activity_player_queue_control.xml index e113075af..d17a7007a 100644 --- a/app/src/main/res/layout/activity_player_queue_control.xml +++ b/app/src/main/res/layout/activity_player_queue_control.xml @@ -154,10 +154,9 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:gravity="center" - android:text="@string/duration_live_button" + android:text="@string/duration_live" android:textAllCaps="true" android:textColor="?attr/colorAccent" - android:maxLength="4" android:background="?attr/selectableItemBackground" android:visibility="gone"/> diff --git a/app/src/main/res/layout/player_popup.xml b/app/src/main/res/layout/player_popup.xml index 9fbc22145..28c730913 100644 --- a/app/src/main/res/layout/player_popup.xml +++ b/app/src/main/res/layout/player_popup.xml @@ -208,10 +208,9 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:gravity="center_vertical" - android:text="@string/duration_live_button" + android:text="@string/duration_live" android:textAllCaps="true" android:textColor="@android:color/white" - android:maxLength="4" android:visibility="gone" android:background="?attr/selectableItemBackground" tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index 6370c5e0e..469fb9e21 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -537,4 +537,6 @@ Forviŝi la historion de elŝutoj Forviŝi elŝutitajn dosierojn %1$s elŝutoj forviŝitaj + Filmetoj + %s sekundoj \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 807351a52..940d2ef2f 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -201,13 +201,13 @@ %s подписчик %s подписчика - %s подписчиков + %s подписчиков Нет просмотров %s просмотр %s просмотра - %s просмотров + %s просмотров Нет видео diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 1a7d61dae..3a4e7c493 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -31,12 +31,12 @@ seek_duration 10000 - 5 seconds - 10 seconds - 15 seconds - 20 seconds - 25 seconds - 30 seconds + @string/dynamic_seek_duration_description + @string/dynamic_seek_duration_description + @string/dynamic_seek_duration_description + @string/dynamic_seek_duration_description + @string/dynamic_seek_duration_description + @string/dynamic_seek_duration_description 5000 @@ -161,8 +161,8 @@ show_comments stream_info_selected_tab show_hold_to_append - en - GB + system + system content_language peertube_instance_setup peertube_selected_instance @@ -267,6 +267,7 @@ + system af az id @@ -346,6 +347,7 @@ ko + @string/system_default Afrikaans Azərbaycan Bahasa Indonesia @@ -427,6 +429,7 @@ + @string/system_default Afghanistan Aland Islands Albania @@ -677,6 +680,7 @@ + system AF AX AL @@ -993,7 +997,7 @@ zh-tw - @string/systems_language + @string/system_default العربية Azərbaycan dili Asturianu diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dab9bde10..622b43bfd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,7 +140,6 @@ Age restricted content Show age restricted video. Allowing such material is possible from Settings. LIVE - LIVE Downloads Downloads Error report @@ -149,8 +148,7 @@ Channels Playlist Playlists - Videos - Comments + Videos Tracks Users Events @@ -593,5 +591,6 @@ The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible Choose an instance App language - System default + System default + %s seconds