Skip to content

Commit 1935b24

Browse files
committed
Use translations
1 parent f0ea905 commit 1935b24

17 files changed

+87
-28
lines changed
15.7 KB
Loading
-279 KB
Binary file not shown.

README.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
WIP - Soon available as snap.
44

5-
| | |
6-
|-|-|
7-
|![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)|![screenshot_light_linux](.github/images/screenshot_light_linux.png)|
8-
9-
## Pulse Level 1
5+
![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)
106

7+
- [X] Dynamic, animated weather backgrounds
118
- [X] Display weather of current location
129
- [X] Display weather of a location X
13-
- [ ] Save your favorite locations
14-
- [ ] Filter per day/week
10+
- [X] Save your favorite locations
11+
- [X] Filter per day/week
1512
- [ ] Show news in your location
1613
- [ ] Show news of location X
1714
- [ ] Filter news by topic/location
@@ -33,10 +30,4 @@ sudo apt -y install git curl cmake meson make clang libgtk-3-dev pkg-config && m
3330

3431
### Api Key
3532

36-
Requires an api key from [openweathermap](https://openweathermap.org) which you need to create yourself (free tier) in your own account. If you did, create the file `apikey.json` under `/assets/` and add your api key as the value of the property `apiKey`.
37-
38-
```json
39-
{
40-
"apiKey": "YOUR_API_KEY_HERE"
41-
}
42-
```
33+
Requires an api key from [openweathermap](https://openweathermap.org) which you need to create yourself (free tier) in your own account.

l10n.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
arb-dir: lib/src/l10n
2+
template-arb-file: app_en.arb
3+
output-localization-file: app_localizations.dart
4+
nullable-getter: false
5+
untranslated-messages-file: needs_translation.json

lib/src/app/app.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:yaru/yaru.dart';
77

88
import '../../constants.dart';
99
import '../../weather.dart';
10+
import '../l10n/l10n.dart';
1011
import '../weather/weather_model.dart';
1112
import 'side_bar.dart';
1213

@@ -16,7 +17,9 @@ class App extends StatelessWidget {
1617
@override
1718
Widget build(BuildContext context) {
1819
return MaterialApp(
19-
title: kAppTitle,
20+
localizationsDelegates: AppLocalizations.localizationsDelegates,
21+
supportedLocales: supportedLocales,
22+
onGenerateTitle: (context) => 'MusicPod',
2023
debugShowCheckedModeBanner: false,
2124
theme: yaruLight,
2225
darkTheme: yaruDark.copyWith(
@@ -51,6 +54,12 @@ class AppPage extends StatefulWidget with WatchItStatefulWidgetMixin {
5154
class _AppPageState extends State<AppPage> {
5255
@override
5356
void initState() {
57+
YaruWindow.of(context).onClose(
58+
() async {
59+
await di.reset();
60+
return true;
61+
},
62+
);
5463
di<WeatherModel>().loadWeather();
5564
super.initState();
5665
}

lib/src/app/offline_page.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import 'package:flutter/material.dart';
22
import 'package:yaru/yaru.dart';
33

44
import '../build_context_x.dart';
5+
import '../l10n/l10n.dart';
56

67
class OfflinePage extends StatelessWidget {
78
const OfflinePage({super.key});
89

910
@override
1011
Widget build(BuildContext context) {
11-
final theme = context.theme;
1212
return YaruDetailPage(
1313
backgroundColor: Colors.transparent,
1414
appBar: YaruWindowTitleBar(
1515
border: BorderSide.none,
16-
title: const Text('Offline'),
16+
title: Text(context.l10n.offline),
1717
backgroundColor: Colors.transparent,
1818
leading: Navigator.of(context).canPop() == true
1919
? const YaruBackButton(

lib/src/l10n/app_de.arb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@@locale": "de",
3+
"save": "Speichern",
4+
"openWeatherApiKey": "OpenWeather API Schlüssel",
5+
"offline": "Keine Netzwerkverbindung",
6+
"cityName": "Ortsnamen",
7+
"cityNotFound": "Ort nicht gefunden",
8+
"enterACityName": "Bitte gib einen Ort ein",
9+
"enterValidApiKey": "Bitte gib einen (gültigen) API Schlüssel ein",
10+
"hourly": "Stündlich",
11+
"daily": "Täglich",
12+
"now": "Jetzt"
13+
}

lib/src/l10n/app_en.arb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@@locale": "en",
3+
"save": "Save",
4+
"openWeatherApiKey": "OpenWeather API key",
5+
"offline": "Offline",
6+
"cityName": "City name",
7+
"cityNotFound": "City not found",
8+
"enterACityName": "Please enter a city name",
9+
"enterValidApiKey": "Please enter a (valid) API key",
10+
"hourly": "Hourly",
11+
"daily": "Daily",
12+
"now": "Now"
13+
}

lib/src/l10n/l10n.dart

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2+
import 'package:flutter/widgets.dart';
3+
4+
export 'package:flutter_gen/gen_l10n/app_localizations.dart';
5+
6+
final List<Locale> supportedLocales = {
7+
const Locale('en'), // make sure 'en' comes first (#216)
8+
...List.of(AppLocalizations.supportedLocales)..remove(const Locale('en')),
9+
}.toList();
10+
11+
extension LocalizationsContext on BuildContext {
12+
AppLocalizations get l10n => AppLocalizations.of(this);
13+
}

lib/src/weather/view/city_search_field.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:yaru/yaru.dart';
44

55
import '../../../string_x.dart';
66
import '../../build_context_x.dart';
7+
import '../../l10n/l10n.dart';
78
import '../weather_model.dart';
89

910
class CitySearchField extends StatefulWidget with WatchItStatefulWidgetMixin {
@@ -65,12 +66,12 @@ class _CitySearchFieldState extends State<CitySearchField> {
6566
prefixIconConstraints:
6667
const BoxConstraints(minWidth: 35, minHeight: 30),
6768
filled: true,
68-
hintText: 'City name',
69+
hintText: context.l10n.cityName,
6970
errorText: widget.watchError
7071
? (error?.cityNotFound == true
71-
? 'City not found'
72+
? context.l10n.cityNotFound
7273
: error?.emptyCity == true
73-
? 'Please enter a city name'
74+
? context.l10n.enterACityName
7475
: error)
7576
: null,
7677
errorMaxLines: 10,

lib/src/weather/view/error_view.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:yaru/yaru.dart';
66
import '../../../string_x.dart';
77
import '../../app/offline_page.dart';
88
import '../../build_context_x.dart';
9+
import '../../l10n/l10n.dart';
910
import '../weather_model.dart';
1011
import 'city_search_field.dart';
1112

@@ -76,7 +77,7 @@ class _ErrorViewState extends State<ErrorView> {
7677
minWidth: 45,
7778
),
7879
suffixIcon: Tooltip(
79-
message: 'Save',
80+
message: context.l10n.save,
8081
child: ClipRRect(
8182
borderRadius: const BorderRadius.only(
8283
topRight: Radius.circular(kYaruButtonRadius),
@@ -98,7 +99,7 @@ class _ErrorViewState extends State<ErrorView> {
9899
),
99100
errorMaxLines: 5,
100101
errorText: widget.error.invalidKey
101-
? 'Please enter a valid API key'
102+
? context.l10n.enterValidApiKey
102103
: widget.error,
103104
border: const OutlineInputBorder(
104105
borderSide: BorderSide.none,
@@ -108,7 +109,7 @@ class _ErrorViewState extends State<ErrorView> {
108109
),
109110
fillColor: context.theme.colorScheme.surface
110111
.withOpacity(0.3),
111-
label: const Text('OpenWeather API key'),
112+
label: Text(context.l10n.openWeatherApiKey),
112113
),
113114
),
114115
),

lib/src/weather/view/today_tile.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:yaru/constants.dart';
55
import '../../../constants.dart';
66
import '../../../string_x.dart';
77
import '../../build_context_x.dart';
8+
import '../../l10n/l10n.dart';
89
import '../theme_x.dart';
910
import '../weather_data_x.dart';
1011

@@ -50,7 +51,7 @@ class TodayTile extends StatelessWidget {
5051
runAlignment: WrapAlignment.center,
5152
children: [
5253
Text(
53-
'Now',
54+
context.l10n.now,
5455
style: style?.copyWith(fontWeight: FontWeight.bold),
5556
),
5657
if (cityName != null)

lib/src/weather/view/weather_page.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:yaru/yaru.dart';
55
import '../../../constants.dart';
66
import '../../app/app_model.dart';
77
import '../../app/side_bar.dart';
8+
import '../../l10n/l10n.dart';
89
import 'forecast_chart.dart';
910
import 'today_chart.dart';
1011

@@ -51,9 +52,9 @@ class WeatherPage extends StatelessWidget with WatchItMixin {
5152
width: kPaneWidth,
5253
child: YaruTabBar(
5354
onTap: (v) => appModel.tabIndex = v,
54-
tabs: const [
55-
Tab(text: 'Hourly'),
56-
Tab(text: 'Daily'),
55+
tabs: [
56+
Tab(text: context.l10n.hourly),
57+
Tab(text: context.l10n.daily),
5758
],
5859
),
5960
),

lib/src/weather/weather_model.dart

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class WeatherModel extends SafeChangeNotifier {
9797
return weatherData;
9898
} catch (e) {
9999
error = e.toString();
100-
print(error);
101100
return null;
102101
}
103102
}

needs_translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

pubspec.lock

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ packages:
134134
url: "https://pub.dev"
135135
source: hosted
136136
version: "3.0.1"
137+
flutter_localizations:
138+
dependency: "direct main"
139+
description: flutter
140+
source: sdk
141+
version: "0.0.0"
137142
flutter_test:
138143
dependency: "direct dev"
139144
description: flutter

pubspec.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ dependencies:
1515
fl_chart: ^0.67.0
1616
flutter:
1717
sdk: flutter
18+
flutter_localizations:
19+
sdk: flutter
1820

1921
flutter_weather_bg_null_safety:
2022
git:
@@ -38,3 +40,7 @@ dev_dependencies:
3840

3941
flutter:
4042
uses-material-design: true
43+
generate: true
44+
45+
dependency_overrides:
46+
intl: 0.19.0

0 commit comments

Comments
 (0)