diff --git a/CheckTranslations.java b/CheckTranslations.java index fba4fa998..8b7c2388b 100644 --- a/CheckTranslations.java +++ b/CheckTranslations.java @@ -17,7 +17,8 @@ public final class CheckTranslations { private static boolean remove = false; private static int checks = 0; private static int matches = 0; - private static Pattern p, e; + private static int changes = 0; + private static Pattern p, pb, pe, e, o; /** * Search translated strings.xml files for empty item / plural tags @@ -56,7 +57,10 @@ public final class CheckTranslations { } p = Pattern.compile("(|\"/>)"); + pb = Pattern.compile("()"); + pe = Pattern.compile("()"); e = Pattern.compile("(<\\/string>|\\/>){1})"); + o = Pattern.compile("()[^]*(<\\/item>)"); for (int i = 0; i < args.length; i++) { if (!args[i].equals("-d") && !args[i].equals("-p") && !args[i].equals("-e") && !args[i].equals("-r")) { @@ -73,7 +77,9 @@ public final class CheckTranslations { System.out.println(checks + " files were checked."); System.out.println(matches + " corrupt lines detected."); - if (remove) System.out.println(matches + " corrupt lines removed."); + if (remove) { + System.out.println(matches + " corrupt lines removed and " + changes + " lines fixed."); + } } @@ -101,7 +107,8 @@ public final class CheckTranslations { List lines = new ArrayList(); boolean checkFailed = false; - + boolean otherDetected = false; + boolean inPlurals = false; try (BufferedReader br = new BufferedReader(new FileReader(f))) { String line; int ln = 0; @@ -120,6 +127,38 @@ public final class CheckTranslations { } } br.close(); + int pluralsLine = 0; + for (int i = 0; i < lines.size(); i++) { + if (o.matcher(lines.get(i)).find()) { + otherDetected = true; + } + if (plurals && pb.matcher(lines.get(i)).find()) { + inPlurals = true; + pluralsLine = i; + } else if (plurals && pe.matcher(lines.get(i)).find()) { + inPlurals = false; + if (!otherDetected) { + boolean b = false; + check: for(int j = pluralsLine; j < i; j++) { + if (lines.get(j).contains("many")) { + b = true; + pluralsLine = j; + break check; + } + } + if (remove && b) { + if (debug) System.out.println(" Line " + (pluralsLine + 1) + " was " + ((remove) ? "changed" : "detected") + ": '" + lines.get(pluralsLine) + "'"); + lines.set(pluralsLine, lines.get(pluralsLine).replace("many", "other")); + changes++; + checkFailed = true; + } else if (debug) { + if (debug) System.out.println(" WARNING: Line " + (i + 1) + " - No found!"); + } + } + otherDetected = false; + } + + } if (remove && checkFailed) { Files.write(f.toPath(), lines, Charset.forName("UTF-8")); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 297da7eed..645049078 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; +import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; @@ -252,9 +253,10 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title))); } - protected void shareUrl(String url) { + protected void shareUrl(String subject, String url) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, url); startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title))); } 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 5fb9e0105..802389a95 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 @@ -623,12 +623,7 @@ public class VideoDetailFragment extends BaseStateFragment implement if (DEBUG) Log.d(TAG, "setupActionBarHandler() called with: info = [" + info + "]"); sortedStreamVideosList = new ArrayList<>(ListHelper.getSortedStreamVideosList(activity, info.getVideoStreams(), info.getVideoOnlyStreams(), false)); actionBarHandler.setupStreamList(sortedStreamVideosList, spinnerToolbar); - actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() { - @Override - public void onActionSelected(int selectedStreamId) { - shareUrl(info.getUrl()); - } - }); + actionBarHandler.setOnShareListener(selectedStreamId -> shareUrl(info.name, info.url)); actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() { @Override 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 000aff487..0cc5cabf3 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 @@ -231,7 +231,7 @@ public class ChannelFragment extends BaseListInfoFragment { openUrlInBrowser(url); break; case R.id.menu_item_share: { - shareUrl(url); + shareUrl(name, url); break; } default: diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index c798bf349..52eeb337c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -167,7 +167,7 @@ public class PlaylistFragment extends BaseListInfoFragment { openUrlInBrowser(url); break; case R.id.menu_item_share: { - shareUrl(url); + shareUrl(name, url); break; } default: diff --git a/fixplurals.sh b/fixplurals.sh index 331a01240..8a637aa91 100755 --- a/fixplurals.sh +++ b/fixplurals.sh @@ -1,4 +1,4 @@ #!/bin/bash javac CheckTranslations.java -find app/src -name "*.xml" | grep values | xargs java CheckTranslations -r +find app/src -name "*.xml" | grep values | xargs java CheckTranslations -d -r