0

I am working on an app which runs in 2 languages, English and Persian (farsi). So user can select his desired language and app is displayed in that language. What should I do?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253

2 Answers2

0

First you should use realm, magical records or an API to store what the user picks. Then you could create your own type of localizeable string handeler, by having an array with 2 dictionaries 1 with english and 1 with persian that all the texts in your application will read from just as you do with a normal localizeable.

Vollan
  • 1,887
  • 11
  • 26
0

Depends on what are your trying to achieve, there is an approach that might be useful to your case, which is:

  1. Declare a global variable which should represents the key of the current used language in the app, call it appLanguageKey String -for example-:

    var appLanguageKey = "english"

  2. Create a datastore for storing both languages desired caption for each term, it might looks like (contains):

    term_key term_english term_farsi

    greeting_key Hello Hoi

    bye_key Bye Doei

For now, you could get the desired value if you tried to do:

desiredTerm = "select term_\(appLanguageKey) where term_key = 'greeting_key'"

Consider it as pseudo-code, the condition should be similar to it.

By implementing such a function that returns a string (I will assume that it is: getDesiredCaption(_ termKey: String) -> String in the following code snippet), you will be able to automatically set the desired caption for any UI component, just call it in viewWillAppear method the view controller:

override func viewWillAppear(_ animated: Bool) {
    .
    .
    .

    label.text = getDesiredCaption("greeting_key")
    // Since that 'appLanguageKey' global viriable is "english",
    // the output should be "Hello"

    .
    .
    .
}

All you have to do for changing the language of the app is to change the value of appLanguageKey to "farsi".


For another approach which related to the Internationalization and Localization, you might want to check this answer, it should affect the app to let its navigation to be from right to left.

Hope this helped.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143