Skip to content

Commit

Permalink
Bug/localize missing text (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
herzhenr committed Sep 23, 2023
1 parent df3df6e commit 2e3089b
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AppConstants {
if (context != null) {
return chipsWolPorts
.map((e) => CustomChoiceChip<int>(
label: "${AppLocalizations.of(context)!.formPort} ${e.value}",
label: AppLocalizations.of(context)!.formPort(e.value),
value: e.value))
.toList();
} else {
Expand Down
100 changes: 98 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,84 @@
"back": "Back",
"genericWarning": "Warning",
"@HOME": {},
"homeSortAlphabetical": "alphabetical",
"homeSortRecent": "recently",
"homeSortType": "type",
"homeAddDeviceButton": "Add Devices",
"homeNoDevices": "No devices yet. Add devices by clicking the + button below",
"homeFilterDevicesTitle": "Filter Devices",
"homeDeviceListTitle": "Devices",
"homeEditDeviceAlertTitle": "Edit Device",
"homeDeviceCardWakeButton": "Wake Up",
"homeDeviceCardEditButton": "Edit",
"homeDeviceCardOnline": "Device is online",
"homeDeviceCardOffline": "Device is offline",
"homeWolCardTitle": "Waking up...",
"homeWolCardIp": "'{ip}' is an invalid IPv4 address",
"@homeWolCardIp": {
"placeholders": {
"ip": {
"type": "String",
"example": "192.168.0.1",
"description": "The IP address which was provided by the user."
}
}
},
"homeWolCardMac": "'{mac}' is an invalid MAC address",
"@homeWolCardMac": {
"placeholders": {
"mac": {
"type": "String",
"example": "12:AB:00:00:00:00",
"description": "The MAC address which was provided by the user."
}
}
},
"homeWolCardPort": "'{port}' is an invalid port",
"@homeWolCardPort": {
"placeholders": {
"port": {
"type": "String",
"example": "9",
"description": "The port number which was provided by the user."
}
}
},
"homeWolCardInvalid": "There was an error trying to send a WOL Package",
"homeWolCardValid": "Provided device details are valid",
"homeWolCardSendWol": "Trying to send WOL Packages",
"homeWolCardSendWolSuccess": "Successfully send WOL packages to {ip}",
"@homeWolCardSendWolSuccess": {
"placeholders": {
"ip": {
"type": "String",
"example": "192.168.0.1",
"description": "The IP address of the device which was woken up."
}
}
},
"homeWolCardSendWolFail": "There was an error when trying to send WOL Packages to the host {ip}",
"@homeWolCardSendWolFail": {
"placeholders": {
"ip": {
"type": "String",
"example": "192.168.0.1",
"description": "The IP address of the device which could not be woken up."
}
}
},
"homeWolCardPingInfo": "Trying to ping device until it is online...",
"homeWolCardPing": "Sending ping #{count}",
"@homeWolCardPing": {
"placeholders": {
"count": {
"type": "int",
"example": "1"
}
}
},
"homeWolCardPingSuccess": "Device is online",
"homeWolCardPingFail": "Device is still offline",
"@DISCOVER": {},
"discoverTitle": "Discover Devices",
"discoverCardTitle": "Network Scan",
Expand All @@ -49,7 +118,15 @@
"formIconLabel": "Icon",
"formIconError": "no device type selected",
"formIconErrorTitle": "Wrong Format",
"formPort": "Port",
"formPort": "Port {port}",
"@formPort": {
"placeholders": {
"port": {
"type": "int",
"example": "9"
}
}
},
"formErrorMessageName": "device has no name",
"formErrorMessageIp": "invalid IP Address",
"formErrorMessageMac": "invalid MAC Address",
Expand Down Expand Up @@ -104,5 +181,24 @@
"aboutInfoText": "A simple tool to wake devices in the local network remotely if they are turned off. This app tries to make this process easy for the user.",
"aboutOpenSourceTitle": "Open Source",
"aboutOpenSourceCodeButton": "Source Code",
"aboutOpenSourceLicenseButton": "Licenses"
"aboutOpenSourceLicenseButton": "Licenses",
"aboutVersionText": "Version: {version} ({buildNumber})",
"@aboutVersionText": {
"placeholders": {
"version": {
"type": "String",
"example": "1.0.0"
},
"buildNumber": {
"type": "String",
"example": "1"
}
}
},
"aboutWebPlatformError": "Web platform isn't supported",
"aboutFuchsiaPlatformError": "Fuchsia platform isn't supported",
"aboutLinuxPlatformError": "Linux platform isn't supported",
"aboutMacOSPlatformError": "macOS platform isn't supported",
"aboutWindowsPlatformError": "Windows platform isn't supported",
"aboutNoPlatformDetected": "Failed to get platform version"
}
39 changes: 20 additions & 19 deletions lib/screens/about/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ class _AboutPageState extends State<AboutPage> {
@override
void initState() {
super.initState();
initPlatformState();
initWifiAddress();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
// not in initSate because buildContext is needed
initPlatformState();
}

Future<void> initPlatformState() async {
var deviceData = <String, dynamic>{};

try {
if (kIsWeb) {
deviceData = <String, dynamic>{
'Error:': 'Web platform isn\'t supported'
'Error:': AppLocalizations.of(context)!.aboutWebPlatformError
};
} else {
switch (defaultTargetPlatform) {
Expand All @@ -60,29 +66,29 @@ class _AboutPageState extends State<AboutPage> {
break;
case TargetPlatform.fuchsia:
deviceData = <String, dynamic>{
'Error:': 'Fuchsia platform isn\'t supported'
'Error:': AppLocalizations.of(context)!.aboutFuchsiaPlatformError
};
break;
case TargetPlatform.linux:
deviceData = <String, dynamic>{
'Error:': 'Linux platform isn\'t supported'
'Error:': AppLocalizations.of(context)!.aboutLinuxPlatformError
};
break;
case TargetPlatform.macOS:
deviceData = <String, dynamic>{
'Error:': 'MacOS platform isn\'t supported'
'Error:': AppLocalizations.of(context)!.aboutMacOSPlatformError
};
break;
case TargetPlatform.windows:
deviceData = <String, dynamic>{
'Error:': 'Windows platform isn\'t supported'
'Error:': AppLocalizations.of(context)!.aboutWindowsPlatformError
};
break;
}
}
} on PlatformException {
deviceData = <String, dynamic>{
'Error:': 'Failed to get platform version.'
'Error:': AppLocalizations.of(context)!.aboutNoPlatformDetected
};
}

Expand Down Expand Up @@ -163,14 +169,10 @@ class _AboutPageState extends State<AboutPage> {
children: [
VersionText(text: widget.packageInfo.appName),
VersionText(text: widget.packageInfo.packageName),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const VersionText(text: "Version "),
VersionText(text: widget.packageInfo.version),
VersionText(text: " (${widget.packageInfo.buildNumber})"),
],
),
VersionText(
text: AppLocalizations.of(context)!.aboutVersionText(
widget.packageInfo.version,
widget.packageInfo.buildNumber)),
],
)
],
Expand All @@ -188,15 +190,14 @@ class _AboutPageState extends State<AboutPage> {
child: InkWell(
borderRadius: AppConstants.borderRadius,
child: ListTile(
// title: const Text("iPhone XR"),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _deviceData.keys.map((String property) {
return Text('${_deviceData[property]}');
}).toList(), // Text("IP: $_wifiAddress \nMAC: 12:12:12:12:12")
return Text(_deviceData[property].toString());
}).toList(),
),
subtitle: Text(
"IP: $_wifiAddress",
"${AppConstants.ipText}: $_wifiAddress",
style: Theme.of(context).textTheme.bodySmall,
),
minLeadingWidth: 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/bottom_sheet_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class _ModularBottomFormPageState extends State<ModularBottomFormPage> {
TextSpan(text: AppLocalizations.of(context)!.formDeleteAlertText),
if (widget.controllerName.text.isNotEmpty)
TextSpan(
text: " ${widget.controllerName.text}",
text: widget.controllerName.text,
style: const TextStyle(fontWeight: FontWeight.bold)),
const TextSpan(text: '?'),
],
Expand Down
18 changes: 10 additions & 8 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ class _HomePageState extends State<HomePage> {
sortDevices();
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<SortingOrder>>[
const PopupMenuItem<SortingOrder>(
PopupMenuItem<SortingOrder>(
value: SortingOrder.alphabetical,
child: Text('alphabetical'),
child: Text(AppLocalizations.of(context)!.homeSortAlphabetical),
),
const PopupMenuItem<SortingOrder>(
PopupMenuItem<SortingOrder>(
value: SortingOrder.recently,
child: Text('recently'),
child: Text(AppLocalizations.of(context)!.homeSortRecent),
),
const PopupMenuItem<SortingOrder>(
PopupMenuItem<SortingOrder>(
value: SortingOrder.type,
child: Text('type'),
child: Text(AppLocalizations.of(context)!.homeSortType),
),
],
),
Expand Down Expand Up @@ -458,7 +458,8 @@ class _HomePageState extends State<HomePage> {
showCustomBottomSheet(
context: context,
formPage: EditDeviceFormPage(
title: "Edit Device",
title: AppLocalizations.of(context)!
.homeEditDeviceAlertTitle,
device: device,
devices: _devices,
onSubmitDeviceCallback: updateDevicesList))
Expand All @@ -472,7 +473,8 @@ class _HomePageState extends State<HomePage> {
context: context,
builder: (context) {
return StreamBuilder<List<Message>>(
stream: sendWolAndGetMessages(device: device.toNetworkDevice()),
stream: sendWolAndGetMessages(
context: context, device: device.toNetworkDevice()),
builder: (BuildContext context,
AsyncSnapshot<List<Message>> snapshot) {
// set color, text and icon of dialog box according to the arrived messages
Expand Down

0 comments on commit 2e3089b

Please sign in to comment.