i18n: special-case count=0 at call site for calendar day a11y label

This commit is contained in:
davotoula
2026-05-21 08:45:37 +02:00
parent 4d4d81edbd
commit 898dec73b9
8 changed files with 47 additions and 10 deletions
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.calendars
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.pluralStringResource
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.stringRes
// Picks calendar_day_a11y_no_events when count is 0 because ICU/CLDR maps 0 to
// the `other` category for every locale we ship, which would otherwise render
// "[date], 0 events" instead of "[date], no events".
@Composable
fun calendarDayA11yLabel(
dateLabel: String,
count: Int,
): String =
if (count == 0) {
stringRes(R.string.calendar_day_a11y_no_events, dateLabel)
} else {
pluralStringResource(R.plurals.calendar_day_a11y_events, count, dateLabel, count)
}
@@ -46,7 +46,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
@@ -266,8 +265,7 @@ private fun DayCell(
MaterialTheme.colorScheme.surface
}
val baseDescription =
pluralStringResource(R.plurals.calendar_day_a11y_events, totalEventCount, dateLabel, totalEventCount)
val baseDescription = calendarDayA11yLabel(dateLabel, totalEventCount)
val todaySuffix = stringRes(R.string.calendar_day_a11y_today_suffix)
val selectedSuffix = stringRes(R.string.calendar_day_a11y_selected_suffix)
val a11y =
@@ -44,7 +44,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
@@ -202,7 +201,7 @@ private fun WeekStrip(
}
val dateLabel = formatLongDate(date.atStartOfDay(ZoneId.systemDefault()).toEpochSecond())
val baseA11y = pluralStringResource(R.plurals.calendar_day_a11y_events, count, dateLabel, count)
val baseA11y = calendarDayA11yLabel(dateLabel, count)
val todaySuffix = stringRes(R.string.calendar_day_a11y_today_suffix)
val selectedSuffix = stringRes(R.string.calendar_day_a11y_selected_suffix)
val a11y =
@@ -2784,12 +2784,12 @@
<item quantity="other">%1$d událostí</item>
</plurals>
<plurals name="calendar_day_a11y_events">
<item quantity="zero">%1$s, žádné události</item>
<item quantity="one">%1$s, %2$d událost</item>
<item quantity="few">%1$s, %2$d události</item>
<item quantity="many">%1$s, %2$d událostí</item>
<item quantity="other">%1$s, %2$d událostí</item>
</plurals>
<string name="calendar_day_a11y_no_events">%1$s, žádné události</string>
<plurals name="calendar_reminder_body">
<item quantity="one">Začíná za %1$d minutu</item>
<item quantity="few">Začíná za %1$d minuty</item>
@@ -2754,10 +2754,10 @@ anz der Bedingungen ist erforderlich</string>
<item quantity="other">%1$d Termine</item>
</plurals>
<plurals name="calendar_day_a11y_events">
<item quantity="zero">%1$s, keine Termine</item>
<item quantity="one">%1$s, %2$d Termin</item>
<item quantity="other">%1$s, %2$d Termine</item>
</plurals>
<string name="calendar_day_a11y_no_events">%1$s, keine Termine</string>
<plurals name="calendar_reminder_body">
<item quantity="one">Beginnt in %1$d Minute</item>
<item quantity="other">Beginnt in %1$d Minuten</item>
@@ -2752,10 +2752,10 @@
<item quantity="other">%1$d eventos</item>
</plurals>
<plurals name="calendar_day_a11y_events">
<item quantity="zero">%1$s, sem eventos</item>
<item quantity="one">%1$s, %2$d evento</item>
<item quantity="other">%1$s, %2$d eventos</item>
</plurals>
<string name="calendar_day_a11y_no_events">%1$s, sem eventos</string>
<plurals name="calendar_reminder_body">
<item quantity="one">Começa em %1$d minuto</item>
<item quantity="other">Começa em %1$d minutos</item>
@@ -2752,10 +2752,10 @@
<item quantity="other">%1$d händelser</item>
</plurals>
<plurals name="calendar_day_a11y_events">
<item quantity="zero">%1$s, inga händelser</item>
<item quantity="one">%1$s, %2$d händelse</item>
<item quantity="other">%1$s, %2$d händelser</item>
</plurals>
<string name="calendar_day_a11y_no_events">%1$s, inga händelser</string>
<plurals name="calendar_reminder_body">
<item quantity="one">Börjar om %1$d minut</item>
<item quantity="other">Börjar om %1$d minuter</item>
+1 -1
View File
@@ -1932,10 +1932,10 @@
<string name="calendar_add_to_phone_calendar">Add to phone calendar</string>
<string name="calendar_nav_jump_to_today">Jump to today</string>
<plurals name="calendar_day_a11y_events">
<item quantity="zero">%1$s, no events</item>
<item quantity="one">%1$s, %2$d event</item>
<item quantity="other">%1$s, %2$d events</item>
</plurals>
<string name="calendar_day_a11y_no_events">%1$s, no events</string>
<string name="calendar_day_a11y_today_suffix">today</string>
<string name="calendar_day_a11y_selected_suffix">selected</string>
<string name="calendar_fab_new_event">Create a new calendar event</string>