Skip to content

Commit

Permalink
Support localization strings
Browse files Browse the repository at this point in the history
* Added French language as an example
  • Loading branch information
justinctlam committed Oct 9, 2017
1 parent e31bb04 commit 6132973
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 43 deletions.
21 changes: 21 additions & 0 deletions SEDaily-IOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
16D67C4A1F33AC620065E838 /* AnswersTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D67C491F33AC620065E838 /* AnswersTracker.swift */; };
16D67C4D1F33AE370065E838 /* ObjectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D67C4C1F33AE370065E838 /* ObjectExtensions.swift */; };
16D766BA1F06B4850066C143 /* AudioView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D766B91F06B4850066C143 /* AudioView.swift */; };
1E44AF031F87B08D00221B22 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1E44AF051F87B08D00221B22 /* Localizable.strings */; };
238E99F4E37C7365658113B8 /* Pods_SEDaily_IOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF0C9F051C6C2F8638D2ABF8 /* Pods_SEDaily_IOSTests.framework */; };
24412438C753126FDDD37CBF /* Pods_SEDaily_IOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A3651E5B02B83E392546E167 /* Pods_SEDaily_IOS.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -104,6 +105,10 @@
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>"; };
16D766B91F06B4850066C143 /* AudioView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioView.swift; sourceTree = "<group>"; };
1E44AEFF1F87ACF500221B22 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
1E44AF001F87ACF500221B22 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Main.strings; sourceTree = "<group>"; };
1E44AF061F87B09100221B22 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
1E44AF081F87B0A700221B22 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
675FBEB71FD81FBA8767227A /* Pods-SEDaily-IOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SEDaily-IOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-SEDaily-IOS/Pods-SEDaily-IOS.release.xcconfig"; sourceTree = "<group>"; };
995F64385352A79BA0DF7DEB /* Pods-SEDaily-IOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SEDaily-IOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SEDaily-IOSTests/Pods-SEDaily-IOSTests.debug.xcconfig"; sourceTree = "<group>"; };
9FDA28C254F62BB468401B75 /* Pods-SEDaily-IOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SEDaily-IOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SEDaily-IOS/Pods-SEDaily-IOS.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -245,6 +250,7 @@
164FE9E41F02EE83009419CA /* API.swift */,
1686FC001F009EC00088A6C1 /* AppDelegate.swift */,
164C71041F021AC8003803BC /* CustomTabViewController.swift */,
1E44AF051F87B08D00221B22 /* Localizable.strings */,
1686FC071F009EC00088A6C1 /* Assets.xcassets */,
164FE9DD1F02DAB8009419CA /* CollectionViewCells */,
164FE9DA1F02DAA5009419CA /* CollectionViews */,
Expand Down Expand Up @@ -373,6 +379,7 @@
knownRegions = (
en,
Base,
fr,
);
mainGroup = 1686FBF41F009EC00088A6C1;
productRefGroup = 1686FBFE1F009EC00088A6C1 /* Products */;
Expand All @@ -391,6 +398,7 @@
buildActionMask = 2147483647;
files = (
1686FC0B1F009EC00088A6C1 /* LaunchScreen.storyboard in Resources */,
1E44AF031F87B08D00221B22 /* Localizable.strings in Resources */,
1686FC081F009EC00088A6C1 /* Assets.xcassets in Resources */,
1686FC061F009EC00088A6C1 /* Main.storyboard in Resources */,
);
Expand Down Expand Up @@ -628,6 +636,7 @@
isa = PBXVariantGroup;
children = (
1686FC051F009EC00088A6C1 /* Base */,
1E44AF001F87ACF500221B22 /* fr */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand All @@ -636,17 +645,28 @@
isa = PBXVariantGroup;
children = (
1686FC0A1F009EC00088A6C1 /* Base */,
1E44AEFF1F87ACF500221B22 /* fr */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
1E44AF051F87B08D00221B22 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
1E44AF061F87B09100221B22 /* Base */,
1E44AF081F87B0A700221B22 /* fr */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
1686FC181F009EC00088A6C1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -706,6 +726,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down
51 changes: 51 additions & 0 deletions SEDaily-IOS/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Localizable.strings
SEDaily-IOS

Created by Justin Lam on 10/6/17.
Copyright © 2017 Koala Tea. All rights reserved.
*/

/* */
"TabBarTitleLatest" = "Latest";
"TabBarJustForYou" = "Just For You";
"TabTitleAll" = "All";
"TabTitleBusinessAndPhilosophy" = "Business and Philosophy";
"TabTitleBlockchain" = "Blockchain";
"TabTitleCloudEngineering" = "Cloud Engineering";
"TabTitleData" = "Data";
"TabTitleJavaScript" = "JavaScript";
"TabTitleMachineLearning" = "Machine Learning";
"TabTitleOpenSource" = "Open Source";
"TabTitleSecurity" = "Security";
"TabTitleHackers" = "Hackers";
"TabTitleGreatestHits" = "Greatest Hits";
"LoginTitle" = "Login";
"LogoutTitle" = "Logout";
"EmailAddressPlaceholder" = "Email";
"PasswordPlaceholder" = "Password";
"ConfirmPasswordPlaceholder" = "Confirm Password";
"FirstNamePlaceholder" = "First Name";
"LastNamePlaceholder" = "Last Name";
"LoginButtonTitle" = "Login";
"CancelButtonTitle" = "Cancel";
"SignUpButtonTitle" = "Sign Up";
"AlertMessageEmailEmpty" = "Email Field Empty";
"AlertMessagePasswordEmpty" = "Password Field Empty";
"AlertMessagePasswordConfirmEmpty" = "Confirm Password Field Empty";
"AlertMessageEmailWrongFormat" = "Invalid Email Format";
"AlertMessagePasswordNotLongEnough" = "Password must be longer than 6 characters";
"AlertMessagePasswordsDonotMatch" = "Password do not match";
"AlertMessageFirstNameEmpty" = "First Name Field Empty";
"AlertMessageFirstNameNotLongEnough" = "First Name must be longer than 1 characters";
"AlertMessageLastNameEmpty" = "Last Name Field Empty";
"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";
"GenericError" = "Error";
"GenericOkay" = "Okay";
"GenericOK" = "OK";
10 changes: 4 additions & 6 deletions SEDaily-IOS/CustomTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ class CustomTabViewController: UITabBarController, UITabBarControllerDelegate {

switch User.getActiveUser().isLoggedIn() {
case false:
let leftBarButton = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(self.loginButtonPressed))
let leftBarButton = UIBarButtonItem(title: NSLocalizedString("LoginTitle", comment: ""), style: .done, target: self, action: #selector(self.loginButtonPressed))
self.navigationItem.leftBarButtonItem = leftBarButton
break
case true:
let leftBarButton = UIBarButtonItem(title: "Logout", style: .done, target: self, action: #selector(self.logoutButtonPressed))
let leftBarButton = UIBarButtonItem(title: NSLocalizedString("LogoutTitle", comment: ""), style: .done, target: self, action: #selector(self.logoutButtonPressed))
self.navigationItem.leftBarButtonItem = leftBarButton
break
}
}

Expand Down Expand Up @@ -99,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: "Latest", image: #imageLiteral(resourceName: "mic_stand"), selectedImage: #imageLiteral(resourceName: "mic_stand_selected"))
let icon2 = UITabBarItem(title: "Just For You", image: #imageLiteral(resourceName: "activity_feed"), selectedImage: #imageLiteral(resourceName: "activity_feed_selected"))
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 icon3 = UITabBarItem(tabBarSystemItem: .mostViewed, tag: 0)

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

enum Alerts {
static let error = "Error"
static let success = "Success"
static let error = NSLocalizedString("GenericError", comment: "")
static let success = NSLocalizedString("GenericSuccess", comment: "")
}

enum Messages {
static let emailEmpty = "Email Field Empty"
static let passwordEmpty = "Password Field Empty"
static let passwordConfirmEmpty = "Confirm Password Field Empty"
static let emailWrongFormat = "Invalid Email Format"
static let passwordNotLongEnough = "Password must be longer than 6 characters"
static let passwordsDonotMatch = "Password do not match"
static let firstNameEmpty = "First Name Field Empty"
static let firstNameNotLongEnough = "First Name must be longer than 1 characters"
static let lastNameEmpty = "Last Name Field Empty"
static let lastNameNotLongEnough = "Last Name must be longer than 1 characters"
static let pleaseLogin = "Please Login"
static let issueWithUserToken = "Issue with User Token"
static let noWebsite = "No linked webste."
static let youMustLogin = "You must login to use this feature."
static let logoutSuccess = "Successfully Logged Out"
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: "")
}
}

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

alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: NSLocalizedString("GenericOkay", comment: ""), style: UIAlertActionStyle.default, handler: nil))
topController.present(alert, animated: true, completion: nil)
completionHandler?()
}
Expand Down
16 changes: 8 additions & 8 deletions SEDaily-IOS/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,34 @@ class LoginViewController: UIViewController {
addBottomBorderToView(view: firstNameTextField, height: 36.calculateHeight(), width: 316.calculateWidth())
addBottomBorderToView(view: lastNameTextField, height: 36.calculateHeight(), width: 316.calculateWidth())

emailTextField.placeholder = "Email"
emailTextField.placeholder = NSLocalizedString("EmailAddressPlaceholder", comment: "")
emailTextField.setPlaceHolderTextColor(Stylesheet.Colors.secondaryColor)
emailTextField.textColor = Stylesheet.Colors.white
emailTextField.autocorrectionType = .no
emailTextField.autocapitalizationType = .none

passwordTextField.placeholder = "Password"
passwordTextField.placeholder = NSLocalizedString("PasswordPlaceholder", comment: "")
passwordTextField.setPlaceHolderTextColor(Stylesheet.Colors.secondaryColor)
passwordTextField.textColor = Stylesheet.Colors.white
passwordTextField.autocorrectionType = .no
passwordTextField.autocapitalizationType = .none
passwordTextField.isSecureTextEntry = true

passwordConfirmTextField.isHidden = true
passwordConfirmTextField.placeholder = "Confirm Password"
passwordConfirmTextField.placeholder = NSLocalizedString("ConfirmPasswordPlaceholder", comment: "")
passwordConfirmTextField.textColor = Stylesheet.Colors.white
passwordConfirmTextField.autocorrectionType = .no
passwordConfirmTextField.autocapitalizationType = .none
passwordConfirmTextField.isSecureTextEntry = true

firstNameTextField.isHidden = true
firstNameTextField.placeholder = "First Name"
firstNameTextField.placeholder = NSLocalizedString("FirstNamePlaceholder", comment: "")
firstNameTextField.textColor = Stylesheet.Colors.white
firstNameTextField.autocorrectionType = .no
firstNameTextField.autocapitalizationType = .none

lastNameTextField.isHidden = true
lastNameTextField.placeholder = "Last Name"
lastNameTextField.placeholder = NSLocalizedString("LastNamePlaceholder", comment: "")
lastNameTextField.textColor = Stylesheet.Colors.white
lastNameTextField.autocorrectionType = .no
lastNameTextField.autocapitalizationType = .none
Expand All @@ -235,20 +235,20 @@ class LoginViewController: UIViewController {
make.height.equalTo(42.calculateHeight())
}

loginButton.setTitle("Login", for: .normal)
loginButton.setTitle(NSLocalizedString("LoginButtonTitle", comment: ""), for: .normal)
loginButton.setTitleColor(Stylesheet.Colors.white, for: .normal)
loginButton.setBackgroundColor(color: Stylesheet.Colors.secondaryColor, forState: .normal)
loginButton.addTarget(self, action: #selector(self.loginButtonPressed), for: .touchUpInside)
loginButton.cornerRadius = 4.calculateWidth()

cancelButton.setTitle("Cancel", for: .normal)
cancelButton.setTitle(NSLocalizedString("CancelButtonTitle", comment: ""), for: .normal)
cancelButton.setTitleColor(Stylesheet.Colors.white, for: .normal)
cancelButton.setBackgroundColor(color: Stylesheet.Colors.secondaryColor, forState: .normal)
cancelButton.addTarget(self, action: #selector(self.cancelButtonPressed), for: .touchUpInside)
cancelButton.cornerRadius = 4.calculateWidth()
cancelButton.isHidden = true

signUpButton.setTitle("Sign Up", for: .normal)
signUpButton.setTitle(NSLocalizedString("SignUpButtonTitle", comment: ""), for: .normal)
signUpButton.setTitleColor(Stylesheet.Colors.white, for: .normal)
signUpButton.setBackgroundColor(color: Stylesheet.Colors.secondaryColor, forState: .normal)
signUpButton.addTarget(self, action: #selector(self.signUpButtonPressed), for: .touchUpInside)
Expand Down
Loading

0 comments on commit 6132973

Please sign in to comment.