Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
More localization (#11)
Browse files Browse the repository at this point in the history
* Localization improvements

yankodimitrov#49

* Russian localization

We're translating our app to more languages, so more to come

* Swift 3
  • Loading branch information
ysoftware authored and moogle19 committed May 22, 2017
1 parent 9babe5b commit 34c8514
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 24 deletions.
16 changes: 8 additions & 8 deletions PasscodeLock/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import Foundation

func localizedStringFor(_ key: String, comment: String) -> String {
func localizedStringFor(key: String, comment: String) -> String {

let name = "PasscodeLock"
let bundle = bundleForResource(name, ofType: "strings")
return NSLocalizedString(key, tableName: name, bundle: bundle, comment: comment)
let defaultString = NSLocalizedString(key, tableName: name, bundle: Bundle(for: PasscodeLock.self), comment: comment)

return NSLocalizedString(key, tableName: name, bundle: Bundle.main, value: defaultString, comment: comment)
}

func bundleForResource(_ name: String, ofType type: String) -> Bundle {
func bundleForResource(name: String, ofType type: String) -> Bundle {

if(Bundle.main.path(forResource: name, ofType: type) != nil) {
return Bundle.main
}

return Bundle(for: PasscodeLock.self)
}
4 changes: 2 additions & 2 deletions PasscodeLock/PasscodeLock/ChangePasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct ChangePasscodeState: PasscodeLockStateType {

init() {

title = localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title")
description = localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description")
title = localizedStringFor(key: "PasscodeLockChangeTitle", comment: "Change passcode title")
description = localizedStringFor(key: "PasscodeLockChangeDescription", comment: "Change passcode description")
}

func accept(passcode: String, from lock: PasscodeLockType) {
Expand Down
8 changes: 4 additions & 4 deletions PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct ConfirmPasscodeState: PasscodeLockStateType {
init(passcode: String) {

passcodeToConfirm = passcode
title = localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title")
description = localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description")
title = localizedStringFor(key: "PasscodeLockConfirmTitle", comment: "Confirm passcode title")
description = localizedStringFor(key: "PasscodeLockConfirmDescription", comment: "Confirm passcode description")
}

func accept(passcode: String, from lock: PasscodeLockType) {
Expand All @@ -33,8 +33,8 @@ struct ConfirmPasscodeState: PasscodeLockStateType {

} else {

let mismatchTitle = localizedStringFor("PasscodeLockMismatchTitle", comment: "Passcode mismatch title")
let mismatchDescription = localizedStringFor("PasscodeLockMismatchDescription", comment: "Passcode mismatch description")
let mismatchTitle = localizedStringFor(key: "PasscodeLockMismatchTitle", comment: "Passcode mismatch title")
let mismatchDescription = localizedStringFor(key: "PasscodeLockMismatchDescription", comment: "Passcode mismatch description")

lock.changeState(SetPasscodeState(title: mismatchTitle, description: mismatchDescription))

Expand Down
4 changes: 2 additions & 2 deletions PasscodeLock/PasscodeLock/EnterPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct EnterPasscodeState: PasscodeLockStateType {
init(allowCancellation: Bool = false) {

isCancellableAction = allowCancellation
title = localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description")
title = localizedStringFor(key: "PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor(key: "PasscodeLockEnterDescription", comment: "Enter passcode description")
}

mutating func accept(passcode: String, from lock: PasscodeLockType) {
Expand Down
4 changes: 2 additions & 2 deletions PasscodeLock/PasscodeLock/PasscodeLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ open class PasscodeLock: PasscodeLockType {
guard isTouchIDAllowed else { return }

let context = LAContext()
let reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "TouchID authentication reason")
let reason = localizedStringFor(key: "PasscodeLockTouchIDReason", comment: "TouchID authentication reason")

context.localizedFallbackTitle = localizedStringFor("PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button")
context.localizedFallbackTitle = localizedStringFor(key: "PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button")

context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
success, error in
Expand Down
4 changes: 2 additions & 2 deletions PasscodeLock/PasscodeLock/RemovePasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct RemovePasscodeState: PasscodeLockStateType {

init() {

title = localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description")
title = localizedStringFor(key: "PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor(key: "PasscodeLockEnterDescription", comment: "Enter passcode description")
}

mutating func accept(passcode: String, from lock: PasscodeLockType) {
Expand Down
4 changes: 2 additions & 2 deletions PasscodeLock/PasscodeLock/SetPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct SetPasscodeState: PasscodeLockStateType {

init() {

title = localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title")
description = localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description")
title = localizedStringFor(key: "PasscodeLockSetTitle", comment: "Set passcode title")
description = localizedStringFor(key: "PasscodeLockSetDescription", comment: "Set passcode description")
}

func accept(passcode: String, from lock: PasscodeLockType) {
Expand Down
5 changes: 4 additions & 1 deletion PasscodeLock/PasscodeLockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat
passcodeLock = PasscodeLock(state: state, configuration: configuration)

let nibName = "PasscodeLockView"
let bundle: Bundle = bundleForResource(nibName, ofType: "nib")
let bundle: Bundle = bundleForResource(name: nibName, ofType: "nib")

super.init(nibName: nibName, bundle: bundle)

Expand Down Expand Up @@ -86,6 +86,9 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat

updatePasscodeView()
deleteSignButton?.isEnabled = false

cancelButton?.setTitle(localizedStringFor(key: "PasscodeLockCancelButtonTitle", comment: "Cancel Button Title"), for: .normal)
deleteSignButton?.setTitle(localizedStringFor(key: "PasscodeLockDeleteButtonTitle", comment: "Delete Button Title"), for: .normal)

setupEvents()
}
Expand Down
8 changes: 7 additions & 1 deletion PasscodeLock/en.lproj/PasscodeLock.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
"PasscodeLockMismatchTitle" = "Try again";
"PasscodeLockMismatchDescription" = "Passcodes didn\'t match.";

/* Cancel Button Title */
"PasscodeLockCancelButtonTitle" = "Cancel";

/* Delete Button Title */
"PasscodeLockDeleteButtonTitle" = "Delete";

/* Touch ID Reason */
"PasscodeLockTouchIDReason" = "Authentication required to proceed";

/* Touch ID Fallback Button */
"PasscodeLockTouchIDButton" = "Enter Passcode";
"PasscodeLockTouchIDButton" = "Enter Passcode";
40 changes: 40 additions & 0 deletions PasscodeLock/ru.lproj/PasscodeLock.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
PasscodeLock.strings
PasscodeLock

Перевёл Ярослав Ерохин github/ysoftware
Created by Yanko Dimitrov on 8/28/15.
Copyright (c) 2015 Yanko Dimitrov. All rights reserved.
*/

/* Enter Passcode State */
"PasscodeLockEnterTitle" = "Введите пароль";
"PasscodeLockEnterDescription" = "Введите пароль, чтобы войти.";

/* Set Passcode State */
"PasscodeLockSetTitle" = "Введите пароль";
"PasscodeLockSetDescription" = "Введите новый пароль.";

/* Confirm Passcode State */
"PasscodeLockConfirmTitle" = "Подтвердите пароль";
"PasscodeLockConfirmDescription" = "Введите пароль ещё раз.";

/* Change Passcode State */
"PasscodeLockChangeTitle" = "Введите старый пароль.";
"PasscodeLockChangeDescription" = "Введите ваш старый пароль.";

/* Passcode Mismatch State */
"PasscodeLockMismatchTitle" = "Попробуйте ещё раз.";
"PasscodeLockMismatchDescription" = "Пароли должны совпадать.";

/* Cancel Button Title */
"PasscodeLockCancelButtonTitle" = "Отмена";

/* Delete Button Title */
"PasscodeLockDeleteButtonTitle" = "Удалить";

/* Touch ID Reason */
"PasscodeLockTouchIDReason" = "Необходимо подтвердить личность.";

/* Touch ID Fallback Button */
"PasscodeLockTouchIDButton" = "Ввести пароль.";

0 comments on commit 34c8514

Please sign in to comment.