Skip to content

Commit

Permalink
Exam supports localization (#350)
Browse files Browse the repository at this point in the history
* Localize ExamEGERussian target
  • Loading branch information
ivan-magda authored Aug 24, 2018
1 parent 57bfa5c commit 4238e2e
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import UIKit

final class AuthGreetingViewController: UIViewController {
@IBOutlet var signInButton: BorderedButton!
@IBOutlet var signUpButton: BorderedButton!
@IBOutlet var laterButton: UIButton!

var presenter: AuthGreetingPresenterProtocol?

private let gradientLayer = CAGradientLayer(
Expand All @@ -31,13 +35,21 @@ final class AuthGreetingViewController: UIViewController {
action: #selector(dismiss(_:))
)
navigationItem.leftBarButtonItem?.tintColor = .white

localize()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
gradientLayer.frame = view.bounds
}

private func localize() {
signInButton.setTitle(NSLocalizedString("SignIn", comment: ""), for: .normal)
signUpButton.setTitle(NSLocalizedString("SignUp", comment: ""), for: .normal)
laterButton.setTitle(NSLocalizedString("Later", comment: ""), for: .normal)
}

// MARK: Actions

@IBAction private func onSignIn(_ sender: Any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.9"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AuthGreetingViewController" customModule="ExamEGERussian" customModuleProvider="target">
<connections>
<outlet property="laterButton" destination="Y0m-Dy-BFE" id="XSu-Ok-5jj"/>
<outlet property="signInButton" destination="fQX-EE-i5s" id="WgF-2g-o4l"/>
<outlet property="signUpButton" destination="fhq-za-NkY" id="fTp-op-URJ"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class HeaderEmptyAuthView: UIView {
label.font = UIFont.systemFont(ofSize: Theme.Title.fontSize, weight: .heavy)
label.textAlignment = .center
label.textColor = .white
label.text = NSLocalizedString("It's You!", comment: "EmptyAuthView title")
label.text = NSLocalizedString("EmptyAuthViewTitle", comment: "")

return label
}()
Expand All @@ -53,7 +53,7 @@ public final class HeaderEmptyAuthView: UIView {
label.font = UIFont.systemFont(ofSize: Theme.Subtitle.fontSize, weight: .medium)
label.textAlignment = .center
label.textColor = .white
label.text = NSLocalizedString("Complete auth to study with comfort", comment: "EmptyAuthView subtitle")
label.text = NSLocalizedString("EmptyAuthViewSubtitle", comment: "")
label.numberOfLines = 0

return label
Expand All @@ -73,7 +73,7 @@ public final class HeaderEmptyAuthView: UIView {
label.font = UIFont.systemFont(ofSize: Theme.Description.fontSize)
label.textAlignment = .center
label.textColor = .white
label.text = NSLocalizedString("Authorized account allows you to sync progress and purchases between devices and display your name in leaderboards", comment: "EmptyAuthView description")
label.text = NSLocalizedString("EmptyAuthViewDescription", comment: "")
label.numberOfLines = 0

return label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ final class LessonsPresenterImpl: LessonsPresenter {
}

private func displayError(_ error: Swift.Error) {
view?.displayError(title: NSLocalizedString("Error", comment: ""), message: error.localizedDescription)
view?.displayError(
title: NSLocalizedString("Error", comment: ""),
message: NSLocalizedString("ErrorMessage", comment: "")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class StepsPagerPresenterImpl: StepsPagerPresenter {
strongSelf.updateStepProgress(at: index, passed: true)
}.catch { [weak self] error in
print("\(#file) \(#function): \(error)")
self?.view?.state = .error(message: NSLocalizedString("Could't mark quiz as solved. Please try again.", comment: ""))
self?.view?.state = .error(message: NSLocalizedString("FailedMarkStepAsSolved", comment: ""))
}
}
}
Expand All @@ -72,21 +72,23 @@ extension StepsPagerPresenterImpl {
private func getSteps() {
obtainStepsFromCache().done {
self.fetchSteps()
}.cauterize()
}
}

private func obtainStepsFromCache() -> Promise<Void> {
return Promise { seal in
private func obtainStepsFromCache() -> Guarantee<Void> {
return Guarantee { seal in
self.stepsService.obtainSteps(for: lesson).done { [weak self] steps in
guard let strongSelf = self else {
return
}

strongSelf.steps = strongSelf.preparedSteps(steps)
strongSelf.view?.state = .fetched(steps: strongSelf.steps)
seal.fulfill(())
}.catch { [weak self] error in
self?.view?.state = .error(message: NSLocalizedString("Failed to get steps from cache", comment: ""))

seal(())
}.catch { error in
print("\(#function): \(error)")
seal(())
}
}
}
Expand All @@ -108,7 +110,7 @@ extension StepsPagerPresenterImpl {
}.catch { [weak self] error in
let message = error is NetworkError
? NSLocalizedString("ConnectionErrorText", comment: "")
: NSLocalizedString("Failed to fetch steps", comment: "")
: NSLocalizedString("FailedFetchStepsError", comment: "")
self?.view?.state = .error(message: message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extension StepsPagerViewController {
withTitle: NSLocalizedString("Error", comment: ""),
message: message,
buttonFirstTitle: NSLocalizedString("Cancel", comment: ""),
buttonSecondTitle: NSLocalizedString("Try Again", comment: ""),
buttonSecondTitle: NSLocalizedString("TryAgain", comment: ""),
firstAction: { [weak self] in
self?.presenter?.cancel()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ final class StepPresenterImpl: StepPresenter {

// MARK: - Private API

private func showError(title: String = NSLocalizedString("Error", comment: ""), message: String) {
private func showError(
title: String = NSLocalizedString("Error", comment: ""),
message: String = NSLocalizedString("ErrorMessage", comment: "")
) {
view?.displayError(title: title, message: message)
}
}
Expand Down Expand Up @@ -72,7 +75,7 @@ extension StepPresenterImpl {

private func setupQuizViewController(_ quizViewController: QuizViewController) {
guard let step = Step.getStepWithId(self.step.id) else {
showError(message: NSLocalizedString("Could't display quiz. Please try again later.", comment: ""))
showError(message: NSLocalizedString("ErrorMessage", comment: ""))
return print("\(#file): Unable to instantiate QuizViewController")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final class TopicsPresenterImpl: TopicsPresenter {

private func displayError(
title: String = NSLocalizedString("Error", comment: ""),
message: String = NSLocalizedString("Something went wrong. Try again later.", comment: "")
message: String = NSLocalizedString("ErrorMessage", comment: "")
) {
view?.displayError(title: title, message: message)
}
Expand All @@ -131,9 +131,9 @@ final class TopicsPresenterImpl: TopicsPresenter {
var title: String {
switch self {
case .all:
return NSLocalizedString("All", comment: "")
return NSLocalizedString("Theory", comment: "")
case .adaptive:
return NSLocalizedString("Adaptive", comment: "")
return NSLocalizedString("Practice", comment: "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class TopicsRouterImpl: BaseRouter, TopicsRouter {
} else {
navigationController?.presentAlert(
withTitle: NSLocalizedString("Error", comment: ""),
message: NSLocalizedString("At this moment we couldn't show adaptive lessons. Please, try again later.", comment: "")
message: NSLocalizedString("NoAdaptiveModuleError", comment: "")
)
}
}
Expand Down
17 changes: 12 additions & 5 deletions Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@
2C2FD78D210753AD00609621 /* LessonsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2FD78C210753AD00609621 /* LessonsPresenter.swift */; };
2C2FD78F210753CD00609621 /* LessonsPresenterImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2FD78E210753CD00609621 /* LessonsPresenterImpl.swift */; };
2C2FD7912107540500609621 /* LessonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2FD7902107540500609621 /* LessonsView.swift */; };
2C302DC121303191006C2BD5 /* AuthGreetingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C302DC321303191006C2BD5 /* AuthGreetingViewController.xib */; };
2C315E6D1F0A947D0039E4F0 /* CodeLanguagePickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 081BF3461EFEF630002F84AA /* CodeLanguagePickerViewController.swift */; };
2C315E6E1F0A947D0039E4F0 /* LessonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 089984281ECDE188005C0B27 /* LessonViewController.swift */; };
2C315E6F1F0A947D0039E4F0 /* LessonPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0899842B1ECDE194005C0B27 /* LessonPresenter.swift */; };
Expand Down Expand Up @@ -4259,7 +4260,6 @@
62E9826D2C6AABDF608C2B57 /* ProfileDescriptionPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E98AFF3B8AC3CB8374445B /* ProfileDescriptionPresenter.swift */; };
62E9829488F863D10CF5544C /* UITableView+TableHeaderLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E98D9D45E6DA6099AF1C0B /* UITableView+TableHeaderLayout.swift */; };
62E982CD54C2C86F14DF84EB /* ProfileHeaderInfoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 62E98801330B94B34FA0D7B9 /* ProfileHeaderInfoView.xib */; };
62E982D6A7D79E45786B4C8D /* AuthGreetingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 62E982CD72238277F414FC52 /* AuthGreetingViewController.xib */; };
62E9831EA7A75D89A3C9EC5B /* CourseListViewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E9865A5FE3936F4ADA7133 /* CourseListViewData.swift */; };
62E983397736699787D8DD35 /* UIView+fromNib.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E982BB5246C2BBC5E88D06 /* UIView+fromNib.swift */; };
62E9834EF86EA5676FD4686E /* ProfileInfoPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E98275C20698D3770CD6D8 /* ProfileInfoPresenter.swift */; };
Expand Down Expand Up @@ -5745,6 +5745,7 @@
2C2FD78C210753AD00609621 /* LessonsPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonsPresenter.swift; sourceTree = "<group>"; };
2C2FD78E210753CD00609621 /* LessonsPresenterImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonsPresenterImpl.swift; sourceTree = "<group>"; };
2C2FD7902107540500609621 /* LessonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonsView.swift; sourceTree = "<group>"; };
2C302DC221303191006C2BD5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AuthGreetingViewController.xib; sourceTree = "<group>"; };
2C34D67320FCD6EC001EF741 /* AuthSignInPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthSignInPresenter.swift; sourceTree = "<group>"; };
2C34D67520FCD84D001EF741 /* AuthAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthAssembly.swift; sourceTree = "<group>"; };
2C34D67920FCE2B0001EF741 /* AuthSignInAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthSignInAssembly.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6147,7 +6148,6 @@
62E981DAF9200478E1C2E97F /* NotificationToken.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationToken.swift; sourceTree = "<group>"; };
62E98275C20698D3770CD6D8 /* ProfileInfoPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileInfoPresenter.swift; sourceTree = "<group>"; };
62E982BB5246C2BBC5E88D06 /* UIView+fromNib.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+fromNib.swift"; sourceTree = "<group>"; };
62E982CD72238277F414FC52 /* AuthGreetingViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AuthGreetingViewController.xib; sourceTree = "<group>"; };
62E9830545E2E72A276F308B /* ProgressService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressService.swift; sourceTree = "<group>"; };
62E9830C9521F4FE18D1E8C3 /* StepAssemblyImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StepAssemblyImpl.swift; sourceTree = "<group>"; };
62E98366860D3BBBCC872942 /* StepsPagerDataSourceImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StepsPagerDataSourceImpl.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10594,7 +10594,7 @@
isa = PBXGroup;
children = (
62E986B6284822FB1A8E1FCC /* AuthGreetingViewController.swift */,
62E982CD72238277F414FC52 /* AuthGreetingViewController.xib */,
2C302DC321303191006C2BD5 /* AuthGreetingViewController.xib */,
);
path = AuthGreetingViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -11991,7 +11991,7 @@
2C5FDC992111E25A0077C15C /* StepTabView.xib in Resources */,
2CD7998D21077D010054D098 /* TopicTableViewCell.xib in Resources */,
2CD1E35B2114B0D0007AA7B3 /* Assets.xcassets in Resources */,
62E982D6A7D79E45786B4C8D /* AuthGreetingViewController.xib in Resources */,
2C302DC121303191006C2BD5 /* AuthGreetingViewController.xib in Resources */,
2C0107A5210F3E87009A53DF /* LaunchScreen.storyboard in Resources */,
2C4F34042109F5C900E259FE /* AuthSignInViewController.xib in Resources */,
2C8A0F2220FC7CD80009F67E /* Localizable.strings in Resources */,
Expand Down Expand Up @@ -16316,7 +16316,6 @@
2C130E8D2125A51A0022E998 /* AuthAssemblyMock.swift in Sources */,
2CA9FDF8212594D00046128C /* BaseServiceMock.swift in Sources */,
2C130E972125A6890022E998 /* StepsAssemblyMock.swift in Sources */,
2C0107B0210F720F009A53DF /* ServiceFactoryTestsHelper.swift in Sources */,
2C570A63212FD61B00B56AD9 /* TopologicalSortTests.swift in Sources */,
2C23FF1B21230C7F00721E59 /* StepPlainObjectTests.swift in Sources */,
2C130E912125A5DC0022E998 /* MockAssemblyViewController.swift in Sources */,
Expand Down Expand Up @@ -18448,6 +18447,14 @@
name = LaunchScreen.xib;
sourceTree = "<group>";
};
2C302DC321303191006C2BD5 /* AuthGreetingViewController.xib */ = {
isa = PBXVariantGroup;
children = (
2C302DC221303191006C2BD5 /* Base */,
);
name = AuthGreetingViewController.xib;
sourceTree = "<group>";
};
2C35C4C51F4DA462002F3BF4 /* adjectives_f.plist */ = {
isa = PBXVariantGroup;
children = (
Expand Down
16 changes: 16 additions & 0 deletions Stepic/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,19 @@ Save = "Save";
PersonalDeadline = "Personal deadline";
DeadlineModeQuestion = "How much time would you like to spend studying on this course?";
PersonalDeadlineWidgetSuggestionText = "Constant learning is a key to success. We can smartly create personal learning schedule for you, so way you'll never forget to study!";

/* ExamEGERussian */
"ErrorMessage" = "Sorry, something went wrong: please try again later.";
"Ok" = "Ok";

"Practice" = "Practice";
"Theory" = "Theory";
"Topics" = "Topics";

"FailedFetchStepsError" = "Unable​ ​to​ ​load​ ​steps. Please try again later.";
"FailedMarkStepAsSolved" = "We​ ​couldn’t​ ​mark​ step as solved. Please try again later.";
"NoAdaptiveModuleError" = "This lesson does not has practice steps.";

"EmptyAuthViewTitle" = "It's You!";
"EmptyAuthViewSubtitle" = "Complete auth to study with comfort";
"EmptyAuthViewDescription" = "Authorized account allows you to sync progress";
16 changes: 16 additions & 0 deletions Stepic/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,19 @@ Save = "Сохранить";
PersonalDeadline = "Персональный дедлайн";
DeadlineModeQuestion = "Сколько времени вы готовы тратить на изучение этого курса?";
PersonalDeadlineWidgetSuggestionText = "Постоянное обучение - путь к успеху. Мы можем создать для вас персональное умное расписание - так вы никогда не забудете получить порцию новых знаний!";

/* ExamEGERussian */
"ErrorMessage" = "Извините, что-то пошло не так: повторите попытку позже.";
"Ok" = "Ok";

"Practice" = "Практика";
"Theory" = "Теория";
"Topics" = "Категории";

"FailedFetchStepsError" = "Невозможно получить данные об уроке в данный момент. Пожалуйста, попробуйте снова.";
"FailedMarkStepAsSolved" = "Мы не можем завершить урок. Пожалуйста, попробуйте снова.";
"NoAdaptiveModuleError" = "В данном уроке нет практических заданий. Пожалуйста, выберите другой урок.";

"EmptyAuthViewTitle" = "Это Вы!";
"EmptyAuthViewSubtitle" = "Пройдите авторизацию для более удобного обучения";
"EmptyAuthViewDescription" = "Авторизованный аккаунт позволит синхронизировать прогресс с другими устройствами";

0 comments on commit 4238e2e

Please sign in to comment.