GoogleSignInButtonStrings.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2022 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. /// A type retrieving the localized strings for the sign-in button text.
  18. @available(iOS 13.0, macOS 10.15, *)
  19. struct GoogleSignInButtonString {
  20. /// Button text used as both key in localized strings files and default value
  21. /// for the standard button.
  22. private let standardButtonText = "Sign in"
  23. /// Button text used as both key in localized strings files and default value
  24. /// for the wide button.
  25. private let wideButtonText = "Sign in with Google"
  26. /// The table name for localized strings (i.e. file name before .strings
  27. /// suffix).
  28. private let stringsTableName = "GoogleSignIn"
  29. /// Returns the localized string for the key if available, or the supplied
  30. /// default text if not.
  31. /// - parameter key: A `String` key to look up.
  32. /// - parameter text: The default `String` text.
  33. /// - returns Either the found `String` or the provided default text.
  34. private func localizedString(key: String, text: String) -> String {
  35. guard let frameworkBundle = Bundle.gidFrameworkBundle() else { return text }
  36. return frameworkBundle.localizedString(
  37. forKey: key,
  38. value: text,
  39. table: stringsTableName
  40. )
  41. }
  42. /// Localized text for the standard button.
  43. @available(iOS 13.0, macOS 10.15, *)
  44. var localizedStandardButtonText: String {
  45. return localizedString(key: standardButtonText, text: "No translation")
  46. }
  47. /// Localized text for the wide button.
  48. @available(iOS 13.0, macOS 10.15, *)
  49. var localizedWideButtonText: String {
  50. return localizedString(key: wideButtonText, text: "No translation")
  51. }
  52. }