Skip to content

Commit

Permalink
Added swiftgen and abstracted all strings to L10n enum
Browse files Browse the repository at this point in the history
  • Loading branch information
themisterholliday committed Oct 12, 2017
1 parent 6132973 commit 5ea0f52
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 44 deletions.
101 changes: 101 additions & 0 deletions Constants/L10nEnum.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen

import Foundation

// swiftlint:disable file_length

// swiftlint:disable explicit_type_interface identifier_name line_length nesting type_body_length type_name
enum L10n {
/// Email Field Empty
static let alertMessageEmailEmpty = L10n.tr("Localizable", "AlertMessageEmailEmpty")
/// Invalid Email Format
static let alertMessageEmailWrongFormat = L10n.tr("Localizable", "AlertMessageEmailWrongFormat")
/// First Name Field Empty
static let alertMessageFirstNameEmpty = L10n.tr("Localizable", "AlertMessageFirstNameEmpty")
/// First Name must be longer than 1 characters
static let alertMessageFirstNameNotLongEnough = L10n.tr("Localizable", "AlertMessageFirstNameNotLongEnough")
/// Issue with User Token
static let alertMessageIssueWithUserToken = L10n.tr("Localizable", "AlertMessageIssueWithUserToken")
/// Last Name Field Empty
static let alertMessageLastNameEmpty = L10n.tr("Localizable", "AlertMessageLastNameEmpty")
/// Last Name must be longer than 1 characters
static let alertMessageLastNameNotLongEnough = L10n.tr("Localizable", "AlertMessageLastNameNotLongEnough")
/// Successfully Logged Out
static let alertMessageLogoutSuccess = L10n.tr("Localizable", "AlertMessageLogoutSuccess")
/// Confirm Password Field Empty
static let alertMessagePasswordConfirmEmpty = L10n.tr("Localizable", "AlertMessagePasswordConfirmEmpty")
/// Password Field Empty
static let alertMessagePasswordEmpty = L10n.tr("Localizable", "AlertMessagePasswordEmpty")
/// Password must be longer than 6 characters
static let alertMessagePasswordNotLongEnough = L10n.tr("Localizable", "AlertMessagePasswordNotLongEnough")
/// Password do not match
static let alertMessagePasswordsDonotMatch = L10n.tr("Localizable", "AlertMessagePasswordsDonotMatch")
/// Please Login
static let alertMessagePleaseLogin = L10n.tr("Localizable", "AlertMessagePleaseLogin")
/// You must login to use this feature.
static let alertMessageYouMustLogin = L10n.tr("Localizable", "AlertMessageYouMustLogin")
/// Cancel
static let cancelButtonTitle = L10n.tr("Localizable", "CancelButtonTitle")
/// Confirm Password
static let confirmPasswordPlaceholder = L10n.tr("Localizable", "ConfirmPasswordPlaceholder")
/// Email
static let emailAddressPlaceholder = L10n.tr("Localizable", "EmailAddressPlaceholder")
/// First Name
static let firstNamePlaceholder = L10n.tr("Localizable", "FirstNamePlaceholder")
/// Error
static let genericError = L10n.tr("Localizable", "GenericError")
/// OK
static let genericOK = L10n.tr("Localizable", "GenericOK")
/// Okay
static let genericOkay = L10n.tr("Localizable", "GenericOkay")
/// Success
static let genericSuccess = L10n.tr("Localizable", "GenericSuccess")
/// Last Name
static let lastNamePlaceholder = L10n.tr("Localizable", "LastNamePlaceholder")
/// Login
static let loginButtonTitle = L10n.tr("Localizable", "LoginButtonTitle")
/// Login
static let loginTitle = L10n.tr("Localizable", "LoginTitle")
/// Logout
static let logoutTitle = L10n.tr("Localizable", "LogoutTitle")
/// Password
static let passwordPlaceholder = L10n.tr("Localizable", "PasswordPlaceholder")
/// Sign Up
static let signUpButtonTitle = L10n.tr("Localizable", "SignUpButtonTitle")
/// Just For You
static let tabBarJustForYou = L10n.tr("Localizable", "TabBarJustForYou")
/// Latest
static let tabBarTitleLatest = L10n.tr("Localizable", "TabBarTitleLatest")
/// All
static let tabTitleAll = L10n.tr("Localizable", "TabTitleAll")
/// Blockchain
static let tabTitleBlockchain = L10n.tr("Localizable", "TabTitleBlockchain")
/// Business and Philosophy
static let tabTitleBusinessAndPhilosophy = L10n.tr("Localizable", "TabTitleBusinessAndPhilosophy")
/// Cloud Engineering
static let tabTitleCloudEngineering = L10n.tr("Localizable", "TabTitleCloudEngineering")
/// Data
static let tabTitleData = L10n.tr("Localizable", "TabTitleData")
/// Greatest Hits
static let tabTitleGreatestHits = L10n.tr("Localizable", "TabTitleGreatestHits")
/// Hackers
static let tabTitleHackers = L10n.tr("Localizable", "TabTitleHackers")
/// JavaScript
static let tabTitleJavaScript = L10n.tr("Localizable", "TabTitleJavaScript")
/// Machine Learning
static let tabTitleMachineLearning = L10n.tr("Localizable", "TabTitleMachineLearning")
/// Open Source
static let tabTitleOpenSource = L10n.tr("Localizable", "TabTitleOpenSource")
/// Security
static let tabTitleSecurity = L10n.tr("Localizable", "TabTitleSecurity")
}
// swiftlint:enable explicit_type_interface identifier_name line_length nesting type_body_length type_name

extension L10n {
fileprivate static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "")
return String(format: format, locale: Locale.current, arguments: args)
}
}

private final class BundleToken {}
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target 'SEDaily-IOS' do
pod 'KTResponsiveUI'
pod 'KoalaTeaPlayer'
pod 'Tabman'
pod 'SwiftGen'
target 'SEDaily-IOSTests' do
inherit! :search_paths
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ PODS:
- SwifterSwift/Foundation (4.0.0)
- SwifterSwift/SwiftStdlib (4.0.0)
- SwifterSwift/UIKit (4.0.0)
- SwiftGen (5.1.2)
- SwiftIcons (1.5.1)
- SwiftyBeaver (1.4.2)
- SwiftyJSON (3.1.4)
Expand All @@ -64,6 +65,7 @@ DEPENDENCIES:
- SideMenu
- SnapKit
- SwifterSwift
- SwiftGen
- SwiftIcons (from `https://github.com/themisterholliday/SwiftIcons.git`, branch `swift-4`)
- SwiftyBeaver
- SwiftyJSON
Expand Down Expand Up @@ -105,12 +107,13 @@ SPEC CHECKSUMS:
SideMenu: 8fe957e0f5dcf1a1175c8ba5d47978d4eb2a89da
SnapKit: a42d492c16e80209130a3379f73596c3454b7694
SwifterSwift: 0b63ade1ec0c5bc4d6228df993de41fe44bc123e
SwiftGen: dd2892e7fb008151f30e6ce0cf465b8b8d89e80e
SwiftIcons: b20641adce6b71fcb2e72389b4b5f2e87252df99
SwiftyBeaver: 91057725648ee4980308f1650af077d04b3654a0
SwiftyJSON: c2842d878f95482ffceec5709abc3d05680c0220
Tabman: 558bede024627206c554e1c8cee728d380655ebf
UIFontComplete: 7e3ce7f0a12d2529fb07f537e262aabfa87df280

PODFILE CHECKSUM: 66b19d5ea05da768f11f82f3d16acb7e731bf857
PODFILE CHECKSUM: 7d6c85bc7ebf3763fd5c8d2c35b66e7dd8a35654

COCOAPODS: 1.3.1
27 changes: 27 additions & 0 deletions SEDaily-IOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
1686FC081F009EC00088A6C1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1686FC071F009EC00088A6C1 /* Assets.xcassets */; };
1686FC0B1F009EC00088A6C1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1686FC091F009EC00088A6C1 /* LaunchScreen.storyboard */; };
1686FC161F009EC00088A6C1 /* SEDaily_IOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1686FC151F009EC00088A6C1 /* SEDaily_IOSTests.swift */; };
169806A61F8EF3970075D8AD /* L10nEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 169806A51F8EF08F0075D8AD /* L10nEnum.swift */; };
16B147B11F16BF9C00433A42 /* AudioViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16B147B01F16BF9C00433A42 /* AudioViewManager.swift */; };
16D67C4A1F33AC620065E838 /* AnswersTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D67C491F33AC620065E838 /* AnswersTracker.swift */; };
16D67C4D1F33AE370065E838 /* ObjectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D67C4C1F33AE370065E838 /* ObjectExtensions.swift */; };
Expand Down Expand Up @@ -101,6 +102,7 @@
1686FC111F009EC00088A6C1 /* SEDaily-IOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SEDaily-IOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
1686FC151F009EC00088A6C1 /* SEDaily_IOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SEDaily_IOSTests.swift; sourceTree = "<group>"; };
1686FC171F009EC00088A6C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
169806A51F8EF08F0075D8AD /* L10nEnum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = L10nEnum.swift; sourceTree = "<group>"; };
16B147B01F16BF9C00433A42 /* AudioViewManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioViewManager.swift; sourceTree = "<group>"; };
16D67C491F33AC620065E838 /* AnswersTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnswersTracker.swift; sourceTree = "<group>"; };
16D67C4C1F33AE370065E838 /* ObjectExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectExtensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -245,6 +247,7 @@
1686FBFF1F009EC00088A6C1 /* SEDaily-IOS */ = {
isa = PBXGroup;
children = (
169806A41F8EF08F0075D8AD /* Constants */,
1610E2C21F227BE0006C8E83 /* Managers */,
1686FC0C1F009EC00088A6C1 /* Info.plist */,
164FE9E41F02EE83009419CA /* API.swift */,
Expand Down Expand Up @@ -277,6 +280,14 @@
path = "SEDaily-IOSTests";
sourceTree = "<group>";
};
169806A41F8EF08F0075D8AD /* Constants */ = {
isa = PBXGroup;
children = (
169806A51F8EF08F0075D8AD /* L10nEnum.swift */,
);
path = Constants;
sourceTree = SOURCE_ROOT;
};
4E74333675FE5899EC260076 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -311,6 +322,7 @@
AE5F616C12D0339AD2CE40F0 /* [CP] Embed Pods Frameworks */,
4B6DBB81C87D23ABC98202EB /* [CP] Copy Pods Resources */,
16D67C4B1F33AD1D0065E838 /* ShellScript */,
169806A21F8EED850075D8AD /* Swiftgen Localize Strings Script */,
);
buildRules = (
);
Expand Down Expand Up @@ -432,6 +444,20 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
169806A21F8EED850075D8AD /* Swiftgen Localize Strings Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Swiftgen Localize Strings Script";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which \"$PODS_ROOT\"/SwiftGen/bin/swiftgen >/dev/null; then\nset -e\n\"$PODS_ROOT\"/SwiftGen/bin/swiftgen strings -t structured-swift3 \"$PROJECT_DIR/SEDaily-IOS/Base.lproj/Localizable.strings\" --output \"$PROJECT_DIR/Constants/L10nEnum.swift\"\nelse\necho \"warning: SwiftGen not installed, download it from https://github.com/SwiftGen/SwiftGen\"\nfi";
};
16D67C4B1F33AD1D0065E838 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -604,6 +630,7 @@
164FE9EB1F02F340009419CA /* Helpers.swift in Sources */,
166036211F266FF300A22B7B /* Notifications.swift in Sources */,
1672FAC41F06C141008445B1 /* NotificationCenterExtension.swift in Sources */,
169806A61F8EF3970075D8AD /* L10nEnum.swift in Sources */,
01BB1D6D1F29999E004A912E /* PodcastPageViewController.swift in Sources */,
164FE9F11F030A2E009419CA /* PodcastModel.swift in Sources */,
164FE9ED1F02F7E2009419CA /* UIButtonExtension.swift in Sources */,
Expand Down
1 change: 0 additions & 1 deletion SEDaily-IOS/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"AlertMessageLastNameNotLongEnough" = "Last Name must be longer than 1 characters";
"AlertMessagePleaseLogin" = "Please Login";
"AlertMessageIssueWithUserToken" = "Issue with User Token";
"AlertMessageNoWebsite" = "No linked webste.";
"AlertMessageYouMustLogin" = "You must login to use this feature.";
"AlertMessageLogoutSuccess" = "Successfully Logged Out";
"GenericSuccess" = "Success";
Expand Down
8 changes: 4 additions & 4 deletions SEDaily-IOS/CustomTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class CustomTabViewController: UITabBarController, UITabBarControllerDelegate {

switch User.getActiveUser().isLoggedIn() {
case false:
let leftBarButton = UIBarButtonItem(title: NSLocalizedString("LoginTitle", comment: ""), style: .done, target: self, action: #selector(self.loginButtonPressed))
let leftBarButton = UIBarButtonItem(title: L10n.loginTitle, style: .done, target: self, action: #selector(self.loginButtonPressed))
self.navigationItem.leftBarButtonItem = leftBarButton
case true:
let leftBarButton = UIBarButtonItem(title: NSLocalizedString("LogoutTitle", comment: ""), style: .done, target: self, action: #selector(self.logoutButtonPressed))
let leftBarButton = UIBarButtonItem(title: L10n.logoutTitle, style: .done, target: self, action: #selector(self.logoutButtonPressed))
self.navigationItem.leftBarButtonItem = leftBarButton
}
}
Expand Down Expand Up @@ -97,8 +97,8 @@ class CustomTabViewController: UITabBarController, UITabBarControllerDelegate {
// let vc2 = GeneralCollectionViewController(collectionViewLayout: layout, type: API.Types.recommended)
// let vc3 = GeneralCollectionViewController(collectionViewLayout: layout, type: API.Types.top)

let icon1 = UITabBarItem(title: NSLocalizedString("TabBarTitleLatest", comment: ""), image: #imageLiteral(resourceName: "mic_stand"), selectedImage: #imageLiteral(resourceName: "mic_stand_selected"))
let icon2 = UITabBarItem(title: NSLocalizedString("TabBarJustForYou", comment: ""), image: #imageLiteral(resourceName: "activity_feed"), selectedImage: #imageLiteral(resourceName: "activity_feed_selected"))
let icon1 = UITabBarItem(title: L10n.tabBarTitleLatest, image: #imageLiteral(resourceName: "mic_stand"), selectedImage: #imageLiteral(resourceName: "mic_stand_selected"))
let icon2 = UITabBarItem(title: L10n.tabBarJustForYou, image: #imageLiteral(resourceName: "activity_feed"), selectedImage: #imageLiteral(resourceName: "activity_feed_selected"))
let icon3 = UITabBarItem(tabBarSystemItem: .mostViewed, tag: 0)

vc1.tabBarItem = icon1
Expand Down
35 changes: 17 additions & 18 deletions SEDaily-IOS/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@ extension Helpers {
static var alert: UIAlertController!

enum Alerts {
static let error = NSLocalizedString("GenericError", comment: "")
static let success = NSLocalizedString("GenericSuccess", comment: "")
static let error = L10n.genericError
static let success = L10n.genericSuccess
}

enum Messages {
static let emailEmpty = NSLocalizedString("AlertMessageEmailEmpty", comment: "")
static let passwordEmpty = NSLocalizedString("AlertMessagePasswordEmpty", comment: "")
static let passwordConfirmEmpty = NSLocalizedString("AlertMessagePasswordConfirmEmpty", comment: "")
static let emailWrongFormat = NSLocalizedString("AlertMessageEmailWrongFormat", comment: "")
static let passwordNotLongEnough = NSLocalizedString("AlertMessagePasswordNotLongEnough", comment: "")
static let passwordsDonotMatch = NSLocalizedString("AlertMessagePasswordsDonotMatch", comment: "")
static let firstNameEmpty = NSLocalizedString("AlertMessageFirstNameEmpty", comment: "")
static let firstNameNotLongEnough = NSLocalizedString("AlertMessageFirstNameNotLongEnough", comment: "")
static let lastNameEmpty = NSLocalizedString("AlertMessageLastNameEmpty", comment: "")
static let lastNameNotLongEnough = NSLocalizedString("AlertMessageLastNameNotLongEnough", comment: "")
static let pleaseLogin = NSLocalizedString("AlertMessagePleaseLogin", comment: "")
static let issueWithUserToken = NSLocalizedString("AlertMessageIssueWithUserToken", comment: "")
static let noWebsite = NSLocalizedString("AlertMessageNoWebsite", comment: "")
static let youMustLogin = NSLocalizedString("AlertMessageYouMustLogin", comment: "")
static let logoutSuccess = NSLocalizedString("AlertMessageLogoutSuccess", comment: "")
static let emailEmpty = L10n.alertMessageEmailEmpty
static let passwordEmpty = L10n.alertMessagePasswordEmpty
static let passwordConfirmEmpty = L10n.alertMessagePasswordConfirmEmpty
static let emailWrongFormat = L10n.alertMessageEmailWrongFormat
static let passwordNotLongEnough = L10n.alertMessagePasswordNotLongEnough
static let passwordsDonotMatch = L10n.alertMessagePasswordsDonotMatch
static let firstNameEmpty = L10n.alertMessageFirstNameEmpty
static let firstNameNotLongEnough = L10n.alertMessageFirstNameNotLongEnough
static let lastNameEmpty = L10n.alertMessageLastNameEmpty
static let lastNameNotLongEnough = L10n.alertMessageLastNameNotLongEnough
static let pleaseLogin = L10n.alertMessagePleaseLogin
static let issueWithUserToken = L10n.alertMessageIssueWithUserToken
static let youMustLogin = L10n.alertMessageYouMustLogin
static let logoutSuccess = L10n.alertMessageLogoutSuccess
}
}

Expand All @@ -53,7 +52,7 @@ class Helpers {
}

alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("GenericOkay", comment: ""), style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: L10n.genericOkay, style: UIAlertActionStyle.default, handler: nil))
topController.present(alert, animated: true, completion: nil)
completionHandler?()
}
Expand Down
Loading

0 comments on commit 5ea0f52

Please sign in to comment.