2017-05-08 15:28:33 +02:00
|
|
|
package org.schabi.newpipe.util;
|
2015-12-29 15:35:51 +01:00
|
|
|
|
2020-01-18 10:46:53 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2015-12-29 15:35:51 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2020-01-04 21:38:27 +01:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.content.res.Resources;
|
2015-12-29 15:35:51 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2017-10-13 05:47:12 +02:00
|
|
|
import android.text.TextUtils;
|
2020-01-04 21:38:27 +01:00
|
|
|
import android.util.DisplayMetrics;
|
2020-01-09 09:40:05 +01:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.PluralsRes;
|
|
|
|
import androidx.annotation.StringRes;
|
2015-12-29 15:35:51 +01:00
|
|
|
|
2019-10-28 05:20:06 +01:00
|
|
|
import org.ocpsoft.prettytime.PrettyTime;
|
|
|
|
import org.ocpsoft.prettytime.units.Decade;
|
2017-05-08 15:28:33 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2019-10-28 03:35:51 +01:00
|
|
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
2017-05-08 15:28:33 +02:00
|
|
|
|
2020-02-28 16:59:52 +01:00
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.RoundingMode;
|
2015-12-29 15:35:51 +01:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.NumberFormat;
|
2018-01-28 07:14:38 +01:00
|
|
|
import java.util.Arrays;
|
2019-10-28 05:20:06 +01:00
|
|
|
import java.util.Calendar;
|
2015-12-29 15:35:51 +01:00
|
|
|
import java.util.Date;
|
2018-01-28 07:14:38 +01:00
|
|
|
import java.util.List;
|
2015-12-29 15:35:51 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2020-02-27 23:10:07 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*
|
2015-12-29 15:35:51 +01:00
|
|
|
* Created by chschtsch on 12/29/15.
|
2016-01-05 21:41:55 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) Gregory Arkhipov 2015
|
|
|
|
* Localization.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-29 15:35:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class Localization {
|
|
|
|
|
2019-10-28 05:20:06 +01:00
|
|
|
private static final String DOT_SEPARATOR = " • ";
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
private static PrettyTime prettyTime;
|
2018-01-28 07:14:38 +01:00
|
|
|
|
2016-03-10 10:50:42 +01:00
|
|
|
private Localization() {
|
|
|
|
}
|
|
|
|
|
2020-01-09 15:51:41 +01:00
|
|
|
public static void init(Context context) {
|
|
|
|
initPrettyTime(context);
|
2019-10-28 05:20:06 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 07:14:38 +01:00
|
|
|
@NonNull
|
|
|
|
public static String concatenateStrings(final String... strings) {
|
|
|
|
return concatenateStrings(Arrays.asList(strings));
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static String concatenateStrings(final List<String> strings) {
|
|
|
|
if (strings.isEmpty()) return "";
|
|
|
|
|
|
|
|
final StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
stringBuilder.append(strings.get(0));
|
|
|
|
|
|
|
|
for (int i = 1; i < strings.size(); i++) {
|
|
|
|
final String string = strings.get(i);
|
|
|
|
if (!TextUtils.isEmpty(string)) {
|
|
|
|
stringBuilder.append(DOT_SEPARATOR).append(strings.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
}
|
|
|
|
|
2019-10-28 03:35:51 +01:00
|
|
|
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(final Context context) {
|
|
|
|
final String contentLanguage = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(context)
|
2020-02-15 16:29:46 +01:00
|
|
|
.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))) {
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
return org.schabi.newpipe.extractor.localization.Localization.fromLocale(Locale.getDefault());
|
|
|
|
}
|
2019-10-28 03:35:51 +01:00
|
|
|
return org.schabi.newpipe.extractor.localization.Localization.fromLocalizationCode(contentLanguage);
|
|
|
|
}
|
2018-10-05 16:19:21 +02:00
|
|
|
|
2019-10-28 03:35:51 +01:00
|
|
|
public static ContentCountry getPreferredContentCountry(final Context context) {
|
|
|
|
final String contentCountry = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(context)
|
2020-02-15 16:29:46 +01:00
|
|
|
.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))) {
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
return new ContentCountry(Locale.getDefault().getCountry());
|
|
|
|
}
|
2019-10-28 03:35:51 +01:00
|
|
|
return new ContentCountry(contentCountry);
|
2018-10-05 16:19:21 +02:00
|
|
|
}
|
|
|
|
|
2015-12-29 15:35:51 +01:00
|
|
|
public static Locale getPreferredLocale(Context context) {
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
2018-10-05 16:19:21 +02:00
|
|
|
String languageCode = sp.getString(context.getString(R.string.content_language_key),
|
2020-02-15 16:29:46 +01:00
|
|
|
context.getString(R.string.default_localization_key));
|
2015-12-29 15:35:51 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
try {
|
|
|
|
if (languageCode.length() == 2) {
|
|
|
|
return new Locale(languageCode);
|
|
|
|
} else if (languageCode.contains("_")) {
|
2020-02-27 23:10:07 +01:00
|
|
|
String country = languageCode.substring(languageCode.indexOf("_"));
|
2017-09-03 08:04:18 +02:00
|
|
|
return new Locale(languageCode.substring(0, 2), country);
|
|
|
|
}
|
|
|
|
} catch (Exception ignored) {
|
2015-12-29 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
return Locale.getDefault();
|
2015-12-29 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
public static String localizeNumber(Context context, long number) {
|
2020-02-27 23:10:07 +01:00
|
|
|
return localizeNumber(context, (double) number);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String localizeNumber(Context context, double number) {
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
NumberFormat nf = NumberFormat.getInstance(getAppLocale(context));
|
2015-12-29 15:35:51 +01:00
|
|
|
return nf.format(number);
|
|
|
|
}
|
|
|
|
|
2020-01-18 10:46:53 +01:00
|
|
|
public static String formatDate(Date date, Context context) {
|
|
|
|
return DateFormat.getDateInstance(DateFormat.MEDIUM, getAppLocale(context)).format(date);
|
2015-12-29 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
2020-01-18 10:46:53 +01:00
|
|
|
@SuppressLint("StringFormatInvalid")
|
2019-10-28 03:35:51 +01:00
|
|
|
public static String localizeUploadDate(Context context, Date date) {
|
2020-01-18 10:46:53 +01:00
|
|
|
return context.getString(R.string.upload_date_text, formatDate(date, context));
|
2015-12-29 15:35:51 +01:00
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
|
|
|
|
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 localizeStreamCount(Context context, long streamCount) {
|
|
|
|
return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, localizeNumber(context, streamCount));
|
|
|
|
}
|
|
|
|
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
public static String localizeWatchingCount(Context context, long watchingCount) {
|
|
|
|
return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, localizeNumber(context, watchingCount));
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
public static String shortCount(Context context, long count) {
|
2020-02-27 23:10:07 +01:00
|
|
|
double value = (double) count;
|
2017-09-03 08:04:18 +02:00
|
|
|
if (count >= 1000000000) {
|
2020-02-27 23:10:07 +01:00
|
|
|
return localizeNumber(context, round(value / 1000000000, 1)) + context.getString(R.string.short_billion);
|
2017-09-03 08:04:18 +02:00
|
|
|
} else if (count >= 1000000) {
|
2020-02-27 23:10:07 +01:00
|
|
|
return localizeNumber(context, round(value / 1000000, 1)) + context.getString(R.string.short_million);
|
2017-09-03 08:04:18 +02:00
|
|
|
} else if (count >= 1000) {
|
2020-02-27 23:10:07 +01:00
|
|
|
return localizeNumber(context, round(value / 1000, 1)) + context.getString(R.string.short_thousand);
|
2017-09-03 08:04:18 +02:00
|
|
|
} else {
|
2020-02-27 23:10:07 +01:00
|
|
|
return localizeNumber(context, value);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 03:37:36 +01:00
|
|
|
public static String listeningCount(Context context, long listeningCount) {
|
|
|
|
return getQuantity(context, R.plurals.listening, R.string.no_one_listening, listeningCount, shortCount(context, listeningCount));
|
|
|
|
}
|
|
|
|
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
public static String shortWatchingCount(Context context, long watchingCount) {
|
2019-10-28 03:37:36 +01:00
|
|
|
return getQuantity(context, R.plurals.watching, R.string.no_one_watching, watchingCount, shortCount(context, watchingCount));
|
|
|
|
}
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
public static String shortViewCount(Context context, long viewCount) {
|
|
|
|
return getQuantity(context, R.plurals.views, R.string.no_views, viewCount, shortCount(context, viewCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String shortSubscriberCount(Context context, long subscriberCount) {
|
|
|
|
return getQuantity(context, R.plurals.subscribers, R.string.no_subscribers, subscriberCount, shortCount(context, subscriberCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getQuantity(Context context, @PluralsRes int pluralId, @StringRes int zeroCaseStringId, long count, String formattedCount) {
|
|
|
|
if (count == 0) return context.getString(zeroCaseStringId);
|
|
|
|
|
|
|
|
// As we use the already formatted count, is not the responsibility of this method handle long numbers
|
|
|
|
// (it probably will fall in the "other" category, or some language have some specific rule... then we have to change it)
|
|
|
|
int safeCount = count > Integer.MAX_VALUE ? Integer.MAX_VALUE : count < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) count;
|
|
|
|
return context.getResources().getQuantityString(pluralId, safeCount, formattedCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getDurationString(long duration) {
|
|
|
|
if (duration < 0) {
|
|
|
|
duration = 0;
|
|
|
|
}
|
|
|
|
String output;
|
|
|
|
long days = duration / (24 * 60 * 60L); /* greater than a day */
|
|
|
|
duration %= (24 * 60 * 60L);
|
|
|
|
long hours = duration / (60 * 60L); /* greater than an hour */
|
|
|
|
duration %= (60 * 60L);
|
|
|
|
long minutes = duration / 60L;
|
|
|
|
long seconds = duration % 60L;
|
|
|
|
|
|
|
|
//handle days
|
|
|
|
if (days > 0) {
|
|
|
|
output = String.format(Locale.US, "%d:%02d:%02d:%02d", days, hours, minutes, seconds);
|
|
|
|
} else if (hours > 0) {
|
|
|
|
output = String.format(Locale.US, "%d:%02d:%02d", hours, minutes, seconds);
|
|
|
|
} else {
|
|
|
|
output = String.format(Locale.US, "%d:%02d", minutes, seconds);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2019-10-28 05:20:06 +01:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Pretty Time
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-01-09 15:51:41 +01:00
|
|
|
private static void initPrettyTime(Context context) {
|
|
|
|
prettyTime = new PrettyTime(getAppLocale(context));
|
2019-10-28 05:20:06 +01:00
|
|
|
// Do not use decades as YouTube doesn't either.
|
|
|
|
prettyTime.removeUnit(Decade.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static PrettyTime getPrettyTime() {
|
|
|
|
return prettyTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String relativeTime(Calendar calendarTime) {
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
String time = getPrettyTime().formatUnrounded(calendarTime);
|
|
|
|
return time.startsWith("-") ? time.substring(1) : time;
|
|
|
|
//workaround fix for russian showing -1 day ago, -19hrs ago…
|
2019-10-28 05:20:06 +01:00
|
|
|
}
|
2020-01-04 21:38:27 +01:00
|
|
|
|
2020-01-28 20:48:42 +01:00
|
|
|
private static void changeAppLanguage(Locale loc, Resources res) {
|
2020-01-04 21:38:27 +01:00
|
|
|
DisplayMetrics dm = res.getDisplayMetrics();
|
|
|
|
Configuration conf = res.getConfiguration();
|
|
|
|
conf.setLocale(loc);
|
|
|
|
res.updateConfiguration(conf, dm);
|
|
|
|
}
|
2020-01-09 09:40:05 +01:00
|
|
|
|
2020-01-09 15:51:41 +01:00
|
|
|
public static Locale getAppLocale(Context context) {
|
Multiple localization fixes
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
2020-02-14 18:19:35 +01:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
String lang = prefs.getString(context.getString(R.string.app_language_key), "en");
|
2020-01-09 09:40:05 +01:00
|
|
|
Locale loc;
|
2020-02-15 16:29:46 +01:00
|
|
|
if (lang.equals(context.getString(R.string.default_localization_key))) {
|
2020-01-09 09:40:05 +01:00
|
|
|
loc = Locale.getDefault();
|
|
|
|
} else if (lang.matches(".*-.*")) {
|
2020-01-28 20:48:42 +01:00
|
|
|
//to differentiate different versions of the language
|
|
|
|
//for example, pt (portuguese in Portugal) and pt-br (portuguese in Brazil)
|
2020-01-09 09:40:05 +01:00
|
|
|
String[] localisation = lang.split("-");
|
|
|
|
lang = localisation[0];
|
|
|
|
String country = localisation[1];
|
|
|
|
loc = new Locale(lang, country);
|
|
|
|
} else {
|
|
|
|
loc = new Locale(lang);
|
|
|
|
}
|
|
|
|
return loc;
|
|
|
|
}
|
2020-01-28 20:48:42 +01:00
|
|
|
|
|
|
|
public static void assureCorrectAppLanguage(Context c) {
|
|
|
|
changeAppLanguage(getAppLocale(c), c.getResources());
|
|
|
|
}
|
2020-02-28 16:59:52 +01:00
|
|
|
|
|
|
|
private static double round(double value, int places) {
|
|
|
|
return new BigDecimal(value).setScale(places, RoundingMode.HALF_UP).doubleValue();
|
|
|
|
}
|
2015-12-29 15:35:51 +01:00
|
|
|
}
|