LocalizedString.swift 960 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // LocalizedString.swift
  3. // MockKit
  4. //
  5. // Created by Pete Schwamb on 3/18/23.
  6. // Copyright © 2023 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. class LocalBundle {
  10. /// Returns the resource bundle associated with the current Swift module.
  11. static var main: Bundle = {
  12. if let mainResourceURL = Bundle(for: LocalBundle.self).resourceURL,
  13. let bundle = Bundle(url: mainResourceURL.appendingPathComponent("MockKit_MockKit.bundle"))
  14. {
  15. return bundle
  16. }
  17. return Bundle(for: LocalBundle.self)
  18. }()
  19. }
  20. func LocalizedString(_ key: String, tableName: String? = nil, value: String? = nil, comment: String) -> String {
  21. if let value = value {
  22. return NSLocalizedString(key, tableName: tableName, bundle: LocalBundle.main, value: value, comment: comment)
  23. } else {
  24. return NSLocalizedString(key, tableName: tableName, bundle: LocalBundle.main, comment: comment)
  25. }
  26. }