Localization and tap gesture

In this app I have a view with 3 textFields or labels on which I have gesture recogniqzers.


They work OK.


I have localized the app for 2 more languages, and now, when I switxh language (inside the app), I get the following error:


2018-02-16 00:19:34.951810+0100 Autonomie[1635:1007703] [Warning] WARNING: A Gesture recognizer (<UITapGestureRecognizer: 0x1757fd90; state = Possible; view = <UITextView 0x17b86600>; target= <(action=autonomieVersionViewTapped:, target=<Autonomie.StartViewController 0x1757f890>)>>) was setup in a storyboard/xib to be added to more than one view (-><UITextView: 0x17ba8000; frame = (60.5 50; 198 25); text = 'version 0.5 © AlphaNums 2...'; clipsToBounds = YES; hidden = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x175e25d0>; layer = <CALayer: 0x175da320>; contentOffset: {0, 0}; contentSize: {198, 31}>) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.

<UIButtonLabel: 0x176d3da0; frame = (160 18; 0 0); text = 'Calcular el rango …'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x176d01c0>>

<UIButtonLabel: 0x1765cc40; frame = (160 18; 0 0); text = 'Calculer autonomie …'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x1765cda0>>


And gestures do not work.


If I switch back to the original language, everything OK.

Answered by Claude31 in 294901022

I want to let user chage the language directly from the app (imagine I want to show to a foreign friend, I don't want to be force to change the phone setting).


Anyway, I found the problem, not related to this : when I create a tapGestureRecognizer in IB, I get the warning.


I created programmatically, problem gone.

> when I switxh language (inside the app),


Why do it that way? Why not let the device do that for you?

2 years later…

I finally found here inspiration here for something very close to what I wanted:
https://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked

Button action to switch language:

Code Block
@objc func openSettings() {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return }
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: nil)
}
}
@IBAction func toggleLanguagePopover() {
var languages : [Language] = []
for country in Language.allLanguages { // I have defined the list of languages the app is localised for
languages.append(country)
}
var anAction : UIAlertAction
var alertStyle = UIAlertController.Style.alert
let alertController = UIAlertController(
title: NSLocalizedString("Language", comment: ""),
message: NSLocalizedString("Select a language, comment: "toggleLanguagePopover"), preferredStyle: alertStyle)
for i in 0..<languages.count {
anAction = UIAlertAction(title: languages[i].flag + " " + languages[i].fullname, style: .default, handler: { (action) -> Void in self.openSettings()} )
anAction.isEnabled = Global.shared.systemLanguage != Language.allLanguages[i] // Button for the already selected language is disabled
alertController.addAction(anAction)
}
let cancelAction = UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style: .destructive, handler: nil)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
}

This brings you to the app settings page with direct access to preferred languages list.
Click on language and return to your app from the navigation button. You have switched the app language.

It's very fast.

Only caveat, the device language does not change, so settings remain displayed in device's language. But that's a really minor annoyance.
Localization and tap gesture
 
 
Q