1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 00:50:32 +00:00

changed the way to change language, now is «NewPipe's language» selector

This commit is contained in:
bopol 2020-01-09 09:40:05 +01:00
parent dea1e0dcb9
commit 3ad0e313ca
10 changed files with 209 additions and 29 deletions

View File

@ -56,7 +56,6 @@ import androidx.fragment.app.FragmentManager;
import com.google.android.material.navigation.NavigationView; import com.google.android.material.navigation.NavigationView;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance; import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
@ -67,7 +66,6 @@ import org.schabi.newpipe.fragments.list.search.SearchFragment;
import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PeertubeHelper; import org.schabi.newpipe.util.PeertubeHelper;
import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.PermissionHelper;
@ -78,8 +76,10 @@ import org.schabi.newpipe.util.ThemeHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import static org.schabi.newpipe.util.Localization.changeAppLanguage; import static org.schabi.newpipe.util.Localization.changeAppLanguage;
import static org.schabi.newpipe.util.Localization.getAppLanguage;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
@ -116,10 +116,9 @@ public class MainActivity extends AppCompatActivity {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
TLSSocketFactoryCompat.setAsDefault(); TLSSocketFactoryCompat.setAsDefault();
} }
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
changeAppLanguage(Localization.getPreferredLocale(getApplicationContext()), getResources()); changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
@ -424,6 +423,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
super.onResume(); super.onResume();
// close drawer on return, and don't show animation, so its looks like the drawer isn't open // close drawer on return, and don't show animation, so its looks like the drawer isn't open

View File

@ -25,6 +25,11 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.Locale;
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
import static org.schabi.newpipe.util.Localization.getAppLanguage;
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends AppCompatActivity {
/** /**
@ -62,6 +67,7 @@ public class AboutActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);

View File

@ -15,9 +15,14 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.settings.SettingsActivity;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.Locale;
import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.service.DownloadManagerService;
import us.shandian.giga.ui.fragment.MissionsFragment; import us.shandian.giga.ui.fragment.MissionsFragment;
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
import static org.schabi.newpipe.util.Localization.getAppLanguage;
public class DownloadActivity extends AppCompatActivity { public class DownloadActivity extends AppCompatActivity {
private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag"; private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag";
@ -29,6 +34,7 @@ public class DownloadActivity extends AppCompatActivity {
i.setClass(this, DownloadManagerService.class); i.setClass(this, DownloadManagerService.class);
startService(i); startService(i);
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader); setContentView(R.layout.activity_downloader);

View File

@ -56,6 +56,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
private Localization initialSelectedLocalization; private Localization initialSelectedLocalization;
private ContentCountry initialSelectedContentCountry; private ContentCountry initialSelectedContentCountry;
private String initialLanguage;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -64,6 +65,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
initialSelectedLocalization = org.schabi.newpipe.util.Localization.getPreferredLocalization(requireContext()); initialSelectedLocalization = org.schabi.newpipe.util.Localization.getPreferredLocalization(requireContext());
initialSelectedContentCountry = org.schabi.newpipe.util.Localization.getPreferredContentCountry(requireContext()); initialSelectedContentCountry = org.schabi.newpipe.util.Localization.getPreferredContentCountry(requireContext());
initialLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en");
} }
@Override @Override
@ -125,9 +127,10 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
.getPreferredLocalization(requireContext()); .getPreferredLocalization(requireContext());
final ContentCountry selectedContentCountry = org.schabi.newpipe.util.Localization final ContentCountry selectedContentCountry = org.schabi.newpipe.util.Localization
.getPreferredContentCountry(requireContext()); .getPreferredContentCountry(requireContext());
final String selectedLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en");
if (!selectedLocalization.equals(initialSelectedLocalization) if (!selectedLocalization.equals(initialSelectedLocalization)
|| !selectedContentCountry.equals(initialSelectedContentCountry)) { || !selectedContentCountry.equals(initialSelectedContentCountry) || !selectedLanguage.equals(initialLanguage)) {
Toast.makeText(requireContext(), R.string.localization_changes_requires_app_restart, Toast.LENGTH_LONG).show(); Toast.makeText(requireContext(), R.string.localization_changes_requires_app_restart, Toast.LENGTH_LONG).show();
NewPipe.setupLocalization(selectedLocalization, selectedContentCountry); NewPipe.setupLocalization(selectedLocalization, selectedContentCountry);

View File

@ -14,6 +14,11 @@ import android.view.MenuItem;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.Locale;
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
import static org.schabi.newpipe.util.Localization.getAppLanguage;
/* /*
* Created by Christian Schabesberger on 31.08.15. * Created by Christian Schabesberger on 31.08.15.
@ -44,7 +49,7 @@ public class SettingsActivity extends AppCompatActivity implements BasePreferenc
@Override @Override
protected void onCreate(Bundle savedInstanceBundle) { protected void onCreate(Bundle savedInstanceBundle) {
setTheme(ThemeHelper.getSettingsThemeStyle(this)); setTheme(ThemeHelper.getSettingsThemeStyle(this));
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
super.onCreate(savedInstanceBundle); super.onCreate(savedInstanceBundle);
setContentView(R.layout.settings_layout); setContentView(R.layout.settings_layout);

View File

@ -7,6 +7,11 @@ import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
import org.ocpsoft.prettytime.PrettyTime; import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.units.Decade; import org.ocpsoft.prettytime.units.Decade;
@ -21,10 +26,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
/* /*
* Created by chschtsch on 12/29/15. * Created by chschtsch on 12/29/15.
* *
@ -226,4 +227,21 @@ public class Localization {
conf.setLocale(loc); conf.setLocale(loc);
res.updateConfiguration(conf, dm); res.updateConfiguration(conf, dm);
} }
public static Locale getAppLanguage(Context context) {
SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString("newpipes_language_key", "en");
Locale loc;
if (lang.equals("system")) {
loc = Locale.getDefault();
} else if (lang.matches(".*-.*")) {
String[] localisation = lang.split("-");
lang = localisation[0];
String country = localisation[1];
loc = new Locale(lang, country);
} else {
loc = new Locale(lang);
}
return loc;
}
} }

View File

@ -193,13 +193,13 @@
<string name="short_billion">بی</string> <string name="short_billion">بی</string>
<string name="no_subscribers">کوئی صارفین نہیں</string> <string name="no_subscribers">کوئی صارفین نہیں</string>
<plurals name="subscribers"> <plurals name="subscribers">
<item quantity="one">% s صارف</item> <item quantity="one">%s صارف</item>
<item quantity="other">% s صارفین</item> <item quantity="other">%s صارفین</item>
</plurals> </plurals>
<string name="no_views">کوئی مناظر نہیں</string> <string name="no_views">کوئی مناظر نہیں</string>
<plurals name="views"> <plurals name="views">
<item quantity="one">% s منظر</item> <item quantity="one">%s منظر</item>
<item quantity="other">% s مناظر</item> <item quantity="other">%s مناظر</item>
</plurals> </plurals>
<string name="no_videos">ویڈیوز دستیاب نہیں</string> <string name="no_videos">ویڈیوز دستیاب نہیں</string>
<plurals name="videos"> <plurals name="videos">
@ -388,7 +388,7 @@
<string name="limit_data_usage_none_description">کوئی حد نہیں</string> <string name="limit_data_usage_none_description">کوئی حد نہیں</string>
<string name="limit_mobile_data_usage_title">موبائل ڈیٹا کا استعمال کرتے وقت ریذولوشن کو محدود کریں</string> <string name="limit_mobile_data_usage_title">موبائل ڈیٹا کا استعمال کرتے وقت ریذولوشن کو محدود کریں</string>
<string name="minimize_on_exit_title">ایپ سوئچ کو کم سے کم کریں</string> <string name="minimize_on_exit_title">ایپ سوئچ کو کم سے کم کریں</string>
<string name="minimize_on_exit_summary">اہم ویڈیو پلیئر سے دوسرے ایپ میں سوئچنگ کرتے وقت کارروائی-% s</string> <string name="minimize_on_exit_summary">اہم ویڈیو پلیئر سے دوسرے ایپ میں سوئچنگ کرتے وقت کارروائی-s%</string>
<string name="minimize_on_exit_none_description">کوئی نہیں</string> <string name="minimize_on_exit_none_description">کوئی نہیں</string>
<string name="minimize_on_exit_background_description">پس منظری پلیر میں کم کریں</string> <string name="minimize_on_exit_background_description">پس منظری پلیر میں کم کریں</string>
<string name="minimize_on_exit_popup_description">پاپ اپ پلیر میں کم کریں</string> <string name="minimize_on_exit_popup_description">پاپ اپ پلیر میں کم کریں</string>

View File

@ -31,20 +31,20 @@
<string name="seek_duration_key" translatable="false">seek_duration</string> <string name="seek_duration_key" translatable="false">seek_duration</string>
<string name="seek_duration_default_value" translatable="false">10000</string> <string name="seek_duration_default_value" translatable="false">10000</string>
<string-array name="seek_duration_description" translatable="false"> <string-array name="seek_duration_description" translatable="false">
<item>5 seconds</item> <item>5 seconds</item>
<item>10 seconds</item> <item>10 seconds</item>
<item>15 seconds</item> <item>15 seconds</item>
<item>20 seconds</item> <item>20 seconds</item>
<item>25 seconds</item> <item>25 seconds</item>
<item>30 seconds</item> <item>30 seconds</item>
</string-array> </string-array>
<string-array name="seek_duration_value" translatable="false"> <string-array name="seek_duration_value" translatable="false">
<item>5000</item> <item>5000</item>
<item>10000</item> <item>10000</item>
<item>15000</item> <item>15000</item>
<item>20000</item> <item>20000</item>
<item>25000</item> <item>25000</item>
<item>30000</item> <item>30000</item>
</string-array> </string-array>
<string name="minimize_on_exit_key" translatable="false">minimize_on_exit_key</string> <string name="minimize_on_exit_key" translatable="false">minimize_on_exit_key</string>
@ -175,6 +175,7 @@
<string name="main_page_content_key" translatable="false">main_page_content</string> <string name="main_page_content_key" translatable="false">main_page_content</string>
<string name="enable_playback_resume_key" translatable="false">enable_playback_resume</string> <string name="enable_playback_resume_key" translatable="false">enable_playback_resume</string>
<string name="enable_playback_state_lists_key" translatable="false">enable_playback_state_lists</string> <string name="enable_playback_state_lists_key" translatable="false">enable_playback_state_lists</string>
<string name="newpipes_language_key" translatable="false">newpipes_language_key</string>
<string name="import_data" translatable="false">import_data</string> <string name="import_data" translatable="false">import_data</string>
<string name="export_data" translatable="false">export_data</string> <string name="export_data" translatable="false">export_data</string>
@ -272,7 +273,6 @@
<item>cs</item> <item>cs</item>
<item>da</item> <item>da</item>
<item>de</item> <item>de</item>
<item>eo</item>
<item>et</item> <item>et</item>
<item>en-GB</item> <item>en-GB</item>
<item>en</item> <item>en</item>
@ -352,7 +352,6 @@
<item>Čeština</item> <item>Čeština</item>
<item>Dansk</item> <item>Dansk</item>
<item>Deutsch</item> <item>Deutsch</item>
<item>Esperanto</item>
<item>Eesti</item> <item>Eesti</item>
<item>English (UK)</item> <item>English (UK)</item>
<item>English (US)</item> <item>English (US)</item>
@ -925,6 +924,137 @@
<item>ZW</item> <item>ZW</item>
</string-array> </string-array>
<!--The next two arrays are set to change the NewPipe language-->
<string-array name="language_code_np" translatable="false">
<item>system</item>
<item>ar</item>
<item>az</item>
<item>ast</item>
<item>be</item>
<item>bg-bd</item>
<item>bn</item>
<item>ca</item>
<item>cs</item>
<item>da</item>
<item>de</item>
<item>el</item>
<item>en</item>
<item>eo</item>
<item>es</item>
<item>et</item>
<item>eu</item>
<item>fa</item>
<item>fi</item>
<item>fil</item>
<item>fr</item>
<item>gl</item>
<item>he</item>
<item>hi</item>
<item>hr</item>
<item>hu</item>
<item>hy</item>
<item>ia</item>
<item>ind</item>
<item>it</item>
<item>ja</item>
<item>ko</item>
<item>ku</item>
<item>lt</item>
<item>mk</item>
<item>ms</item>
<item>nb-no</item>
<item>ne</item>
<item>nl</item>
<item>nl-be</item>
<item>pa</item>
<item>pl</item>
<item>pr</item>
<item>pt</item>
<item>pt-br</item>
<item>ro</item>
<item>ru</item>
<item>sk</item>
<item>sl</item>
<item>sq</item>
<item>sr</item>
<item>sv</item>
<item>ta</item>
<item>te</item>
<item>th</item>
<item>tr</item>
<item>uk</item>
<item>ur</item>
<item>vi</item>
<item>zh</item>
<item>zh-hans</item>
<item>zh-tw</item>
</string-array>
<string-array name="language_name_np" translatable="false">
<item>@string/system</item>
<item>العربية</item>
<item>Azərbaycan dili</item>
<item>Asturianu</item>
<item>Беларуская</item>
<item>български език</item>
<item>বাংলা</item>
<item>Català</item>
<item>Čeština</item>
<item>Dansk</item>
<item>Deutsch</item>
<item>Ελληνικά</item>
<item>English</item>
<item>Esperanto</item>
<item>Español</item>
<item>Eesti keel</item>
<item>Euskara</item>
<item>فارسی</item>
<item>Suomen kieli</item>
<item>Wikang Filipino</item>
<item>Français</item>
<item>Galego</item>
<item>עברית</item>
<item>हिन्दी</item>
<item>Hrvatski</item>
<item>magyar</item>
<item>Հայերեն</item>
<item>Interlingua</item>
<item>Bahasa Indonesia</item>
<item>Italiano</item>
<item>日本語</item>
<item>한국어</item>
<item>کوردی</item>
<item>Lietuvių kalba</item>
<item>македонски јазик</item>
<item>Bahasa Melayu</item>
<item>Norsk bokmål</item>
<item>Nनेपाली</item>
<item>Nederlands (NL)</item>
<item>Nederlands (BE)</item>
<item>ਪੰਜਾਬੀ</item>
<item>Polski</item>
<item>Pirate Language</item>
<item>Português (PT)</item>
<item>Português (BR)</item>
<item>Română</item>
<item>русский язык</item>
<item>Slovenčina</item>
<item>Slovenščina</item>
<item>Shqip</item>
<item>Српски</item>
<item>Svenska</item>
<item>தமிழ்</item>
<item>తెలుగు</item>
<item>ไทย</item>
<item>Türkçe</item>
<item>українська мова</item>
<item>اردو</item>
<item>Tiếng Việt</item>
<item>官话</item>
<item>简化字</item>
<item>臺灣華語</item>
<!--todo : fix ia, ind, see why it crashes for ur-->
</string-array>
<!-- Limit mobile data usage --> <!-- Limit mobile data usage -->
<string name="limit_mobile_data_usage_key" translatable="false">limit_mobile_data_usage</string> <string name="limit_mobile_data_usage_key" translatable="false">limit_mobile_data_usage</string>
<string name="limit_data_usage_none_key" translatable="false">limit_data_usage_none</string> <string name="limit_data_usage_none_key" translatable="false">limit_data_usage_none</string>
@ -943,6 +1073,7 @@
<string name="list_view_mode_key" translatable="false">list_view_mode</string> <string name="list_view_mode_key" translatable="false">list_view_mode</string>
<string name="list_view_mode_value" translatable="false">auto</string> <string name="list_view_mode_value" translatable="false">auto</string>
<string name="system">System</string>
<string-array name="list_view_mode_values" translatable="false"> <string-array name="list_view_mode_values" translatable="false">
<item>auto</item> <item>auto</item>

View File

@ -585,5 +585,6 @@
<string name="downloads_storage_use_saf_title">Use SAF</string> <string name="downloads_storage_use_saf_title">Use SAF</string>
<string name="downloads_storage_use_saf_summary">The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible</string> <string name="downloads_storage_use_saf_summary">The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible</string>
<string name="choose_instance_prompt">Choose an instance</string> <string name="choose_instance_prompt">Choose an instance</string>
<string name="newpipes_language_title">NewPipe\'s language</string>
</resources> </resources>

View File

@ -3,6 +3,16 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/content"> android:title="@string/content">
<ListPreference
app:iconSpaceReserved="false"
android:defaultValue="system"
android:entries="@array/language_name_np"
android:entryValues="@array/language_code_np"
android:key="@string/newpipes_language_key"
android:summary="%s"
android:title="@string/newpipes_language_title"/>
<ListPreference <ListPreference
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
android:defaultValue="@string/default_language_value" android:defaultValue="@string/default_language_value"