Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple localization fixes #3098

Merged
merged 11 commits into from
Feb 21, 2020
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gitignore
/build
app.iml
B0pol marked this conversation as resolved.
Show resolved Hide resolved
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ public void handleResult(@NonNull StreamInfo info) {
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void handleResult(@NonNull ChannelInfo result) {

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void onCreate(Bundle savedInstanceState) {

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
isSuggestionsEnabled = preferences.getBoolean(getString(R.string.show_search_suggestions_key), true);
contentCountry = preferences.getString(getString(R.string.content_country_key), getString(R.string.default_country_value));
contentCountry = preferences.getString(getString(R.string.content_country_key), getString(R.string.default_localization_key));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private String getStreamInfoDetailLine(final StreamInfoItem infoItem) {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Vector;

Expand Down Expand Up @@ -377,8 +378,12 @@ private String getUserActionString(UserAction userAction) {
}

private String getContentLangString() {
B0pol marked this conversation as resolved.
Show resolved Hide resolved
return PreferenceManager.getDefaultSharedPreferences(this)
String contentLanguage = PreferenceManager.getDefaultSharedPreferences(this)
.getString(this.getString(R.string.content_country_key), "none");
if (contentLanguage.equals(getString(R.string.default_localization_key))) {
contentLanguage = Locale.getDefault().toString();
}
return contentLanguage;
}

private String getOsString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.schabi.newpipe.settings;

import android.content.SharedPreferences;
import android.content.res.Resources;
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;

Expand All @@ -21,6 +22,24 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//initializing R.array.seek_duration_description to display the translation of seconds
Resources res = getResources();
String[] durationsValues = res.getStringArray(R.array.seek_duration_value);
String[] durationsDescriptions = res.getStringArray(R.array.seek_duration_description);
int currentDurationValue;
for (int i = 0; i < durationsDescriptions.length; i++) {
currentDurationValue = Integer.parseInt(durationsValues[i]) / 1000;
try {
durationsDescriptions[i] = String.format(
res.getQuantityString(R.plurals.dynamic_seek_duration_description, currentDurationValue),
currentDurationValue);
} catch (Resources.NotFoundException ignored) {
//if this happens, the translation is missing, and the english string will be displayed instead
}
}
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
Expand Down
37 changes: 22 additions & 15 deletions app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

public class Localization {

private static PrettyTime prettyTime;
private static final String DOT_SEPARATOR = " • ";
private static PrettyTime prettyTime;

private Localization() {
}
Expand Down Expand Up @@ -83,22 +83,28 @@ public static String concatenateStrings(final List<String> strings) {
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(final Context context) {
final String contentLanguage = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.content_language_key), context.getString(R.string.default_language_value));
.getString(context.getString(R.string.content_language_key), context.getString(R.string.default_localization_key));
if (contentLanguage.equals(context.getString(R.string.default_localization_key))) {
return org.schabi.newpipe.extractor.localization.Localization.fromLocale(Locale.getDefault());
}
return org.schabi.newpipe.extractor.localization.Localization.fromLocalizationCode(contentLanguage);
}

public static ContentCountry getPreferredContentCountry(final Context context) {
final String contentCountry = PreferenceManager
.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.content_country_key), context.getString(R.string.default_country_value));
.getString(context.getString(R.string.content_country_key), context.getString(R.string.default_localization_key));
if (contentCountry.equals(context.getString(R.string.default_localization_key))) {
return new ContentCountry(Locale.getDefault().getCountry());
}
return new ContentCountry(contentCountry);
}

public static Locale getPreferredLocale(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

String languageCode = sp.getString(context.getString(R.string.content_language_key),
context.getString(R.string.default_language_value));
context.getString(R.string.default_localization_key));

try {
if (languageCode.length() == 2) {
Expand All @@ -114,8 +120,7 @@ public static Locale getPreferredLocale(Context context) {
}

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);
}

Expand All @@ -132,14 +137,14 @@ public static String localizeViewCount(Context context, long viewCount) {
return getQuantity(context, R.plurals.views, R.string.no_views, viewCount, localizeNumber(context, viewCount));
}

public static String localizeSubscribersCount(Context context, long subscriberCount) {
Stypox marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand All @@ -156,7 +161,7 @@ public static String listeningCount(Context context, long listeningCount) {
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));
}

Expand Down Expand Up @@ -215,7 +220,9 @@ private static PrettyTime getPrettyTime() {
}

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) {
Expand All @@ -226,10 +233,10 @@ private static void changeAppLanguage(Locale loc, Resources res) {
}

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")) {
if (lang.equals(context.getString(R.string.default_localization_key))) {
loc = Locale.getDefault();
} else if (lang.matches(".*-.*")) {
//to differentiate different versions of the language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static int getIcon(int serviceId) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</LinearLayout>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout-large-land/activity_main_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_player_queue_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</LinearLayout>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/player_popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,13 @@
<string name="clear_download_history">Forviŝi la historion de elŝutoj</string>
<string name="delete_downloaded_files">Forviŝi elŝutitajn dosierojn</string>
<string name="deleted_downloads">%1$s elŝutoj forviŝitaj</string>
<string name="videos_string">Filmetoj</string>
<string name="permission_display_over_apps">Doni la permeson por afiŝiĝi supre aliaj apoj</string>
<string name="app_language_title">Lingvo de la apo</string>
<string name="systems_language">Sistemnormo</string>
<string name="subtitle_activity_recaptcha">Premu « Finita » kiam solvita</string>
<string name="recaptcha_done_button">Finita</string>
<plurals name="dynamic_seek_duration_description">
<item quantity="other">%s sekundoj</item>
</plurals>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@
<plurals name="subscribers">
<item quantity="one">%s подписчик</item>
<item quantity="few">%s подписчика</item>
<item quantity="other">%s подписчиков</item>
<item quantity="many">%s подписчиков</item>
</plurals>
<string name="no_views">Нет просмотров</string>
<plurals name="views">
<item quantity="one">%s просмотр</item>
<item quantity="few">%s просмотра</item>
<item quantity="other">%s просмотров</item>
<item quantity="many">%s просмотров</item>
</plurals>
<string name="no_videos">Нет видео</string>
<plurals name="videos">
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<string name="seek_duration_key" translatable="false">seek_duration</string>
<string name="seek_duration_default_value" translatable="false">10000</string>
<string-array name="seek_duration_description" translatable="false">
<!-- They are overridden in VideoAudioSettingsFragment.java if the translation
(dynamic_seek_duration_description) exist. Otherwise this array is picked-->
<item>5 seconds</item>
<item>10 seconds</item>
<item>15 seconds</item>
Expand Down Expand Up @@ -161,8 +163,6 @@
<string name="show_comments_key" translatable="false">show_comments</string>
<string name="stream_info_selected_tab_key" translatable="false">stream_info_selected_tab</string>
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>
<string name="default_language_value">en</string>
<string name="default_country_value">GB</string>
<string name="content_language_key" translatable="false">content_language</string>
<string name="peertube_instance_setup_key" translatable="false">peertube_instance_setup</string>
<string name="peertube_selected_instance_key" translatable="false">peertube_selected_instance</string>
Expand Down Expand Up @@ -265,8 +265,11 @@
<string name="update_app_key" translatable="false">update_app_key</string>
<string name="update_pref_screen_key" translatable="false">update_pref_screen_key</string>

<!-- Localizations -->
<string name="default_localization_key" translatable="false">system</string>
<!-- alternatively, load these from some local android data store -->
<string-array name="language_codes" translatable="false">
<item>@string/default_localization_key</item>
<item>af</item>
<item>az</item>
<item>id</item>
Expand Down Expand Up @@ -346,6 +349,7 @@
<item>ko</item>
</string-array>
<string-array name="language_names" translatable="false">
<item>@string/systems_language</item>
<item>Afrikaans</item>
<item>Azərbaycan</item>
<item>Bahasa Indonesia</item>
Expand Down Expand Up @@ -427,6 +431,7 @@


<string-array name="country_names" translatable="false">
<item>@string/systems_language</item>
<item>Afghanistan</item>
<item>Aland Islands</item>
<item>Albania</item>
Expand Down Expand Up @@ -677,6 +682,7 @@
</string-array>

<string-array name="country_codes" translatable="false">
<item>@string/default_localization_key</item>
<item>AF</item>
<item>AX</item>
<item>AL</item>
Expand Down Expand Up @@ -928,7 +934,7 @@

<!--The next two arrays are set to change the app language-->
<string-array name="app_language_code" translatable="false">
<item>system</item>
<item>@string/default_localization_key</item>
<item>ar</item>
<item>az</item>
<item>ast</item>
Expand Down
Loading