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

Today widget localization #15614

Merged
Prev Previous commit
Next Next commit
move LocalizedStringKey extension to a separate file
Giorgio Ruscigno committed Jan 13, 2021
commit 0c1de986211f5f9e114aa2452194a94653824b2a
12 changes: 12 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -403,6 +403,7 @@
3F1FD2502548AD8B0060C53A /* TodayWidgetStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98E58A2E2360D23400E5534B /* TodayWidgetStats.swift */; };
3F1FD27B2548AE900060C53A /* CocoaLumberjack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938CF3DB1EF1BE6800AF838E /* CocoaLumberjack.swift */; };
3F1FD30D2548B0A80060C53A /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CC05F51962150600975CAC /* Constants.m */; };
3F2656A125AF4DFA0073A832 /* LocalizedStringKey+extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2656A025AF4DFA0073A832 /* LocalizedStringKey+extension.swift */; };
3F29EB7224042276005313DE /* MeViewController+UIViewControllerRestoration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F29EB7124042276005313DE /* MeViewController+UIViewControllerRestoration.swift */; };
3F2F0C16256C6B2C003351C7 /* HomeWidgetTodayRemoteService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2F0C15256C6B2C003351C7 /* HomeWidgetTodayRemoteService.swift */; };
3F3087C424EDB7040087B548 /* AnnouncementCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F3087C324EDB7040087B548 /* AnnouncementCell.swift */; };
@@ -2939,6 +2940,7 @@
3F1AD48023FC87A400BB1375 /* BlogDetailsViewController+MeButtonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlogDetailsViewController+MeButtonTests.swift"; sourceTree = "<group>"; };
3F1B66A223A2F54B0075F09E /* ReaderReblogActionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderReblogActionTests.swift; sourceTree = "<group>"; };
3F1FD31C2548B30D0060C53A /* WordPressHomeWidgetToday-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WordPressHomeWidgetToday-Bridging-Header.h"; sourceTree = "<group>"; };
3F2656A025AF4DFA0073A832 /* LocalizedStringKey+extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LocalizedStringKey+extension.swift"; sourceTree = "<group>"; };
3F26DFD124930B5900B5EBD1 /* WordPress 96.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 96.xcdatamodel"; sourceTree = "<group>"; };
3F29EB7124042276005313DE /* MeViewController+UIViewControllerRestoration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MeViewController+UIViewControllerRestoration.swift"; sourceTree = "<group>"; };
3F2F0C15256C6B2C003351C7 /* HomeWidgetTodayRemoteService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWidgetTodayRemoteService.swift; sourceTree = "<group>"; };
@@ -6327,6 +6329,14 @@
name = ReaderPostActions;
sourceTree = "<group>";
};
3F26569F25AF4DBF0073A832 /* Localization */ = {
isa = PBXGroup;
children = (
3F2656A025AF4DFA0073A832 /* LocalizedStringKey+extension.swift */,
);
path = Localization;
sourceTree = "<group>";
};
3F29EB6724041F47005313DE /* Activity Logs */ = {
isa = PBXGroup;
children = (
@@ -6599,6 +6609,7 @@
3F5689EF254209790048A9E4 /* TodayWidgetSmallView.swift */,
3F5689FF25420DE80048A9E4 /* TodayWidgetMediumView.swift */,
3F568A1D254210950048A9E4 /* Cards */,
3F26569F25AF4DBF0073A832 /* Localization */,
);
path = Views;
sourceTree = "<group>";
@@ -14284,6 +14295,7 @@
3F1FD2502548AD8B0060C53A /* TodayWidgetStats.swift in Sources */,
3F2F0C16256C6B2C003351C7 /* HomeWidgetTodayRemoteService.swift in Sources */,
3F526D572539FAC60069706C /* TodayWidgetView.swift in Sources */,
3F2656A125AF4DFA0073A832 /* LocalizedStringKey+extension.swift in Sources */,
3F568A0025420DE80048A9E4 /* TodayWidgetMediumView.swift in Sources */,
3F568A2F254216550048A9E4 /* FlexibleCard.swift in Sources */,
3F568A1F254213B60048A9E4 /* VerticalCard.swift in Sources */,
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import SwiftUI

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is two spaces between import statements and the extension definition typical?


extension LocalizedStringKey {
static let defaultBundle = Bundle(for: HomeWidgetTodayRemoteService.self)

/// TODO - TODAYWIDGET - LocalizedStringKey is used as a wrapper of NSLocalizedString, in order to use synthetic keys and assign a default value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be worth mentioning this as a TODO just because IMHO it's unlikely to change any time soon. It seems like this was a great (missed) opportunity for Apple to clean this up and have LocalizedStringKey have proper fallback behaviour and they didn't, so I wouldn't expect this to change.

I like the comment though explaining why it exists and the circumstances under which it could be replaced. Just not sure if TODO is that useful since it might be in that state for a looooooong time 😄

/// in case of missing localization. This will need to be updated (if and) as soon as LocalizedStringKey supports default values
init(_ key: String, defaultValue: String, comment: String) {
self.init(NSLocalizedString(key, tableName: nil, bundle: Self.defaultBundle, value: defaultValue, comment: comment))
}
}
11 changes: 0 additions & 11 deletions WordPress/WordPressHomeWidgetToday/Views/TodayWidgetView.swift
Original file line number Diff line number Diff line change
@@ -52,14 +52,3 @@ extension TodayWidgetView {
static let commentsTitle = LocalizedStringKey("widget.today.comments.label", defaultValue: "Comments", comment: "Title of comments label in today widget")
}
}


extension LocalizedStringKey {
static let defaultBundle = Bundle(for: HomeWidgetTodayRemoteService.self)

/// TODO - TODAYWIDGET - LocalizedStringKey is used as a wrapper of NSLocalizedString, in order to use synthetic keys and assing a default value
/// in case of missing localization. This will need to be updated (if and) as soon as LocalizedStringKey supports default values
init(_ key: String, defaultValue: String, comment: String) {
self.init(NSLocalizedString(key, tableName: nil, bundle: Self.defaultBundle, value: defaultValue, comment: comment))
}
}