Skip to content

Commit 2cf3849

Browse files
authored
Merge pull request #24 from hoc081098/codex/add-missing-string-resources-and-translations
Localize Accept-Language demo strings
2 parents 723c5d3 + 9fe7601 commit 2cf3849

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

app/src/main/java/com/hoc081098/jetpackcomposelocalization/DemoAcceptLanguageHeader.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.runtime.Immutable
2020
import androidx.compose.runtime.getValue
2121
import androidx.compose.ui.Alignment
2222
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.res.stringResource
2324
import androidx.compose.ui.unit.dp
2425
import androidx.lifecycle.ViewModel
2526
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -88,15 +89,19 @@ internal fun DemoAcceptLanguageHeader(
8889
) {
8990

9091
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
91-
Button(onClick = viewModel::get) { Text("GET") }
92-
OutlinedButton(onClick = viewModel::reset) { Text("Reset") }
92+
Button(onClick = viewModel::get) {
93+
Text(text = stringResource(id = R.string.demo_accept_language_get_button))
94+
}
95+
OutlinedButton(onClick = viewModel::reset) {
96+
Text(text = stringResource(id = R.string.demo_accept_language_reset_button))
97+
}
9398
}
9499

95100
Spacer(modifier = Modifier.height(8.dp))
96101

97102
when (val currentState = state) {
98103
DemoAcceptLanguageUiState.Idle ->
99-
Text(text = "Press GET to call httpbin.org/get")
104+
Text(text = stringResource(id = R.string.demo_accept_language_prompt))
100105

101106
DemoAcceptLanguageUiState.Loading ->
102107
Row(
@@ -106,7 +111,7 @@ internal fun DemoAcceptLanguageHeader(
106111
) {
107112
CircularProgressIndicator()
108113
Spacer(modifier = Modifier.width(8.dp))
109-
Text(text = "Loading…")
114+
Text(text = stringResource(id = R.string.demo_accept_language_loading))
110115
}
111116

112117
is DemoAcceptLanguageUiState.Success -> {
@@ -115,16 +120,28 @@ internal fun DemoAcceptLanguageHeader(
115120
horizontalAlignment = Alignment.CenterHorizontally,
116121
verticalArrangement = Arrangement.spacedBy(4.dp)
117122
) {
118-
Text(text = "Response success", style = MaterialTheme.typography.titleSmall)
119-
Text(text = "Response: ${currentState.data}")
123+
Text(
124+
text = stringResource(id = R.string.demo_accept_language_response_title),
125+
style = MaterialTheme.typography.titleSmall,
126+
)
127+
Text(
128+
text = stringResource(
129+
id = R.string.demo_accept_language_response,
130+
currentState.data.toString(),
131+
),
132+
)
120133
}
121134
}
122135

123-
is DemoAcceptLanguageUiState.Error ->
136+
is DemoAcceptLanguageUiState.Error -> {
137+
val message = currentState.message
138+
?: stringResource(id = R.string.demo_accept_language_error_unknown)
139+
124140
Text(
125-
text = "Error: ${currentState.message ?: "unknown"}",
141+
text = stringResource(id = R.string.demo_accept_language_error, message),
126142
color = MaterialTheme.colorScheme.error,
127143
)
144+
}
128145
}
129146
}
130147
}

app/src/main/res/values-vi/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
<string name="current_locale_language_country">Ngôn ngữ hiện tại: %1$s, ngôn ngữ: %2$s, quốc gia: %3$s, thẻ ngôn ngữ: %4$s</string>
55
<string name="follow_system">Theo hệ thống</string>
66
<string name="demo_datetime_formatter">Bây giờ là %1$s</string>
7+
<string name="demo_accept_language_get_button">Gọi GET</string>
8+
<string name="demo_accept_language_reset_button">Đặt lại</string>
9+
<string name="demo_accept_language_prompt">Nhấn GET để gọi httpbin.org/get</string>
10+
<string name="demo_accept_language_loading">Đang tải…</string>
11+
<string name="demo_accept_language_response_title">Phản hồi thành công</string>
12+
<string name="demo_accept_language_response">Phản hồi: %1$s</string>
13+
<string name="demo_accept_language_error">Lỗi: %1$s</string>
14+
<string name="demo_accept_language_error_unknown">không rõ</string>
715
</resources>

app/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
<string name="current_locale_language_country">Current locale: %1$s, language: %2$s, country: %3$s, languageTag: %4$s</string>
44
<string name="follow_system">Follow system</string>
55
<string name="demo_datetime_formatter">It is now %1$s</string>
6+
<string name="demo_accept_language_get_button">GET</string>
7+
<string name="demo_accept_language_reset_button">Reset</string>
8+
<string name="demo_accept_language_prompt">Press GET to call httpbin.org/get</string>
9+
<string name="demo_accept_language_loading">Loading…</string>
10+
<string name="demo_accept_language_response_title">Response success</string>
11+
<string name="demo_accept_language_response">Response: %1$s</string>
12+
<string name="demo_accept_language_error">Error: %1$s</string>
13+
<string name="demo_accept_language_error_unknown">unknown</string>
614
</resources>

0 commit comments

Comments
 (0)