Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.5.2 with Notification Service fix #1806

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import RuuviLocalization
import UserNotifications

class NotificationService: UNNotificationServiceExtension {
Expand Down Expand Up @@ -106,62 +107,45 @@ extension NotificationService {
return ""
}

var format = ""
let languageUDKey = "SettingsUserDegaults.languageUDKey"
let locale: Locale
if let languageCode = notificationServiceAppGroup?.string(forKey: languageUDKey) {
locale = Locale(identifier: languageCode)
} else {
locale = .current
}

switch triggerType {
case .under:
switch alertType {
case .temperature:
format = "alert_notification_temperature_low_threshold"
return RuuviLocalization.alertNotificationTemperatureLowThreshold(threshold, locale)
case .humidity:
format = "alert_notification_humidity_low_threshold"
return RuuviLocalization.alertNotificationHumidityLowThreshold(threshold, locale)
case .pressure:
format = "alert_notification_pressure_low_threshold"
return RuuviLocalization.alertNotificationPressureLowThreshold(threshold, locale)
case .signal:
format = "alert_notification_rssi_low_threshold"
return RuuviLocalization.alertNotificationRssiLowThreshold(threshold, locale)
case .movement:
let format = "LocalNotificationsManager.DidMove.title"
return localized(value: format)
default:
break
return RuuviLocalization.LocalNotificationsManager.DidMove.title // TODO: @rinat localize
case .offline:
return "" // TODO: @rinat obtain spec
}
case .over:
switch alertType {
case .temperature:
format = "alert_notification_temperature_high_threshold"
return RuuviLocalization.alertNotificationTemperatureHighThreshold(threshold, locale)
case .humidity:
format = "alert_notification_humidity_high_threshold"
return RuuviLocalization.alertNotificationHumidityHighThreshold(threshold, locale)
case .pressure:
format = "alert_notification_pressure_high_threshold"
return RuuviLocalization.alertNotificationPressureHighThreshold(threshold, locale)
case .signal:
format = "alert_notification_rssi_high_threshold"
return RuuviLocalization.alertNotificationRssiHighThreshold(threshold, locale)
case .movement:
let format = "LocalNotificationsManager.DidMove.title"
return localized(value: format)
default:
break
return RuuviLocalization.LocalNotificationsManager.DidMove.title // TODO: @rinat localize
case .offline:
return "" // TODO: @rinat obtain spec
}
}

return String(format: localized(value: format), threshold)
}

private func localized(value: String) -> String {
let languageUDKey = "SettingsUserDegaults.languageUDKey"
guard let languageCode = notificationServiceAppGroup?.string(forKey: languageUDKey),
let bundle = Bundle.main.path(
forResource: languageCode,
ofType: "lproj"
),
let languageBundle = Bundle(path: bundle)
else {
return NSLocalizedString(value, comment: value)
}

return NSLocalizedString(
value,
tableName: nil,
bundle: languageBundle,
comment: value
)
}
}
26 changes: 25 additions & 1 deletion Apps/RuuviStation/NotificationService/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ targets:
excludes:
- "*.entitlements"
- Info.plist
- path: ../Widgets/Sources
resources:
- path: ../Sources/Resources/Strings/
- path: ../Sources/Resources/Sounds/
- path: ../Sources/Resources/Sounds/
dependencies:
- package: Swinject
- package: BTKit
- package: Future
- package: GRDB
- package: Humidity
- package: KeychainAccess
- target: RuuviUser
embed: true
- target: RuuviCloud
embed: true
- target: RuuviOntology
embed: true
- target: RuuviPool
embed: true
- target: RuuviLocal
embed: true
- target: RuuviPersistence
embed: true
- target: RuuviContext
embed: true
- target: RuuviLocalization
embed: true
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ extension TagChartsViewController: TagChartsViewInput {
syncStatusLabel.text = RuuviLocalization.TagCharts.Status.serving
case let .reading(points):
let format = RuuviLocalization.readingHistoryX
syncStatusLabel.text = format(Float(points))
syncStatusLabel.text = format(Float(points), Locale.current)
case .disconnecting:
syncStatusLabel.text = RuuviLocalization.TagCharts.Status.disconnecting
case .success:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ extension OffsetCorrectionAppleViewController: OffsetCorrectionViewInput {
case .pressure:
let format = RuuviLocalization.OffsetCorrection.Dialog.Calibration.enterPressure
let unit = viewModel.pressureUnit.value ?? .hectopascals
message = format(unit.symbol)
message = format(unit.symbol, Locale.current)
default:
let format = RuuviLocalization.OffsetCorrection.Dialog.Calibration.enterTemperature
let unit = viewModel.temperatureUnit.value ?? .celsius
message = format(unit.symbol)
message = format(unit.symbol, Locale.current)
}

let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class TagSettingsViewController: UIViewController {

private lazy var temperatureAlertSection: TagSettingsSection? = {
let sectionTitle = temperatureAlertFormat(
viewModel?.temperatureUnit.value?.symbol ?? RuuviLocalization.na
viewModel?.temperatureUnit.value?.symbol ?? RuuviLocalization.na,
Locale.current
)
let section = TagSettingsSection(
identifier: .alertTemperature,
Expand All @@ -203,7 +204,7 @@ class TagSettingsViewController: UIViewController {

private lazy var humidityAlertSection: TagSettingsSection? = {
let symbol = HumidityUnit.percent.symbol
let sectionTitle = airHumidityAlertFormat(symbol)
let sectionTitle = airHumidityAlertFormat(symbol, Locale.current)
let section = TagSettingsSection(
identifier: .alertHumidity,
title: sectionTitle,
Expand All @@ -227,7 +228,7 @@ class TagSettingsViewController: UIViewController {

private lazy var pressureAlertSection: TagSettingsSection? = {
let sectionTitle = pressureAlertFormat(
viewModel?.pressureUnit.value?.symbol ?? RuuviLocalization.na
viewModel?.pressureUnit.value?.symbol ?? RuuviLocalization.na, Locale.current
)
let section = TagSettingsSection(
identifier: .alertPressure,
Expand Down Expand Up @@ -941,7 +942,7 @@ extension TagSettingsViewController {
tableView.bind(viewModel.temperatureUnit) { [weak self] _, value in
guard let sSelf = self else { return }
sSelf.temperatureAlertSection?.title = sSelf.temperatureAlertFormat(
value?.symbol ?? RuuviLocalization.na
value?.symbol ?? RuuviLocalization.na, Locale.current
)
}

Expand Down Expand Up @@ -999,7 +1000,7 @@ extension TagSettingsViewController {
header, unit in
guard let sSelf = self else { return }
let sectionTitle = sSelf.temperatureAlertFormat(
unit?.symbol ?? RuuviLocalization.na
unit?.symbol ?? RuuviLocalization.na, Locale.current
)
header.setTitle(with: sectionTitle)
}
Expand Down Expand Up @@ -1119,7 +1120,7 @@ extension TagSettingsViewController {
tableView.bind(viewModel.pressureUnit) { [weak self] _, value in
guard let sSelf = self else { return }
sSelf.pressureAlertSection?.title = sSelf.pressureAlertFormat(
value?.symbol ?? RuuviLocalization.na
value?.symbol ?? RuuviLocalization.na, Locale.current
)
}

Expand Down Expand Up @@ -1179,7 +1180,7 @@ extension TagSettingsViewController {
[weak self] header, unit in
guard let sSelf = self else { return }
let sectionTitle = sSelf.pressureAlertFormat(
unit?.symbol ?? RuuviLocalization.na
unit?.symbol ?? RuuviLocalization.na, Locale.current
)
header.setTitle(with: sectionTitle)
}
Expand Down Expand Up @@ -1876,13 +1877,27 @@ extension TagSettingsViewController {
guard isViewLoaded else { return nil }
let format = RuuviLocalization.TagSettings.Alerts.Temperature.description
if let min, let max {
return attributedString(from: format(Float(min), Float(max)))
return attributedString(from: format(Float(min), Float(max), Locale.current))
}

if let tu = viewModel?.temperatureUnit.value?.unitTemperature,
let l = viewModel?.temperatureLowerBound.value?.converted(to: tu),
let u = viewModel?.temperatureUpperBound.value?.converted(to: tu) {
return attributedString(from: format(Float(l.value.round(to: 2)), Float(u.value.round(to: 2))))
return attributedString(
from: format(
Float(
l.value.round(
to: 2
)
),
Float(
u.value.round(
to: 2
)
),
Locale.current
)
)
} else {
return nil
}
Expand Down Expand Up @@ -1932,13 +1947,14 @@ extension TagSettingsViewController {
guard isViewLoaded else { return nil }
let format = RuuviLocalization.TagSettings.Alerts.Temperature.description
if let min, let max {
return attributedString(from: format(Float(min), Float(max)))
return attributedString(from: format(Float(min), Float(max), Locale.current))
}
if let l = viewModel?.relativeHumidityLowerBound.value,
let u = viewModel?.relativeHumidityUpperBound.value {
let message = format(
Float(l.round(to: 2)),
Float(u.round(to: 2))
Float(u.round(to: 2)),
Locale.current
)
return attributedString(from: message)
} else {
Expand Down Expand Up @@ -1984,7 +2000,7 @@ extension TagSettingsViewController {

if let minValue, let maxValue {
return attributedString(
from: format(Float(minValue), Float(maxValue))
from: format(Float(minValue), Float(maxValue), Locale.current)
)
}

Expand All @@ -2001,7 +2017,8 @@ extension TagSettingsViewController {
)
let message = format(
Float(l.round(to: 2)),
Float(u.round(to: 2))
Float(u.round(to: 2)),
Locale.current
)
return attributedString(from: message)
} else {
Expand Down Expand Up @@ -2063,15 +2080,16 @@ extension TagSettingsViewController {

if let min, let max {
return attributedString(
from: format(Float(min), Float(max))
from: format(Float(min), Float(max), Locale.current)
)
}

if let lower = viewModel?.signalLowerBound.value,
let upper = viewModel?.signalUpperBound.value {
let message = format(
Float(lower),
Float(upper)
Float(upper),
Locale.current
)
return attributedString(from: message)
} else {
Expand Down Expand Up @@ -3740,7 +3758,7 @@ extension TagSettingsViewController {
alertTextField.delegate = self
let format = RuuviLocalization.TagSettings.AlertSettings.Dialog.min
alertTextField.placeholder = format(
Float(minimumBound)
Float(minimumBound), Locale.current
)
alertTextField.keyboardType = .decimalPad
alertMinRangeTextField = alertTextField
Expand All @@ -3757,7 +3775,7 @@ extension TagSettingsViewController {
alertTextField.delegate = self
let format = RuuviLocalization.TagSettings.AlertSettings.Dialog.max
alertTextField.placeholder = format(
Float(maximumBound)
Float(maximumBound), Locale.current
)
alertTextField.keyboardType = .decimalPad
alertMaxRangeTextField = alertTextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ extension HumidityUnit: SelectionItemProtocol {
switch self {
case .percent: { _ in RuuviLocalization.HumidityUnit.Percent.title }
case .gm3: { _ in RuuviLocalization.HumidityUnit.Gm3.title }
case .dew:
RuuviLocalization.HumidityUnit.Dew.title
case .dew: { param in RuuviLocalization.HumidityUnit.Dew.title(param, Locale.current) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ struct ExportHeadersProvider: RuuviServiceExportHeaders {
let humidityFormat = RuuviLocalization.ExportService.humidity
return [
RuuviLocalization.ExportService.date,
tempFormat(units.temperatureUnit.symbol),
tempFormat(units.temperatureUnit.symbol, Locale.current),
units.humidityUnit == .dew
? humidityFormat(units.temperatureUnit.symbol)
: humidityFormat(units.humidityUnit.symbol),
pressureFormat(units.pressureUnit.symbol),
? humidityFormat(units.temperatureUnit.symbol, Locale.current)
: humidityFormat(units.humidityUnit.symbol, Locale.current),
pressureFormat(units.pressureUnit.symbol, Locale.current),
"RSSI" + " (\(RuuviLocalization.dBm))",
RuuviLocalization.ExportService.accelerationX + " (\(RuuviLocalization.g))",
RuuviLocalization.ExportService.accelerationY + " (\(RuuviLocalization.g))",
Expand Down
8 changes: 4 additions & 4 deletions Apps/RuuviStation/Sources/Station.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<string>applinks:network.ruuvi.com</string>
<string>applinks:station.ruuvi.com</string>
</array>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.ruuvi.station.pnservice</string>
Expand Down
19 changes: 14 additions & 5 deletions Common/RuuviLocalization/Templates/strings-swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import Foundation
{% endif %}
{% set translation string.translation|replace:'"','\"'|replace:' ','\t' %}
{% if string.types %}
{{accessModifier}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
{{enumName}}.tr("{{table}}", "{{string.key}}", {%+ call argumentsBlock string.types %}, fallback: "{{translation}}")
{{accessModifier}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}, _ locale: Locale = Locale.current) -> String {
{{enumName}}.tr("{{table}}", "{{string.key}}", {%+ call argumentsBlock string.types %}, fallback: "{{translation}}", locale: locale)
}
{% elif param.lookupFunction %}
{{accessModifier}} static var {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}", fallback: "{{translation}}") }
Expand Down Expand Up @@ -75,13 +75,22 @@ import Foundation
// MARK: - Implementation Details

extension {{enumName}} {
private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String) -> String {
private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String, locale: Locale = Locale.current) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
{% else %}
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
let format: String
if let bundle = BundleToken.bundle.path(
forResource: locale.identifier,
ofType: "lproj"
), let languageBundle = Bundle(path: bundle) {
format = languageBundle.localizedString(forKey: key, value: value, table: table)
} else {
format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
}

{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
return String(format: format, locale: locale, arguments: args)
}
}
{% if not param.bundle and not param.lookupFunction %}
Expand Down
Loading
Loading