From 2a0daaa806fe8d1d678f82bd004140ffb2cb42e8 Mon Sep 17 00:00:00 2001 From: Nebojsa Vuksic Date: Tue, 29 Jul 2025 15:47:03 +0200 Subject: [PATCH] Use Bundle to load string resources --- .../weatherApp/ui/WeatherAppSample.kt | 12 +++++-- .../ui/components/SearchToolbarMenu.kt | 2 +- .../ui/components/WeatherDetailsCard.kt | 35 +++++++++++++++---- .../messages/ComposeTemplate.properties | 15 ++++---- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt index bb9095d..ae40259 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt @@ -71,11 +71,18 @@ private fun LeftColumn( // TODO Set selected item on initial showing Column(modifier) { - GroupHeader("My Locations", modifier = Modifier.wrapContentHeight().fillMaxWidth()) + GroupHeader( + ComposeTemplateBundle.message("weather.app.my.locations.header.text"), + modifier = Modifier + .wrapContentHeight() + .fillMaxWidth() + ) Spacer(modifier = Modifier.height(10.dp)) val listState = rememberSelectableLazyListState() + + // TODO Check why preselection isn't working LaunchedEffect(myLocations) { listState .selectedKeys = myLocations @@ -95,7 +102,6 @@ private fun LeftColumn( items( items = myLocations, key = { item -> item }, - contentType = { item -> item.location }, ) { item -> ContentItemRow( @@ -138,7 +144,7 @@ private fun RightColumn( Column(modifier) { SearchToolbarMenu( searchAutoCompletionItemProvider = searchAutoCompletionItemProvider, - confirmButtonText = "Add", + confirmButtonText = ComposeTemplateBundle.message("weather.app.search.toolbar.menu.add.button.text"), onSearchPerformed = { place -> weatherViewModelApi.onLoadWeatherForecast(place) }, diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/SearchToolbarMenu.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/SearchToolbarMenu.kt index 3931f2f..54c805f 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/SearchToolbarMenu.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/SearchToolbarMenu.kt @@ -54,7 +54,7 @@ internal fun SearchToolbarMenu( Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { Icon( AllIconsKeys.Actions.AddList, - contentDescription = ComposeTemplateBundle.message("search.toolbar.menu.add.button.content.description") + contentDescription = ComposeTemplateBundle.message("weather.app.search.toolbar.menu.add.button.content.description") ) Text(confirmButtonText) } diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt index 2daa515..1f0db7d 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt @@ -23,6 +23,7 @@ import org.jetbrains.jewel.ui.component.HorizontallyScrollableContainer import org.jetbrains.jewel.ui.component.Icon import org.jetbrains.jewel.ui.component.Text import org.jetbrains.jewel.ui.icons.AllIconsKeys +import org.jetbrains.plugins.template.ComposeTemplateBundle import org.jetbrains.plugins.template.weatherApp.WeatherAppColors import org.jetbrains.plugins.template.weatherApp.model.DailyForecast import org.jetbrains.plugins.template.weatherApp.model.WeatherForecastData @@ -113,7 +114,10 @@ internal fun WeatherDetailsCard( // Temperature (emphasized) Text( - text = "${currentWeatherForecast.temperature.toInt()}°C", + text = ComposeTemplateBundle.message( + "weather.app.temperature.text", + currentWeatherForecast.temperature.toInt() + ), color = textColor, fontSize = 32.sp, fontWeight = FontWeight.ExtraBold @@ -139,14 +143,21 @@ internal fun WeatherDetailsCard( ) { // Wind info Text( - text = "Wind: ${currentWeatherForecast.windSpeed.toInt()} km/h ${currentWeatherForecast.windDirection.label}", + text = ComposeTemplateBundle.message( + "weather.app.wind.direction.text", + currentWeatherForecast.windSpeed.toInt(), + currentWeatherForecast.windDirection.label + ), color = textColor, fontSize = 16.sp ) // Humidity info Text( - text = "Humidity: ${currentWeatherForecast.humidity}%", + text = ComposeTemplateBundle.message( + "weather.app.humidity.text", + currentWeatherForecast.humidity + ), color = textColor, fontSize = 16.sp ) @@ -176,7 +187,7 @@ private fun SevenDaysForecastWidget( if (weatherForecastData.dailyForecasts.isNotEmpty()) { Column(modifier) { Text( - text = "7-Day Forecast", + text = ComposeTemplateBundle.message("weather.app.7days.forecast.title.text"), color = textColor, fontSize = 18.sp, fontWeight = FontWeight.Bold, @@ -262,7 +273,10 @@ private fun DayForecastItem( // Temperature Text( - text = "${forecast.temperature.toInt()}°C", + text = ComposeTemplateBundle.message( + "weather.app.temperature.text", + forecast.temperature.toInt() + ), color = textColor, fontSize = 16.sp, fontWeight = FontWeight.Bold @@ -272,7 +286,10 @@ private fun DayForecastItem( // Humidity Text( - text = "Humidity: ${forecast.humidity}%", + text = ComposeTemplateBundle.message( + "weather.app.humidity.text", + forecast.humidity + ), color = textColor, fontSize = 12.sp ) @@ -281,7 +298,11 @@ private fun DayForecastItem( // Wind direction Text( - text = "Wind: ${forecast.windDirection.label}", + text = ComposeTemplateBundle.message( + "weather.app.wind.direction.text", + forecast.windSpeed.toInt(), + forecast.windDirection.label + ), color = textColor, fontSize = 12.sp ) diff --git a/src/main/resources/messages/ComposeTemplate.properties b/src/main/resources/messages/ComposeTemplate.properties index 55e0807..becc060 100644 --- a/src/main/resources/messages/ComposeTemplate.properties +++ b/src/main/resources/messages/ComposeTemplate.properties @@ -1,8 +1,7 @@ -projectService=Project service: {0} -randomLabel=The random number is: {0} -shuffle=Shuffle -helloWorld=Hello world #{0} -increment=Moar -action.dev.sebastiano.jewel.ijplugin.demo.text=Jewel Demo Dialog - -search.toolbar.menu.add.button.content.description=Add a place to a watch list. \ No newline at end of file +weather.app.temperature.text={0}\u00B0C +weather.app.humidity.text=Humidity: {0}% +weather.app.wind.direction.text=Wind: {0} km/h {1} +weather.app.my.locations.header.text=My Locations +weather.app.search.toolbar.menu.add.button.text=Add +weather.app.search.toolbar.menu.add.button.content.description=Add a place to a watch list. +weather.app.7days.forecast.title.text=7-day Forecast \ No newline at end of file