Skip to content

Commit

Permalink
Use translations (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Apr 28, 2024
1 parent f0ea905 commit 067606a
Show file tree
Hide file tree
Showing 19 changed files with 201 additions and 155 deletions.
Binary file modified .github/images/screenshot_dark_linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/images/screenshot_light_linux.png
Binary file not shown.
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# Pulse - Weather and news app for the Ubuntu Desktop
### Pulse - Weather app for the Linux Desktop

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

| | |
|-|-|
|![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)|![screenshot_light_linux](.github/images/screenshot_light_linux.png)|
![screenshot_dark_linux](.github/images/screenshot_dark_linux.png)

## Pulse Level 1
### Api Key

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

## Build

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

</details>

### Api Key

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`.

```json
{
"apiKey": "YOUR_API_KEY_HERE"
}
```
5 changes: 5 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
arb-dir: lib/src/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
nullable-getter: false
untranslated-messages-file: needs_translation.json
11 changes: 10 additions & 1 deletion lib/src/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:yaru/yaru.dart';

import '../../constants.dart';
import '../../weather.dart';
import '../l10n/l10n.dart';
import '../weather/weather_model.dart';
import 'side_bar.dart';

Expand All @@ -16,7 +17,9 @@ class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: kAppTitle,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: supportedLocales,
onGenerateTitle: (context) => 'MusicPod',
debugShowCheckedModeBanner: false,
theme: yaruLight,
darkTheme: yaruDark.copyWith(
Expand Down Expand Up @@ -51,6 +54,12 @@ class AppPage extends StatefulWidget with WatchItStatefulWidgetMixin {
class _AppPageState extends State<AppPage> {
@override
void initState() {
YaruWindow.of(context).onClose(
() async {
await di.reset();
return true;
},
);
di<WeatherModel>().loadWeather();
super.initState();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/app/offline_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';

import '../build_context_x.dart';
import '../l10n/l10n.dart';

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

@override
Widget build(BuildContext context) {
final theme = context.theme;
return YaruDetailPage(
backgroundColor: Colors.transparent,
appBar: YaruWindowTitleBar(
border: BorderSide.none,
title: const Text('Offline'),
title: Text(context.l10n.offline),
backgroundColor: Colors.transparent,
leading: Navigator.of(context).canPop() == true
? const YaruBackButton(
Expand Down
13 changes: 13 additions & 0 deletions lib/src/l10n/app_de.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@@locale": "de",
"save": "Speichern",
"openWeatherApiKey": "OpenWeather API Schlüssel",
"offline": "Keine Netzwerkverbindung",
"cityName": "Ortsnamen",
"cityNotFound": "Ort nicht gefunden",
"enterACityName": "Bitte gib einen Ort ein",
"enterValidApiKey": "Bitte gib einen (gültigen) API Schlüssel ein",
"hourly": "Stündlich",
"daily": "Täglich",
"now": "Jetzt"
}
13 changes: 13 additions & 0 deletions lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@@locale": "en",
"save": "Save",
"openWeatherApiKey": "OpenWeather API key",
"offline": "Offline",
"cityName": "City name",
"cityNotFound": "City not found",
"enterACityName": "Please enter a city name",
"enterValidApiKey": "Please enter a (valid) API key",
"hourly": "Hourly",
"daily": "Daily",
"now": "Now"
}
13 changes: 13 additions & 0 deletions lib/src/l10n/l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter/widgets.dart';

export 'package:flutter_gen/gen_l10n/app_localizations.dart';

final List<Locale> supportedLocales = {
const Locale('en'), // make sure 'en' comes first (#216)
...List.of(AppLocalizations.supportedLocales)..remove(const Locale('en')),
}.toList();

extension LocalizationsContext on BuildContext {
AppLocalizations get l10n => AppLocalizations.of(this);
}
7 changes: 4 additions & 3 deletions lib/src/weather/view/city_search_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:yaru/yaru.dart';

import '../../../string_x.dart';
import '../../build_context_x.dart';
import '../../l10n/l10n.dart';
import '../weather_model.dart';

class CitySearchField extends StatefulWidget with WatchItStatefulWidgetMixin {
Expand Down Expand Up @@ -65,12 +66,12 @@ class _CitySearchFieldState extends State<CitySearchField> {
prefixIconConstraints:
const BoxConstraints(minWidth: 35, minHeight: 30),
filled: true,
hintText: 'City name',
hintText: context.l10n.cityName,
errorText: widget.watchError
? (error?.cityNotFound == true
? 'City not found'
? context.l10n.cityNotFound
: error?.emptyCity == true
? 'Please enter a city name'
? context.l10n.enterACityName
: error)
: null,
errorMaxLines: 10,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/weather/view/error_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:yaru/yaru.dart';
import '../../../string_x.dart';
import '../../app/offline_page.dart';
import '../../build_context_x.dart';
import '../../l10n/l10n.dart';
import '../weather_model.dart';
import 'city_search_field.dart';

Expand Down Expand Up @@ -76,7 +77,7 @@ class _ErrorViewState extends State<ErrorView> {
minWidth: 45,
),
suffixIcon: Tooltip(
message: 'Save',
message: context.l10n.save,
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(kYaruButtonRadius),
Expand All @@ -98,7 +99,7 @@ class _ErrorViewState extends State<ErrorView> {
),
errorMaxLines: 5,
errorText: widget.error.invalidKey
? 'Please enter a valid API key'
? context.l10n.enterValidApiKey
: widget.error,
border: const OutlineInputBorder(
borderSide: BorderSide.none,
Expand All @@ -108,7 +109,7 @@ class _ErrorViewState extends State<ErrorView> {
),
fillColor: context.theme.colorScheme.surface
.withOpacity(0.3),
label: const Text('OpenWeather API key'),
label: Text(context.l10n.openWeatherApiKey),
),
),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/weather/view/today_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:yaru/constants.dart';
import '../../../constants.dart';
import '../../../string_x.dart';
import '../../build_context_x.dart';
import '../../l10n/l10n.dart';
import '../theme_x.dart';
import '../weather_data_x.dart';

Expand Down Expand Up @@ -50,7 +51,7 @@ class TodayTile extends StatelessWidget {
runAlignment: WrapAlignment.center,
children: [
Text(
'Now',
context.l10n.now,
style: style?.copyWith(fontWeight: FontWeight.bold),
),
if (cityName != null)
Expand Down
7 changes: 4 additions & 3 deletions lib/src/weather/view/weather_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:yaru/yaru.dart';
import '../../../constants.dart';
import '../../app/app_model.dart';
import '../../app/side_bar.dart';
import '../../l10n/l10n.dart';
import 'forecast_chart.dart';
import 'today_chart.dart';

Expand Down Expand Up @@ -51,9 +52,9 @@ class WeatherPage extends StatelessWidget with WatchItMixin {
width: kPaneWidth,
child: YaruTabBar(
onTap: (v) => appModel.tabIndex = v,
tabs: const [
Tab(text: 'Hourly'),
Tab(text: 'Daily'),
tabs: [
Tab(text: context.l10n.hourly),
Tab(text: context.l10n.daily),
],
),
),
Expand Down
Loading

0 comments on commit 067606a

Please sign in to comment.