To run the example project, clone the repo, and run pod install
from the Example directory first.
To start using ResxSwift you first need to register your resx resource files:
guard let filePath_en = Bundle.main.path(forResource: "Resource.en", ofType: "resx") else { fatalError("File load error") }}
ResxSwift.shared.load(fileURL: URL(fileURLWithPath: filePath_en), language: "en", namespace: "Resource")
To use your loaded language resources all you need to do is:
ResxSwift.shared.localizedString("key")
ResxSwift supports multiple languages and namespaces to make it easy for you to load multiple resources without them interfering with each other.
To load multiple resources, just make sure to supply the correct language and, if applicable, namespace.
guard let resourceFilePath_en = Bundle.main.path(forResource: "Resource.en", ofType: "resx") else { fatalError("File load error") }}
guard let clientFilePath_en = Bundle.main.path(forResource: "Client.en", ofType: "resx") else { fatalError("File load error") }}
ResxSwift.shared.load(fileURL: URL(fileURLWithPath: filePath_en), language: "en", namespace: "Resource")
ResxSwift.shared.load(fileURL: URL(fileURLWithPath: filePath_en), language: "en", namespace: "Client")
When loading a resource file you have to supply a language. To reference the language when fetching a localization you just supply the language, like: ResxSwift.shared.localizedString("key", language: "en")
Supplying a namespace
is optional. If no namespace is supplied ResxSwift will infer namespace by extracting all characters from the filename up until the first period. Namespace.en.resx
will result in Namespace
as the namespace. To reference the namespace when fetching a localization you just supply the namespace, like: ResxSwift.shared.localizedString("key", namespace: "Namespace")
ResxSwift supports using a default language.
ResxSwift.shared.defaultLanguage = "en"
Note defaultLanguage
will automatically be set to the initial language loaded.
ResxSwift supports using a default namespace.
ResxSwift.shared.defaultNamespace = "en"
Note defaultNamespace
will automatically be set to the initial namespace loaded.
ResxSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ResxSwift'
amnell, mathias@apping.se
ResxSwift is available under the MIT license. See the LICENSE file for more info.