I made a single file for a structure that I need to call in other classes but I am trying everything to make it work but it seems I am not going to make this alone and figure it out.
code for single file:
import Foundation
struct CustomLanguage {
func createBundlePath () -> Bundle {
let selectedLanguage = "en"
let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj")
return Bundle(path: path!)!
}
}
other class:
import Foundation
import UIKit
class signInViewController: UIViewController {
@IBOutlet weak var welcomeLabelSignIn: UILabel!
override func viewDidLoad() {
}
welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: "the structure call here" , value: "", comment: "")
{
so at the bundle: I Need to call that structure
the single file for the structure
I can't call it to localize the labels, buttons... in other classes
CodePudding user response:
Try this;
struct CustomLanguage {
static func createBundlePath () -> Bundle {
let selectedLanguage = "en"
let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj")
return Bundle(path: path!)!
}
}
Then;
welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: CustomLanguage.createBundlePath() , value: "", comment: "")