Commit 1dbe4695 authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Fix missing "few" plural for Polish locale

parent df7a6328
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -375,7 +375,12 @@ public class MainActivity extends AppCompatActivity {
        final long h = summary.getDuration() / 3600;
        final long m = summary.getDuration() % 3600 / 60;
        summaryDuration.setText(getString(R.string.summary_duration, h, m));
        summaryPositions.setText(getResources().getQuantityString(R.plurals.summary_positions, (int) summary.getPositionsCount(), (int) summary.getPositionsCount()));
        int positionsCount = (int) summary.getPositionsCount();
        if (needsPluralFewHack(positionsCount)) {
            summaryPositions.setText(getResources().getString(R.string.summary_positions_few, positionsCount));
        } else {
            summaryPositions.setText(getResources().getQuantityString(R.plurals.summary_positions, positionsCount, positionsCount));
        }
    }

    /**
@@ -572,7 +577,11 @@ public class MainActivity extends AppCompatActivity {
    private void updateSyncStatus(int unsynced) {
        String text;
        if (unsynced > 0) {
            if (needsPluralFewHack(unsynced)) {
                text = getString(R.string.label_positions_behind_few, unsynced);
            } else {
                text = getResources().getQuantityString(R.plurals.label_positions_behind, unsynced, unsynced);
            }
            if (syncError) {
                setSyncLed(LED_RED);
            } else {
@@ -756,4 +765,19 @@ public class MainActivity extends AppCompatActivity {
            }
        }
    };

    /**
     * Check if count matches "few" plurals and language is Polish
     * Hack for API <= 10 where "few" plural is missing for some languages
     * todo: this simple hack currently supports only language "pl"
     *
     * @param i Count
     * @return True if hack is needed, false otherwise
     */
    private boolean needsPluralFewHack(int i) {
        return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                && Locale.getDefault().getLanguage().equalsIgnoreCase("pl")
                && (i % 10 >= 2 && i % 10 <= 4)
                && (i % 100 < 12 || i % 100 > 14);
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -40,14 +40,15 @@
    <string name="label_name">Nazwa</string>
    <string name="label_newtrack_name">Nazwa nowej trasy</string>
    <plurals name="label_positions_behind">
        <item quantity="one">%d pozycja do tyłu</item>
        <item quantity="few">%d pozycje do tyłu</item>
        <item quantity="many">%d pozycji do tyłu</item>
        <item quantity="other">%d pozycji do tyłu</item>
        <item quantity="one">Została %d pozycja</item>
        <item quantity="few">Zostały %d pozycje</item>
        <item quantity="many">Zostało %d pozycji</item>
        <item quantity="other">Zostało %d pozycji</item>
    </plurals>
    <string name="label_positions_behind_few">Zostały %d pozycje</string>
    <string name="label_status">Status</string>
    <string name="label_synchronization">Synchronizacja</string>
    <string name="label_synchronized">wszystko wysłane</string>
    <string name="label_synchronized">Wszystko wysłane</string>
    <string name="label_track">Bieżąca trasa</string>
    <string name="location_disabled">Należy włączyć przynajmniej jedną usługę lokalizacji</string>
    <string name="location_permission_denied">Należy zaakceptować zgodę na dostęp do lokalizacji</string>
@@ -92,6 +93,7 @@
        <item quantity="many">%d pozycji</item>
        <item quantity="other">%d pozycji</item>
    </plurals>
    <string name="summary_positions_few">%d pozycje</string>
    <string name="title_newtrack">Nowa trasa</string>
    <string name="track_summary">Podsumowanie trasy</string>
    <string name="tracking_started">Zapis włączony</string>
+6 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
  ~ See <http://www.gnu.org/licenses/>
  -->

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="app_name" translatable="false">μlogger</string>
    <string name="app_name_ascii" translatable="false">ulogger</string>
    <string name="button_start">Start</string>
@@ -20,7 +20,7 @@
    <string name="label_newtrack_name">New track name</string>
    <string name="label_name">Name</string>
    <string name="label_last_update">Last update: %s</string>
    <string name="label_synchronized">synchronized</string>
    <string name="label_synchronized">Synchronized</string>
    <string name="cancel">Cancel</string>
    <string name="submit">Submit</string>
    <string name="ok">OK</string>
@@ -82,6 +82,8 @@
        <item quantity="many">%d positions</item>
        <item quantity="other">%d positions</item>
    </plurals>
    <!-- hack for api <= 10 and missing "few" plurals, currently used only for Polish locale -->
    <string name="summary_positions_few" comment="few positions hack" tools:ignore="PluralsCandidate">%d positions</string>
    <string name="summary_duration">%1$d h %2$d min</string>
    <string name="unit_kilometer">km</string>
    <string name="unit_mile">mi.</string>
@@ -115,4 +117,6 @@
        <item quantity="many">%d positions behind</item>
        <item quantity="other">%d positions behind</item>
    </plurals>
    <!-- hack for api <= 10 and missing "few" plurals, currently used only for Polish locale -->
    <string name="label_positions_behind_few" comment="few positions hack" tools:ignore="PluralsCandidate">%d positions behind</string>
</resources>