CUTR-at-USF / OpenTripPlanner-for-Android

An Android app for multi-modal trip planning and navigation using any OpenTripPlanner server.
Other
130 stars 91 forks source link

Use plurals for real-time arrival estimates #418

Open barbeau opened 9 years ago

barbeau commented 9 years ago

As discussed in https://github.com/CUTR-at-USF/OpenTripPlanner-for-Android/issues/413#issuecomment-55166727, 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 commented 9 years ago

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

otpandroid_realtimenotification

vreixo commented 9 years ago

@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 commented 9 years ago

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.

vreixo commented 9 years ago

@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.