Skip to content

Commit

Permalink
formatt files
Browse files Browse the repository at this point in the history
  • Loading branch information
LapStore committed Jan 7, 2019
1 parent d365d89 commit e2396d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Localizable.podspec → LocalizableLib.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'LocalizableLib'
s.version = '0.1.3'
s.version = '0.1.4'
s.summary = 'support change language on the fly and Right to left languages and localize views from StoryBoard'
s.description = <<-DESC
support change language on the fly and Right to left languages and localize views from StoryBoard!
Expand All @@ -13,6 +13,6 @@ DESC
s.source = { :git => 'https://github.com/sh3at90/Localization.git', :tag => s.version.to_s }

s.ios.deployment_target = '10.0'
s.source_files = 'Localizable/*'
s.source_files = 'LocalizableLib/*'

end
22 changes: 18 additions & 4 deletions LocalizableLib/MoLocalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
//////////////

import UIKit

struct Constants {
static let appleLanguage = "AppleLanguages"
static let defaultLanguage = "en"
static let arabicLanguage = "ar"
static let arabicLanguage = "ar"
}

class MoLocalization: NSObject {

static var isRightToLeftLanguage = false

private class func reset(startStoryBorad: String, startViewController: String) {
let rootviewcontroller: UIWindow = ((UIApplication.shared.delegate?.window)!)!
let stry = UIStoryboard(name: startStoryBorad, bundle: nil)
rootviewcontroller.rootViewController = stry.instantiateViewController(withIdentifier: startViewController)
}

class func setCurrentLang(lang: String, isRightToLeft: Bool = false, forceReset: Bool = false , startStoryBorad: String? = nil, startViewController: String? = nil) {
MoLocalization.isRightToLeftLanguage = isRightToLeft
let userdef = UserDefaults.standard
Expand All @@ -28,15 +33,19 @@ class MoLocalization: NSObject {
if let startStoryBorad = startStoryBorad, let startViewController = startViewController, forceReset == true{
reset(startStoryBorad: startStoryBorad, startViewController: startViewController)
}

}

private class func enableRightToLeft() {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
UINavigationBar .appearance().semanticContentAttribute = .forceRightToLeft
UIView.appearance().semanticContentAttribute = .forceRightToLeft
UINavigationBar .appearance().semanticContentAttribute = .forceRightToLeft
}

private class func enableLeftToRight() {
UIView.appearance().semanticContentAttribute = .forceLeftToRight
UINavigationBar .appearance().semanticContentAttribute = .forceLeftToRight
}

public class func currentAppleLanguage() -> String {
let userdef = UserDefaults.standard
let langArray = userdef.object(forKey: Constants.appleLanguage) as? NSArray
Expand All @@ -48,9 +57,14 @@ class MoLocalization: NSObject {
return Constants.defaultLanguage
}
}


extension String {

func localized() -> String {
let path = Bundle.main.path(forResource: MoLocalization.currentAppleLanguage(), ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}}
}

}

0 comments on commit e2396d8

Please sign in to comment.