0

I Implement a localization in my app. add a Tamil language I follow a below link enter link description here How to choose a Tamil language In Edit Scheme option. I don't See a Tamil language. See a Screenshot [![enter image description here][2]][2] how to add a Tamil Language in my App. Any one help me.

mouni
  • 327
  • 1
  • 3
  • 15

1 Answers1

1

The reason you cannot add it in the scheme is that these are only for the iOS system languages. Tamil is not an optional system language for iOS but you can still use it in the localisation. In the project localisation:

Go to the bottom of the list proposed and select 'other'. A new list will open and you can choose Tamil there.

enter image description here

from here in the project variables.

enter image description here

as an app language you'll need to implement a language chooser button. See the link in the comments or do the following, add a function:

func changeToLanguage(_ langCode: String) {
    if Bundle.main.preferredLocalizations.first != langCode {
        let message = NSLocalizedString("In order to change the language, the App must be closed and reopened by you.", comment: "")
        let confirmAlertCtrl = UIAlertController(title: NSLocalizedString("App restart required", comment: ""), message: message, preferredStyle: .alert)

        let confirmAction = UIAlertAction(title: NSLocalizedString("Close now", comment: ""), style: .destructive) { _ in
            UserDefaults.standard.set([langCode], forKey: "AppleLanguages")
            UserDefaults.standard.synchronize()
            exit(EXIT_SUCCESS)
        }
        confirmAlertCtrl.addAction(confirmAction)

        let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
        confirmAlertCtrl.addAction(cancelAction)

        present(confirmAlertCtrl, animated: true, completion: nil)
    }
} 

and call it from a button:

@IBAction func didPressChangeLanguageButton() {
        let message = NSLocalizedString("Change language of this app including its content.", comment: "")
        let sheetCtrl = UIAlertController(title: NSLocalizedString("Choose language", comment: ""), message: message, preferredStyle: .actionSheet)

        for languageCode in Bundle.main.localizations.filter({ $0 != "Base" }) {
            let langName = Locale.current.localizedString(forLanguageCode: languageCode)
            if languageCode != "(null)" {
                let action = UIAlertAction(title: NSLocalizedString(langName!, comment: ""), style: .default) { _ in
                self.changeToLanguage(languageCode) // see step #2
                }
                sheetCtrl.addAction(action)
            }
        }

        let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
        sheetCtrl.addAction(cancelAction)

        sheetCtrl.popoverPresentationController?.sourceView = self.view
        sheetCtrl.popoverPresentationController?.sourceRect = self.changeLanguageButton.frame
        present(sheetCtrl, animated: true, completion: nil)
    }
Zyntx
  • 659
  • 6
  • 19
  • Hi Zyntx there is no Others option in edit Scheme option – mouni Apr 11 '18 at 08:27
  • go to the main Project and click on Info. I'll post an additional image. – Zyntx Apr 11 '18 at 08:32
  • @mouni: The reason you cannot add it in the scheme is that these are the iOS system languages. Tamil is not an optional **system** language for iOS but you can still use it in the localisation. You'll need to implement a language chooser in the app. – Zyntx Apr 11 '18 at 08:38
  • @mouni and to implement a language switcher look at the helper class proposed in this link: [change language programmatically](https://stackoverflow.com/questions/22061402/change-language-in-the-app-programmatically/22061784#22061784) – Zyntx Apr 11 '18 at 08:47