Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Use plurals for real-time arrival estimates #418

Open
barbeau opened this issue Sep 10, 2014 · 4 comments
Open

Use plurals for real-time arrival estimates #418

barbeau opened this issue Sep 10, 2014 · 4 comments

Comments

@barbeau
Copy link
Member

barbeau commented Sep 10, 2014

As discussed in #413 (comment), we should use plurals for singular (minute) vs. plural (minutes) text displayed to the user.

otpandroid-realtimeworking

Good examples of implementation for this are in the OBA Android project:

<plurals name="stop_info_arrive_delayed">
        <item quantity="one">1 minute delay</item>
        <!-- Entire element below should be on a single line if XML is reformatted - see #99 -->
        <item quantity="other"><xliff:g id="count">%d</xliff:g> minute delay</item>
    </plurals>
    <plurals name="stop_info_arrive_early">
        <item quantity="one">1 minute early</item>
        <!-- Below element should remain on same line if XML is reformatted - see #99 -->
        <item quantity="other"><xliff:g id="count">%d</xliff:g> minutes early</item>
    </plurals>
    <plurals name="stop_info_depart_delayed">
        <item quantity="one">Departed 1 minute late</item>
        <!-- Entire element below should be on a single line if XML is reformatted - see #99 -->
        <item quantity="other">Departed <xliff:g id="count">%d</xliff:g> minutes late</item>
    </plurals>
    <plurals name="stop_info_depart_early">
        <item quantity="one">Departed 1 minute early</item>
        <!-- Entire element below should be on a single line if XML is reformatted - see #99 -->
        <item quantity="other">Departed <xliff:g id="count">%d</xliff:g> minutes early</item>
    </plurals>

Usage in code is shown here:

if (delay > 0) {
  // Arriving delayed
  return res.getQuantityString(R.plurals.stop_info_arrive_delayed, (int) delay,delay);
} else if (delay < 0) {
  // Arriving early
  delay = -delay;
  return res.getQuantityString(R.plurals.stop_info_arrive_early, (int) delay, delay);
} else {
  // Arriving on time
  return context.getString(R.string.stop_info_ontime);
}
@barbeau
Copy link
Member Author

barbeau commented Sep 10, 2014

This also applies to the notification for real-time info:

otpandroid_realtimenotification

@vreixo
Copy link
Contributor

vreixo commented Sep 10, 2014

@barbeau we already have this, including values in strings. The problem is that negative values are changed later on (in the special cases of delays), and only positive one is substituted, I'll add it also for -1. I prefer to not change all negative values because I think that it's more clear this way and to don't hide some possible errors.

I'll submit a correction with this and other graphical improvements to the notifications in a few minutes.

barbeau added a commit that referenced this issue Sep 10, 2014
Fix #418 - Checked also -1 to display singular values.
@barbeau
Copy link
Member Author

barbeau commented Sep 10, 2014

Thanks @vreixo, for fixing the -1 presentation! I'm going to re-open the issue, so at some point in the future we can use the official Android plurals technique to format singular/plural strings. The reason behind wanting to use this is that different languages have different ways to represent singular/plural, so its better to use the built-in Android rules for this. From the above link:

Different languages have different rules for grammatical agreement with quantity. In English, for example, the quantity 1 is a special case. We write "1 book", but for any other quantity we'd write "n books". This distinction between singular and plural is very common, but other languages make finer distinctions. The full set supported by Android is zero, one, two, few, many, and other.

The rules for deciding which case to use for a given language and quantity can be very complex, so Android provides you with methods such as getQuantityString() to select the appropriate resource for you.

@barbeau barbeau reopened this Sep 10, 2014
@vreixo
Copy link
Contributor

vreixo commented Sep 10, 2014

@barbeau agreed that mechanism seems very interesting. Regarding my previous comment, I was just referring to don't change all negative values in our function of the app.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants