Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c549280a authored by Beverly's avatar Beverly
Browse files

Replace zen setting plurals with MessageFormat

For better translations. See go/android-i18n-plurals.

Test: manual
Test: make RunSettingsRoboTests7
Fixes: 156651436
Change-Id: Ic82140b81bf49f071291d2824fa45d310de238ae
parent 9aa80727
Loading
Loading
Loading
Loading
+74 −64
Original line number Diff line number Diff line
@@ -7820,14 +7820,14 @@
    <!-- Setting summary for controlling how caption text display in real time [CHAR LIMIT=NONE]-->
    <string name="live_caption_summary">Automatically caption media</string>
    <!-- Sound: Summary for the Do not Disturb option when there are no automatic rules enabled. [CHAR LIMIT=NONE]-->
    <string name="zen_mode_settings_summary_off">None</string>
    <!-- Sound: Summary for the Do not Disturb option when at least one automatic rule is enabled. [CHAR LIMIT=NONE]-->
    <plurals name="zen_mode_settings_summary_on">
        <item quantity="one">1 schedule set</item>
        <item quantity="other"><xliff:g id="on_count" example="10">%d</xliff:g> schedules set</item>
    </plurals>
    <!-- Sound: Summary for the Do not Disturb option that describes how many automatic rules (schedules) are enabled [CHAR LIMIT=NONE]-->
    <string name="zen_mode_settings_schedules_summary">
        {count, plural,
            =0    {None}
            =1    {1 schedule set}
            other {# schedules set}
        }
    </string>
    <!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
    <string name="zen_mode_settings_title">Do Not Disturb</string>
@@ -8000,12 +8000,6 @@
    <!-- Sound settings screen, summary format of do not disturb when on with extra info. [CHAR LIMIT=NONE] -->
    <string name="zen_mode_sound_summary_on_with_info">On / <xliff:g name="dnd_summary" example="No sound except alarms and media">%1$s</xliff:g></string>
    <!-- Sound settings screen, summary format of do not disturb when off with extra information. [CHAR LIMIT=NONE] -->
    <string name="zen_mode_sound_summary_off_with_info">Off / <xliff:g name="dnd_summary" example="1 schedule can turn on automatically">%1$s</xliff:g></string>
    <!-- Sound settings screen, summary format of do not disturb when off with no extra information. [CHAR LIMIT=NONE] -->
    <string name="zen_mode_sound_summary_off">Off</string>
    <!-- Sound settings screen, summary format of do not disturb when on with no extra information. [CHAR LIMIT=NONE] -->
    <string name="zen_mode_sound_summary_on">On</string>
@@ -8016,19 +8010,29 @@
    <string name="zen_mode_duration_summary_forever">Until you turn off</string>
    <!--  Do not disturb: Summary for zen mode duration setting indicating how long dnd will last when dnd is manually toggled on [CHAR LIMIT=NONE] -->
    <plurals name="zen_mode_duration_summary_time_hours">
        <item quantity="one">1 hour</item>
        <item quantity="other"><xliff:g id="num_hours" example="3">%d</xliff:g> hours</item>
    </plurals>
    <string name="zen_mode_duration_summary_time_hours">
        {count, plural,
            =1    {1 hour}
            other {# hours}
        }
    </string>
    <!--  Do not disturb: Summary for zen mode duration setting indicating how long dnd will last when toggled on -->
    <string name="zen_mode_duration_summary_time_minutes"><xliff:g id="num_minutes" example="5">%d</xliff:g> minutes</string>
    <string name="zen_mode_duration_summary_time_minutes">
        {count, plural,
            =1    {1 minute}
            other {# minutes}
        }
    </string>
    <!-- Summary for the Sound Do not Disturb option when at least one automatic rules is enabled. [CHAR LIMIT=NONE]-->
    <plurals name="zen_mode_sound_summary_summary_off_info">
        <item quantity="one">1 schedule can turn on automatically</item>
        <item quantity="other"><xliff:g id="on_count" example="3">%d</xliff:g> schedules can turn on automatically</item>
    </plurals>
    <!-- Summary for the Sound Do not Disturb option when DND isn't currently on. [CHAR LIMIT=NONE]-->
    <string name="zen_mode_sound_summary_off">
        {count, plural,
            =0    {Off}
            =1    {Off / 1 schedule can turn on automatically}
            other {Off / # schedules can turn on automatically}
        }
    </string>
    <!-- Do not disturb settings, main screen, category header [CHAR LIMIT=120]-->
    <string name="zen_category_behavior">What can interrupt Do Not Disturb</string>
@@ -9027,12 +9031,14 @@
    <string name="zen_mode_from_all_conversations">All conversations</string>
    <string name="zen_mode_from_important_conversations">Priority conversations</string>
    <string name="zen_mode_from_no_conversations">None</string>
    <plurals name="zen_mode_conversations_count">
        <item quantity="one">1 conversation</item>
        <item quantity="other"><xliff:g id="conversations" example="3">%d</xliff:g> conversations</item>
    </plurals>
    <!-- [CHAR LIMIT=40] Zen mode settings: No conversations are allowed to bypass DND -->
    <string name="zen_mode_conversations_count_none">None</string>
    <!-- [CHAR LIMIT=NONE] Zen mode settings: Number of conversations allowed to bypass DND -->
    <string name="zen_mode_conversations_count">
        {count, plural,
            =0    {None}
            =1    {1 conversation}
            other {# conversations}
        }
    </string>
    <!-- [CHAR LIMIT=120] Zen mode settings: Header for calls and messages section of conversations
    setting page -->
    <string name="zen_mode_people_calls_messages_section_title">Who can interrupt</string>
@@ -9053,12 +9059,15 @@
    <!-- [CHAR LIMIT=50] Zen mode settings: Starred contacts preference title -->
    <string name="zen_mode_starred_contacts_title">Starred contacts</string>
    <!-- Zen mode settings: Starred contacts summary [CHAR LIMIT=NONE] -->
    <plurals name="zen_mode_starred_contacts_summary_additional_contacts">
        <item quantity="one">1 other</item>
        <item quantity="other"><xliff:g id="num_people" example="3">%d</xliff:g> others</item>
    </plurals>
    <!-- [CHAR LIMIT=40] Zen mode settings: Starred contacts summary when there are no starred contacts -->
    <string name="zen_mode_starred_contacts_summary_none">None</string>
    <string name="zen_mode_starred_contacts_summary_contacts">
        {count, plural, offset:2
            =0    {None}
            =1    {{contact_1}}
            =2    {{contact_1} and {contact_2}}
            =3    {{contact_1}, {contact_2}, and {contact_3}}
            other {{contact_1}, {contact_2}, and # others}
        }
    </string>
    <!-- [CHAR LIMIT=40] Zen mode settings: Messages option -->
    <string name="zen_mode_messages">Messages</string>
@@ -9077,15 +9086,14 @@
    <string name="zen_mode_all_messages_summary">All messages can reach you</string>
    <!-- Zen mode settings: All calls can bypass DND summary [CHAR LIMIT=NONE -->
    <string name="zen_mode_all_calls_summary">All calls can reach you</string>
    <!-- Zen mode settings: There are no contacts on the device [CHAR LIMIT=NONE] -->
    <string name="zen_mode_contacts_count_none">None</string>
    <!-- Zen mode settings: Senders in contacts can bypass DND summary summary [CHAR LIMIT=NONE] -->
    <plurals name="zen_mode_contacts_count">
        <item quantity="one">1 contact</item>
        <item quantity="other"><xliff:g id="num_contacts" example="120">%d</xliff:g> contacts</item>
    </plurals>
    <string name="zen_mode_contacts_count">
        {count, plural,
            =0    {None}
            =1    {1 contact}
            other {# contacts}
        }
    </string>
    <!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: From anyone -->
    <string name="zen_mode_from_anyone">Anyone</string>
    <!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: From contacts only -->
@@ -9170,14 +9178,16 @@
    <string name="zen_mode_bypassing_apps_summary_some">Some notifications</string>
    <!-- [CHAR LIMIT=NONE] Zen mode settings: Footer for DND bypassing apps settings -->
    <string name="zen_mode_bypassing_apps_footer">Selected people can still reach you, even if you don\u2019t allow apps to interrupt</string>
    <!-- [CHAR LIMIT=120] Zen mode settings: Allow apps to bypass DND -->
    <plurals name="zen_mode_bypassing_apps_subtext">
        <item quantity="one"><xliff:g id="app_name" example="Nest">%s</xliff:g> can interrupt</item>
        <item quantity="other"><xliff:g id="app_names" example="Nest and Google Play Store">%s</xliff:g> can interrupt</item>
    </plurals>
    <!-- [CHAR LIMIT=30] Zen mode settings: List item in a summary indicating additional apps are
     allowed to bypass Do Not Disturb. For example, "Nest, Messages, and 2 more can interrupt". -->
    <string name="zen_mode_apps_bypassing_list_count"><xliff:g id="number" example="2">%d</xliff:g> more</string>
    <!-- [CHAR LIMIT=NONE] Zen mode settings: Lists apps that can bypass DND. For example, "Nest, Messages, and 2 more can interrupt". -->
    <string name="zen_mode_bypassing_apps_subtext">
        {count, plural, offset:2
            =0    {No apps can interrupt}
            =1    {{app_1} can interrupt}
            =2    {{app_1} and {app_2} can interrupt}
            =3    {{app_1}, {app_2}, and {app_3} can interrupt}
            other {{app_1}, {app_2}, and # more can interrupt}
        }
    </string>
    <!-- [CHAR LIMIT=100] Zen mode settings: Allow apps to bypass DND title-->
    <string name="zen_mode_bypassing_apps_title">Apps</string>
    <!-- [CHAR LIMIT=100] Zen mode settings: App that can bypass DND's secondary text describing which notification channels from the app can bypass DND-->
@@ -9190,18 +9200,18 @@
    toggle title -->
    <string name="zen_mode_bypassing_app_channels_toggle_all">Allow all notifications</string>
    <!-- [CHAR LIMIT=120] Zen mode settings: Summary for sound interruption settings -->
    <plurals name="zen_mode_other_sounds_summary">
        <item quantity="one"><xliff:g id="sound_category">%s</xliff:g> can interrupt</item>
        <item quantity="other"><xliff:g id="sound_categories" example="Alarms, media sounds, and 2 more">%s</xliff:g> can interrupt</item>
    </plurals>
    <!-- [CHAR LIMIT=120] Zen mode settings: No other sounds are allowed to bypass DND -->
    <string name="zen_mode_other_sounds_none">Nothing can interrupt</string>
    <!-- [CHAR LIMIT=30] Zen mode settings: List item in a summary indicating additional sounds
    are allowed to bypass Do Not Disturb. For example, "Alarms, media sounds, and 2 more can
    interrupt". -->
    <string name="zen_mode_other_sounds_list_count"><xliff:g id="number" example="2">%d</xliff:g> more</string>
    <!-- [CHAR LIMIT=NONE] Zen mode settings: Summary for sound interruption settings -->
    <string name="zen_mode_other_sounds_summary">
        {count, plural, offset:2
            =0    {Nothing can interrupt}
            =1    {{sound_category_1} can interrupt}
            =2    {{sound_category_1} and {sound_category_2} can interrupt}
            =3    {{sound_category_1}, {sound_category_2}, and {sound_category_3} can interrupt}
            other {{sound_category_1}, {sound_category_2}, and # more can interrupt}
        }
    </string>
    <!-- [CHAR LIMIT=120] Zen mode settings: No sounds are allowed to bypass DND -->
    <string name="zen_mode_sounds_none">Nothing can interrupt</string>
    <!-- [CHAR LIMIT=120] Zen mode settings: Summary for people category -->
    <string name="zen_mode_people_none">No one can interrupt</string>
    <!-- [CHAR LIMIT=120] Zen mode settings: Summary for people category -->
+22 −27
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.content.Context;
import android.database.Cursor;
import android.icu.text.ListFormatter;
import android.icu.text.MessageFormat;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.Settings;
@@ -41,7 +41,9 @@ import com.android.settings.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class ZenModeBackend {
@@ -468,37 +470,30 @@ public class ZenModeBackend {
    String getStarredContactsSummary(Context context) {
        List<String> starredContacts = getStarredContacts();
        int numStarredContacts = starredContacts.size();

        List<String> displayContacts = new ArrayList<>();

        if (numStarredContacts == 0) {
            displayContacts.add(context.getString(R.string.zen_mode_starred_contacts_summary_none));
        } else {
            for (int i = 0; i < 2 && i < numStarredContacts; i++) {
                displayContacts.add(starredContacts.get(i));
            }

        MessageFormat msgFormat = new MessageFormat(
                mContext.getString(R.string.zen_mode_starred_contacts_summary_contacts),
                Locale.getDefault());
        Map<String, Object> args = new HashMap<>();
        args.put("count", numStarredContacts);
        if (numStarredContacts >= 1) {
            args.put("contact_1", starredContacts.get(0));
            if (numStarredContacts >= 2) {
                args.put("contact_2", starredContacts.get(1));
                if (numStarredContacts == 3) {
                displayContacts.add(starredContacts.get(2));
            } else if (numStarredContacts > 2) {
                displayContacts.add(context.getResources().getQuantityString(
                        R.plurals.zen_mode_starred_contacts_summary_additional_contacts,
                        numStarredContacts - 2, numStarredContacts - 2));
                    args.put("contact_3", starredContacts.get(2));
                }
            }

        // values in displayContacts must not be null
        return ListFormatter.getInstance().format(displayContacts);
        }
        return msgFormat.format(args);
    }

    String getContactsNumberSummary(Context context) {
        final int numContacts = queryAllContactsData().getCount();
        if (numContacts == 0) {
            return context.getResources().getString(
                    R.string.zen_mode_contacts_count_none);
        }
        return context.getResources().getQuantityString(R.plurals.zen_mode_contacts_count,
                numContacts, numContacts);
        MessageFormat msgFormat = new MessageFormat(
                mContext.getString(R.string.zen_mode_contacts_count),
                Locale.getDefault());
        Map<String, Object> args = new HashMap<>();
        args.put("count", queryAllContactsData().getCount());
        return msgFormat.format(args);
    }

    private Cursor queryStarredContactsData() {
+19 −22
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ package com.android.settings.notification.zen;
import android.app.Application;
import android.app.NotificationChannel;
import android.content.Context;
import android.icu.text.ListFormatter;
import android.icu.text.MessageFormat;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArraySet;
@@ -21,7 +21,10 @@ import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
@@ -119,29 +122,23 @@ public class ZenModeBypassingAppsPreferenceController extends AbstractZenModePre
        }

        final int numAppsBypassingDnd = appsBypassingDnd.size();
        if (numAppsBypassingDnd == 0) {
            mSummary = mContext.getResources().getString(
                    R.string.zen_mode_bypassing_apps_subtext_none);
            refreshSummary(mPreference);
            return;
        String[] appsBypassingDndArr = appsBypassingDnd.toArray(new String[numAppsBypassingDnd]);
        MessageFormat msgFormat = new MessageFormat(
                mContext.getString(R.string.zen_mode_bypassing_apps_subtext),
                Locale.getDefault());
        Map<String, Object> args = new HashMap<>();
        args.put("count", numAppsBypassingDnd);
        if (numAppsBypassingDnd >= 1) {
            args.put("app_1", appsBypassingDndArr[0]);
            if (numAppsBypassingDnd >= 2) {
                args.put("app_2", appsBypassingDndArr[1]);
                if (numAppsBypassingDnd == 3) {
                    args.put("app_3", appsBypassingDndArr[2]);
                }
            }
        }

        List<String> displayAppsBypassing = new ArrayList<>();
        if (numAppsBypassingDnd <= 2) {
            displayAppsBypassing.addAll(appsBypassingDnd);
        } else {
            String[] appsBypassingDndArr =
                    appsBypassingDnd.toArray(new String[numAppsBypassingDnd]);
            displayAppsBypassing.add(appsBypassingDndArr[0]);
            displayAppsBypassing.add(appsBypassingDndArr[1]);
            displayAppsBypassing.add(mContext.getResources().getString(
                    R.string.zen_mode_apps_bypassing_list_count,
                    numAppsBypassingDnd - 2));
        }
        mSummary = mContext.getResources().getQuantityString(
                R.plurals.zen_mode_bypassing_apps_subtext,
                numAppsBypassingDnd,
                ListFormatter.getInstance().format(displayAppsBypassing));
        mSummary = msgFormat.format(args);
        refreshSummary(mPreference);
    }

+17 −5
Original line number Diff line number Diff line
@@ -17,11 +17,16 @@
package com.android.settings.notification.zen;

import android.content.Context;
import android.icu.text.MessageFormat;

import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
        implements PreferenceControllerMixin {

@@ -51,12 +56,19 @@ public class ZenModeDurationPreferenceController extends AbstractZenModePreferen
            summary = mContext.getString(R.string.zen_mode_duration_summary_forever);
        } else {
            if (zenDuration >= 60) {
                int hours = zenDuration / 60;
                summary = mContext.getResources().getQuantityString(
                        R.plurals.zen_mode_duration_summary_time_hours, hours, hours);
                MessageFormat msgFormat = new MessageFormat(
                        mContext.getString(R.string.zen_mode_duration_summary_time_hours),
                        Locale.getDefault());
                Map<String, Object> msgArgs = new HashMap<>();
                msgArgs.put("count", zenDuration / 60);
                summary = msgFormat.format(msgArgs);
            } else {
                summary = mContext.getResources().getString(
                        R.string.zen_mode_duration_summary_time_minutes, zenDuration);
                MessageFormat msgFormat = new MessageFormat(
                        mContext.getString(R.string.zen_mode_duration_summary_time_minutes),
                        Locale.getDefault());
                Map<String, Object> msgArgs = new HashMap<>();
                msgArgs.put("count", zenDuration);
                summary = msgFormat.format(msgArgs);
            }
        }

+10 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.icu.text.MessageFormat;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import android.view.View;
@@ -41,7 +42,10 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.RadioButtonPreference;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * Options to choose the priority conversations that are allowed to bypass DND.
@@ -130,12 +134,13 @@ public class ZenModePriorityConversationsPreferenceController

        if (numConversations == UNSET) {
            return null;
        } else if (numConversations == 0) {
            return mContext.getResources().getString(
                    R.string.zen_mode_conversations_count_none);
        } else {
            return mContext.getResources().getQuantityString(
                    R.plurals.zen_mode_conversations_count, numConversations, numConversations);
            MessageFormat msgFormat = new MessageFormat(
                    mContext.getString(R.string.zen_mode_conversations_count),
                    Locale.getDefault());
            Map<String, Object> args = new HashMap<>();
            args.put("count", numConversations);
            return msgFormat.format(args);
        }
    }

Loading