mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Make weather strings translatable
This commit is contained in:
+1
-1
@@ -369,7 +369,7 @@ public class DebugActivity extends AbstractGBActivity {
|
||||
|
||||
weatherSpec.location = "Green Hill";
|
||||
weatherSpec.currentConditionCode = 601; // snow
|
||||
weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentCondition = Weather.getConditionString(DebugActivity.this, weatherSpec.currentConditionCode);
|
||||
|
||||
weatherSpec.currentTemp = 15 + 273;
|
||||
weatherSpec.currentHumidity = 30;
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public class CMWeatherReceiver extends BroadcastReceiver implements CMWeatherMan
|
||||
weatherSpec.windDirection = (int) weatherInfo.getWindDirection();
|
||||
|
||||
weatherSpec.currentConditionCode = Weather.mapToOpenWeatherMapCondition(CMtoYahooCondintion(weatherInfo.getConditionCode()));
|
||||
weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentCondition = Weather.getConditionString(mContext, weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentHumidity = (int) weatherInfo.getHumidity();
|
||||
|
||||
weatherSpec.forecasts = new ArrayList<>();
|
||||
|
||||
+1
-1
@@ -184,7 +184,7 @@ public class LineageOsWeatherReceiver extends BroadcastReceiver implements Linea
|
||||
weatherSpec.windDirection = (int) weatherInfo.getWindDirection();
|
||||
|
||||
weatherSpec.currentConditionCode = Weather.mapToOpenWeatherMapCondition(LineageOSToYahooCondition(weatherInfo.getConditionCode()));
|
||||
weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentCondition = Weather.getConditionString(mContext, weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentHumidity = (int) weatherInfo.getHumidity();
|
||||
|
||||
weatherSpec.forecasts = new ArrayList<>();
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ public class OmniJawsObserver extends ContentObserver {
|
||||
|
||||
weatherSpec.location = c.getString(0);
|
||||
weatherSpec.currentConditionCode = Weather.mapToOpenWeatherMapCondition(c.getInt(2));
|
||||
weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
|
||||
weatherSpec.currentCondition = Weather.getConditionString(mContext, weatherSpec.currentConditionCode);
|
||||
//alternatively the following would also be possible
|
||||
//weatherSpec.currentCondition = c.getString(1);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -35,6 +37,8 @@ import java.io.ObjectStreamException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
public class Weather {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Weather.class);
|
||||
|
||||
@@ -472,183 +476,183 @@ public class Weather {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getConditionString(int openWeatherMapCondition) {
|
||||
public static String getConditionString(final Context context, int openWeatherMapCondition) {
|
||||
switch (openWeatherMapCondition) {
|
||||
case 200:
|
||||
return "thunderstorm with light rain";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_light_rain);
|
||||
case 201:
|
||||
return "thunderstorm with rain";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_rain);
|
||||
case 202:
|
||||
return "thunderstorm with heavy rain";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_heavy_rain);
|
||||
case 210:
|
||||
return "light thunderstorm:";
|
||||
return context.getString(R.string.weather_condition_light_thunderstorm);
|
||||
case 211:
|
||||
return "thunderstorm";
|
||||
return context.getString(R.string.weather_condition_thunderstorm);
|
||||
case 230:
|
||||
return "thunderstorm with light drizzle";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_light_drizzle);
|
||||
case 231:
|
||||
return "thunderstorm with drizzle";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_drizzle);
|
||||
case 232:
|
||||
return "thunderstorm with heavy drizzle";
|
||||
return context.getString(R.string.weather_condition_thunderstorm_with_heavy_drizzle);
|
||||
case 212:
|
||||
return "heavy thunderstorm";
|
||||
return context.getString(R.string.weather_condition_heavy_thunderstorm);
|
||||
case 221:
|
||||
return "ragged thunderstorm";
|
||||
//Group 3xx: Drizzle
|
||||
return context.getString(R.string.weather_condition_ragged_thunderstorm);
|
||||
// Group 3xx: Drizzle
|
||||
case 300:
|
||||
return "light intensity drizzle";
|
||||
return context.getString(R.string.weather_condition_light_intensity_drizzle);
|
||||
case 301:
|
||||
return "drizzle";
|
||||
return context.getString(R.string.weather_condition_drizzle);
|
||||
case 302:
|
||||
return "heavy intensity drizzle";
|
||||
return context.getString(R.string.weather_condition_heavy_intensity_drizzle);
|
||||
case 310:
|
||||
return "light intensity drizzle rain";
|
||||
return context.getString(R.string.weather_condition_light_intensity_drizzle_rain);
|
||||
case 311:
|
||||
return "drizzle rain";
|
||||
return context.getString(R.string.weather_condition_drizzle_rain);
|
||||
case 312:
|
||||
return "heavy intensity drizzle rain";
|
||||
return context.getString(R.string.weather_condition_heavy_intensity_drizzle_rain);
|
||||
case 313:
|
||||
return "shower rain and drizzle";
|
||||
return context.getString(R.string.weather_condition_shower_rain_and_drizzle);
|
||||
case 314:
|
||||
return "heavy shower rain and drizzle";
|
||||
return context.getString(R.string.weather_condition_heavy_shower_rain_and_drizzle);
|
||||
case 321:
|
||||
return "shower drizzle";
|
||||
//Group 5xx: Rain
|
||||
return context.getString(R.string.weather_condition_shower_drizzle);
|
||||
// Group 5xx: Rain
|
||||
case 500:
|
||||
return "light rain";
|
||||
return context.getString(R.string.weather_condition_light_rain);
|
||||
case 501:
|
||||
return "moderate rain";
|
||||
return context.getString(R.string.weather_condition_moderate_rain);
|
||||
case 502:
|
||||
return "heavy intensity rain";
|
||||
return context.getString(R.string.weather_condition_heavy_intensity_rain);
|
||||
case 503:
|
||||
return "very heavy rain";
|
||||
return context.getString(R.string.weather_condition_very_heavy_rain);
|
||||
case 504:
|
||||
return "extreme rain";
|
||||
return context.getString(R.string.weather_condition_extreme_rain);
|
||||
case 511:
|
||||
return "freezing rain";
|
||||
return context.getString(R.string.weather_condition_freezing_rain);
|
||||
case 520:
|
||||
return "light intensity shower rain";
|
||||
return context.getString(R.string.weather_condition_light_intensity_shower_rain);
|
||||
case 521:
|
||||
return "shower rain";
|
||||
return context.getString(R.string.weather_condition_shower_rain);
|
||||
case 522:
|
||||
return "heavy intensity shower rain";
|
||||
return context.getString(R.string.weather_condition_heavy_intensity_shower_rain);
|
||||
case 531:
|
||||
return "ragged shower rain";
|
||||
//Group 6xx: Snow
|
||||
return context.getString(R.string.weather_condition_ragged_shower_rain);
|
||||
// Group 6xx: Snow
|
||||
case 600:
|
||||
return "light snow";
|
||||
return context.getString(R.string.weather_condition_light_snow);
|
||||
case 601:
|
||||
return "snow";
|
||||
return context.getString(R.string.weather_condition_snow);
|
||||
case 620:
|
||||
return "light shower snow";
|
||||
return context.getString(R.string.weather_condition_light_shower_snow);
|
||||
case 602:
|
||||
return "heavy snow";
|
||||
return context.getString(R.string.weather_condition_heavy_snow);
|
||||
case 611:
|
||||
return "sleet";
|
||||
return context.getString(R.string.weather_condition_sleet);
|
||||
case 612:
|
||||
return "shower sleet";
|
||||
return context.getString(R.string.weather_condition_shower_sleet);
|
||||
case 621:
|
||||
return "shower snow";
|
||||
return context.getString(R.string.weather_condition_shower_snow);
|
||||
case 622:
|
||||
return "heavy shower snow";
|
||||
return context.getString(R.string.weather_condition_heavy_shower_snow);
|
||||
case 615:
|
||||
return "light rain and snow";
|
||||
return context.getString(R.string.weather_condition_light_rain_and_snow);
|
||||
case 616:
|
||||
return "rain and snow";
|
||||
//Group 7xx: Atmosphere
|
||||
return context.getString(R.string.weather_condition_rain_and_snow);
|
||||
// Group 7xx: Atmosphere
|
||||
case 701:
|
||||
return "mist";
|
||||
return context.getString(R.string.weather_condition_mist);
|
||||
case 711:
|
||||
return "smoke";
|
||||
return context.getString(R.string.weather_condition_smoke);
|
||||
case 721:
|
||||
return "haze";
|
||||
return context.getString(R.string.weather_condition_haze);
|
||||
case 731:
|
||||
return "sandcase dust whirls";
|
||||
return context.getString(R.string.weather_condition_sandcase_dust_whirls);
|
||||
case 741:
|
||||
return "fog";
|
||||
return context.getString(R.string.weather_condition_fog);
|
||||
case 751:
|
||||
return "sand";
|
||||
return context.getString(R.string.weather_condition_sand);
|
||||
case 761:
|
||||
return "dust";
|
||||
return context.getString(R.string.weather_condition_dust);
|
||||
case 762:
|
||||
return "volcanic ash";
|
||||
return context.getString(R.string.weather_condition_volcanic_ash);
|
||||
case 771:
|
||||
return "squalls";
|
||||
return context.getString(R.string.weather_condition_squalls);
|
||||
case 781:
|
||||
return "tornado";
|
||||
return context.getString(R.string.weather_condition_tornado);
|
||||
case 900:
|
||||
return "tornado";
|
||||
return context.getString(R.string.weather_condition_tornado);
|
||||
case 800:
|
||||
return "clear sky";
|
||||
//Group 80x: Clouds
|
||||
return context.getString(R.string.weather_condition_clear_sky);
|
||||
// Group 80x: Clouds
|
||||
case 801:
|
||||
return "few clouds";
|
||||
return context.getString(R.string.weather_condition_few_clouds);
|
||||
case 802:
|
||||
return "scattered clouds";
|
||||
return context.getString(R.string.weather_condition_scattered_clouds);
|
||||
case 803:
|
||||
return "broken clouds";
|
||||
return context.getString(R.string.weather_condition_broken_clouds);
|
||||
case 804:
|
||||
return "overcast clouds";
|
||||
//Group 90x: Extreme
|
||||
return context.getString(R.string.weather_condition_overcast_clouds);
|
||||
// Group 90x: Extreme
|
||||
case 901:
|
||||
return "tropical storm";
|
||||
return context.getString(R.string.weather_condition_tropical_storm);
|
||||
case 903:
|
||||
return "cold";
|
||||
return context.getString(R.string.weather_condition_cold);
|
||||
case 904:
|
||||
return "hot";
|
||||
return context.getString(R.string.weather_condition_hot);
|
||||
case 905:
|
||||
return "windy";
|
||||
return context.getString(R.string.weather_condition_windy);
|
||||
case 906:
|
||||
return "hail";
|
||||
//Group 9xx: Additional
|
||||
return context.getString(R.string.weather_condition_hail);
|
||||
// Group 9xx: Additional
|
||||
case 951:
|
||||
return "calm";
|
||||
return context.getString(R.string.weather_condition_calm);
|
||||
case 952:
|
||||
return "light breeze";
|
||||
return context.getString(R.string.weather_condition_light_breeze);
|
||||
case 953:
|
||||
return "gentle breeze";
|
||||
return context.getString(R.string.weather_condition_gentle_breeze);
|
||||
case 954:
|
||||
return "moderate breeze";
|
||||
return context.getString(R.string.weather_condition_moderate_breeze);
|
||||
case 955:
|
||||
return "fresh breeze";
|
||||
return context.getString(R.string.weather_condition_fresh_breeze);
|
||||
case 956:
|
||||
return "strong breeze";
|
||||
return context.getString(R.string.weather_condition_strong_breeze);
|
||||
case 957:
|
||||
return "high windcase near gale";
|
||||
return context.getString(R.string.weather_condition_high_windcase_near_gale);
|
||||
case 958:
|
||||
return "gale";
|
||||
return context.getString(R.string.weather_condition_gale);
|
||||
case 959:
|
||||
return "severe gale";
|
||||
return context.getString(R.string.weather_condition_severe_gale);
|
||||
case 960:
|
||||
return "storm";
|
||||
return context.getString(R.string.weather_condition_storm);
|
||||
case 961:
|
||||
return "violent storm";
|
||||
return context.getString(R.string.weather_condition_violent_storm);
|
||||
case 902:
|
||||
return "hurricane";
|
||||
return context.getString(R.string.weather_condition_hurricane);
|
||||
case 962:
|
||||
return "hurricane";
|
||||
return context.getString(R.string.weather_condition_hurricane);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAqiLevelString(int aqi) {
|
||||
public static String getAqiLevelString(final Context context, int aqi) {
|
||||
// Uses the [2023 Plume index](https://plumelabs.files.wordpress.com/2023/06/plume_aqi_2023.pdf) as a reference
|
||||
if (aqi < 0) {
|
||||
return "(n/a)";
|
||||
return context.getString(R.string.aqi_level_unknown);
|
||||
}
|
||||
if (aqi < 20) {
|
||||
return "excellent";
|
||||
return context.getString(R.string.aqi_level_excellent);
|
||||
} else if (aqi < 50) {
|
||||
return "fair";
|
||||
return context.getString(R.string.aqi_level_fair);
|
||||
} else if (aqi < 100) {
|
||||
return "poor";
|
||||
return context.getString(R.string.aqi_level_poor);
|
||||
} else if (aqi < 150) {
|
||||
return "unhealthy";
|
||||
return context.getString(R.string.aqi_level_unhealthy);
|
||||
} else if (aqi < 250) {
|
||||
return "very unhealthy";
|
||||
return context.getString(R.string.aqi_level_very_unhealthy);
|
||||
} else {
|
||||
return "dangerous";
|
||||
return context.getString(R.string.aqi_level_dangerous);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -3174,7 +3174,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
builder = performInitialized("Sending air quality index");
|
||||
int length = 8;
|
||||
int aqi = weatherSpec.airQuality != null ? weatherSpec.airQuality.aqi : -1;
|
||||
String aqiString = Weather.getAqiLevelString(aqi);
|
||||
String aqiString = Weather.getAqiLevelString(getContext(), aqi);
|
||||
if (supportsConditionString) {
|
||||
length += aqiString.getBytes().length + 1;
|
||||
}
|
||||
@@ -3213,7 +3213,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
bytesPerDay = 5;
|
||||
conditionsLength = weatherSpec.currentCondition.getBytes().length;
|
||||
for (WeatherSpec.Daily forecast : weatherSpec.forecasts) {
|
||||
conditionsLength += Weather.getConditionString(forecast.conditionCode).getBytes().length;
|
||||
conditionsLength += Weather.getConditionString(getContext(), forecast.conditionCode).getBytes().length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3260,7 +3260,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
buf.put((byte) forecastMinTemp);
|
||||
|
||||
if (supportsConditionString) {
|
||||
buf.put(Weather.getConditionString(forecast.conditionCode).getBytes());
|
||||
buf.put(Weather.getConditionString(getContext(), forecast.conditionCode).getBytes());
|
||||
buf.put((byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2131,6 +2131,85 @@
|
||||
<string name="warning">Warning!</string>
|
||||
<string name="note">Note</string>
|
||||
<string name="no_data">No data</string>
|
||||
<!-- Weathers -->
|
||||
<string name="weather_condition_thunderstorm_with_light_rain">thunderstorm with light rain</string>
|
||||
<string name="weather_condition_thunderstorm_with_rain">thunderstorm with rain</string>
|
||||
<string name="weather_condition_thunderstorm_with_heavy_rain">thunderstorm with heavy rain</string>
|
||||
<string name="weather_condition_light_thunderstorm">light thunderstorm</string>
|
||||
<string name="weather_condition_thunderstorm">thunderstorm</string>
|
||||
<string name="weather_condition_thunderstorm_with_light_drizzle">thunderstorm with light drizzle</string>
|
||||
<string name="weather_condition_thunderstorm_with_drizzle">thunderstorm with drizzle</string>
|
||||
<string name="weather_condition_thunderstorm_with_heavy_drizzle">thunderstorm with heavy drizzle</string>
|
||||
<string name="weather_condition_heavy_thunderstorm">heavy thunderstorm</string>
|
||||
<string name="weather_condition_ragged_thunderstorm">ragged thunderstorm</string>
|
||||
<string name="weather_condition_light_intensity_drizzle">light intensity drizzle</string>
|
||||
<string name="weather_condition_drizzle">drizzle</string>
|
||||
<string name="weather_condition_heavy_intensity_drizzle">heavy intensity drizzle</string>
|
||||
<string name="weather_condition_light_intensity_drizzle_rain">light intensity drizzle rain</string>
|
||||
<string name="weather_condition_drizzle_rain">drizzle rain</string>
|
||||
<string name="weather_condition_heavy_intensity_drizzle_rain">heavy intensity drizzle rain</string>
|
||||
<string name="weather_condition_shower_rain_and_drizzle">shower rain and drizzle</string>
|
||||
<string name="weather_condition_heavy_shower_rain_and_drizzle">heavy shower rain and drizzle</string>
|
||||
<string name="weather_condition_shower_drizzle">shower drizzle</string>
|
||||
<string name="weather_condition_light_rain">light rain</string>
|
||||
<string name="weather_condition_moderate_rain">moderate rain</string>
|
||||
<string name="weather_condition_heavy_intensity_rain">heavy intensity rain</string>
|
||||
<string name="weather_condition_very_heavy_rain">very heavy rain</string>
|
||||
<string name="weather_condition_extreme_rain">extreme rain</string>
|
||||
<string name="weather_condition_freezing_rain">freezing rain</string>
|
||||
<string name="weather_condition_light_intensity_shower_rain">light intensity shower rain</string>
|
||||
<string name="weather_condition_shower_rain">shower rain</string>
|
||||
<string name="weather_condition_heavy_intensity_shower_rain">heavy intensity shower rain</string>
|
||||
<string name="weather_condition_ragged_shower_rain">ragged shower rain</string>
|
||||
<string name="weather_condition_light_snow">light snow</string>
|
||||
<string name="weather_condition_snow">snow</string>
|
||||
<string name="weather_condition_light_shower_snow">light shower snow</string>
|
||||
<string name="weather_condition_heavy_snow">heavy snow</string>
|
||||
<string name="weather_condition_sleet">sleet</string>
|
||||
<string name="weather_condition_shower_sleet">shower sleet</string>
|
||||
<string name="weather_condition_shower_snow">shower snow</string>
|
||||
<string name="weather_condition_heavy_shower_snow">heavy shower snow</string>
|
||||
<string name="weather_condition_light_rain_and_snow">light rain and snow</string>
|
||||
<string name="weather_condition_rain_and_snow">rain and snow</string>
|
||||
<string name="weather_condition_mist">mist</string>
|
||||
<string name="weather_condition_smoke">smoke</string>
|
||||
<string name="weather_condition_haze">haze</string>
|
||||
<string name="weather_condition_sandcase_dust_whirls">sandcase dust whirls</string>
|
||||
<string name="weather_condition_fog">fog</string>
|
||||
<string name="weather_condition_sand">sand</string>
|
||||
<string name="weather_condition_dust">dust</string>
|
||||
<string name="weather_condition_volcanic_ash">volcanic ash</string>
|
||||
<string name="weather_condition_squalls">squalls</string>
|
||||
<string name="weather_condition_tornado">tornado</string>
|
||||
<string name="weather_condition_clear_sky">clear sky</string>
|
||||
<string name="weather_condition_few_clouds">few clouds</string>
|
||||
<string name="weather_condition_scattered_clouds">scattered clouds</string>
|
||||
<string name="weather_condition_broken_clouds">broken clouds</string>
|
||||
<string name="weather_condition_overcast_clouds">overcast clouds</string>
|
||||
<string name="weather_condition_tropical_storm">tropical storm</string>
|
||||
<string name="weather_condition_cold">cold</string>
|
||||
<string name="weather_condition_hot">hot</string>
|
||||
<string name="weather_condition_windy">windy</string>
|
||||
<string name="weather_condition_hail">hail</string>
|
||||
<string name="weather_condition_calm">calm</string>
|
||||
<string name="weather_condition_light_breeze">light breeze</string>
|
||||
<string name="weather_condition_gentle_breeze">gentle breeze</string>
|
||||
<string name="weather_condition_moderate_breeze">moderate breeze</string>
|
||||
<string name="weather_condition_fresh_breeze">fresh breeze</string>
|
||||
<string name="weather_condition_strong_breeze">strong breeze</string>
|
||||
<string name="weather_condition_high_windcase_near_gale">high windcase near gale</string>
|
||||
<string name="weather_condition_gale">gale</string>
|
||||
<string name="weather_condition_severe_gale">severe gale</string>
|
||||
<string name="weather_condition_storm">storm</string>
|
||||
<string name="weather_condition_violent_storm">violent storm</string>
|
||||
<string name="weather_condition_hurricane">hurricane</string>
|
||||
<string name="aqi_level_unknown">(n/a)</string>
|
||||
<string name="aqi_level_excellent">excellent</string>
|
||||
<string name="aqi_level_fair">fair</string>
|
||||
<string name="aqi_level_poor">poor</string>
|
||||
<string name="aqi_level_unhealthy">unhealthy</string>
|
||||
<string name="aqi_level_very_unhealthy">very unhealthy</string>
|
||||
<string name="aqi_level_dangerous">dangerous</string>
|
||||
<!-- LED Color -->
|
||||
<string name="preferences_led_color">LED Color</string>
|
||||
<!-- FM transmitters -->
|
||||
|
||||
Reference in New Issue
Block a user