Skip to content

Commit

Permalink
fix: allow bolding portions of localized text (#602)
Browse files Browse the repository at this point in the history
* fix: allow bolding portions of localized text

* fix: automatically convert styling

* fix: remove test for deleted component

---------

Co-authored-by: Brandon Rodriguez <[email protected]>
  • Loading branch information
BrandonTR and Brandon Rodriguez authored Dec 19, 2024
1 parent 46d2461 commit 9c27e6f
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 69 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.fromHtml
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -92,9 +94,10 @@ fun UpcomingTripView(state: UpcomingTripViewState) {
fontWeight = FontWeight.Bold
)
is TripInstantDisplay.Approaching ->
BoldedTripStatus(
text = stringResource(R.string.minutes_abbr, 1),
modifier = modifier
Text(
text = AnnotatedString.fromHtml(stringResource(R.string.minutes_abbr, 1)),
modifier = modifier,
style = MaterialTheme.typography.headlineMedium,
)
is TripInstantDisplay.Time ->
Text(
Expand All @@ -119,14 +122,22 @@ fun UpcomingTripView(state: UpcomingTripViewState) {
}
)
is TripInstantDisplay.Minutes ->
BoldedTripStatus(
text = stringResource(R.string.minutes_abbr, state.trip.minutes),
modifier = modifier
Text(
text =
AnnotatedString.fromHtml(
stringResource(R.string.minutes_abbr, state.trip.minutes)
),
modifier = modifier,
style = MaterialTheme.typography.headlineMedium,
)
is TripInstantDisplay.ScheduleMinutes ->
BoldedTripStatus(
text = stringResource(R.string.minutes_abbr, state.trip.minutes),
modifier = modifier.then(Modifier.alpha(0.6F))
Text(
text =
AnnotatedString.fromHtml(
stringResource(R.string.minutes_abbr, state.trip.minutes)
),
modifier = modifier.then(Modifier.alpha(0.6F)),
style = MaterialTheme.typography.headlineMedium,
)
is TripInstantDisplay.Cancelled ->
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">Rumbo</string>
<string name="inbound">Entrante</string>
<string name="loading">Cargando…</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b> min</string>
<string name="more_link">Más</string>
<string name="more_page_footer">Hecho con ♥ por T</string>
<string name="more_section_feature_flags">Banderas de características</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">Prale nan direksyon</string>
<string name="inbound">Antran</string>
<string name="loading">Chajman...</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b> minit</string>
<string name="more_link">Plis</string>
<string name="more_page_footer">Ki fèt ak ♥ pa T a</string>
<string name="more_section_feature_flags">Drapo Opsyon</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">Rumo</string>
<string name="inbound">Entrada</string>
<string name="loading">Carregando...</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b> min</string>
<string name="more_link">Mais</string>
<string name="more_page_footer">Feito com ♥ pelo T</string>
<string name="more_section_feature_flags">Exibir sinalizações</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">Tiêu đề</string>
<string name="inbound">Đến</string>
<string name="loading">Đang tải...</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b> phút</string>
<string name="more_link">Thêm</string>
<string name="more_page_footer">Được tạo ra với ♥ bởi T</string>
<string name="more_section_feature_flags">Cờ tính năng</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">方向</string>
<string name="inbound">进站</string>
<string name="loading">正在加载……</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b>分钟</string>
<string name="more_link">更多</string>
<string name="more_page_footer">Made with ♥ by the T</string>
<string name="more_section_feature_flags">功能标记</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="heading">方向</string>
<string name="inbound">進站</string>
<string name="loading">正在載入……</string>
<string name="minutes_abbr">&lt;b>%1$d&lt;/b>分鐘</string>
<string name="more_link">更多</string>
<string name="more_page_footer">Made with ♥ by the T</string>
<string name="more_section_feature_flags">功能標記</string>
Expand Down
7 changes: 6 additions & 1 deletion androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
<string name="icon_description_external_link" tools:ignore="MissingTranslation">External Link</string>
<string name="inbound">Inbound</string>
<string name="loading" tools:ignore="TypographyEllipsis">Loading...</string>
<string name="minutes_abbr" tools:ignore="MissingTranslation">%1$s min</string>
<!--
In order to preserve style tags while simultaneously formatting the string with parameters, we
must escape the html styling tags
https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML
-->
<string name="minutes_abbr">&lt;b>%1$d&lt;/b> min</string>
<string name="more_link">More</string>
<string name="more_page_footer">Made with ♥ by the T</string>
<string name="more_section_feature_flags">Feature Flags</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ abstract class ConvertIosLocalizationTask : DefaultTask() {

private fun convertIosTemplate(iosTemplate: String): String {
var unspecifiedIndex = 1
return iosTemplate.replace(template) {
replaceTemplate(it) { unspecifiedIndex.also { unspecifiedIndex += 1 } }
}
return iosTemplate
.replace(template) {
replaceTemplate(it) { unspecifiedIndex.also { unspecifiedIndex += 1 } }
}
.replace("""\*\*([^*]+)\*\*""".toRegex(), "<b>$1</b>")
}
}
}

0 comments on commit 9c27e6f

Please sign in to comment.