Skip to content

Commit 067606a

Browse files
authored
Use translations (#9)
1 parent f0ea905 commit 067606a

19 files changed

+201
-155
lines changed
15.7 KB
Loading
-279 KB
Binary file not shown.

README.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
# Pulse - Weather and news app for the Ubuntu Desktop
1+
### Pulse - Weather app for the Linux Desktop
22

3-
WIP - Soon available as snap.
3+
[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/pulse)
44

5-
| | |
6-
|-|-|
7-
|![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)|![screenshot_light_linux](.github/images/screenshot_light_linux.png)|
5+
![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)
86

9-
## Pulse Level 1
7+
### Api Key
108

11-
- [X] Display weather of current location
12-
- [X] Display weather of a location X
13-
- [ ] Save your favorite locations
14-
- [ ] Filter per day/week
15-
- [ ] Show news in your location
16-
- [ ] Show news of location X
17-
- [ ] Filter news by topic/location
9+
Requires an api key from [openweathermap](https://openweathermap.org) which you need to create yourself (free tier) in your own account.
1810

1911
## Build
2012

@@ -30,13 +22,3 @@ sudo apt -y install git curl cmake meson make clang libgtk-3-dev pkg-config && m
3022
```
3123

3224
</details>
33-
34-
### Api Key
35-
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-
```

l10n.yaml

Lines changed: 5 additions & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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,

0 commit comments

Comments
 (0)