Skip to content

Commit

Permalink
Added configureIfNeeded method so there is no necessity to call confi…
Browse files Browse the repository at this point in the history
…gure() if you want to configure it for main bundle
  • Loading branch information
tomkowz committed Feb 13, 2016
1 parent 8516b80 commit 4962b49
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Swifternalization/Swifternalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ final public class Swifternalization {
*/
private var translations = [Translation]()

/**
Determine whether Swifternalization is configured.
It should be considered configured after `load(bundle:)` method is called.
*/
private var configured = false

// MARK: Public Methods

/**
Expand All @@ -46,6 +52,16 @@ final public class Swifternalization {
sharedInstance.load(bundle)
}

/**
Configures Swifternalization if you didn't do that before calling
`localizedString...` methods.
*/
private class func configureIfNeeded(bundle: NSBundle = NSBundle.mainBundle()) {
if sharedInstance.configured == false {
configure(bundle)
}
}

/**
Get localized value for a key.

Expand Down Expand Up @@ -83,6 +99,9 @@ final public class Swifternalization {
specified or `key` if `defaultValue` is not specified.
*/
public class func localizedString(key: String, stringValue: String, fittingWidth: Int? = nil, defaultValue: String? = nil, comment: String? = nil) -> String {

configureIfNeeded()

/**
Filter translations and get only these that match passed `key`.
In ideal case when all is correctly filled by a developer it should be
Expand Down Expand Up @@ -165,6 +184,7 @@ final public class Swifternalization {

// Store processed translations in `translations` variable for future use.
translations = LoadedTranslationsProcessor.processTranslations(baseTranslations, preferedLanguageTranslations: languageTranslations, sharedExpressions: expressions)
configured = true
}

/**
Expand Down

0 comments on commit 4962b49

Please sign in to comment.