GoogleSignInButtonStrings.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #if !arch(arm) && !arch(i386)
  17. import Foundation
  18. /// A type retrieving the localized strings for the sign-in button text.
  19. @available(iOS 13.0, macOS 10.15, *)
  20. struct GoogleSignInButtonString {
  21. /// Button text used as both key in localized strings files and default value
  22. /// for the standard button.
  23. private let standardButtonText = "Sign in"
  24. /// Button text used as both key in localized strings files and default value
  25. /// for the wide button.
  26. private let wideButtonText = "Sign in with Google"
  27. /// The table name for localized strings (i.e. file name before .strings
  28. /// suffix).
  29. private let stringsTableName = "GoogleSignIn"
  30. /// Returns the localized string for the key if available, or the supplied
  31. /// default text if not.
  32. /// - parameter key: A `String` key to look up.
  33. /// - parameter text: The default `String` text.
  34. /// - returns Either the found `String` or the provided default text.
  35. private func localizedString(key: String, text: String) -> String {
  36. guard let frameworkBundle = Bundle.gidFrameworkBundle() else { return text }
  37. return frameworkBundle.localizedString(
  38. forKey: key,
  39. value: text,
  40. table: stringsTableName
  41. )
  42. }
  43. /// Localized text for the standard button.
  44. @available(iOS 13.0, macOS 10.15, *)
  45. var localizedStandardButtonText: String {
  46. return localizedString(key: standardButtonText, text: "No translation")
  47. }
  48. /// Localized text for the wide button.
  49. @available(iOS 13.0, macOS 10.15, *)
  50. var localizedWideButtonText: String {
  51. return localizedString(key: wideButtonText, text: "No translation")
  52. }
  53. }
  54. #endif // !arch(arm) && !arch(i386)