Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customise Mainstoryboard.strings per target

I have an Application with 2 targets. String resources in the app are scattered across the code and storyboard file. Now I need totally distinct set of strings for both the targets (Although in English language though for both targets). I was able to create 2 different versions of Localized.strings per string following this link - Alternative strings for different targets of same App - use NSLocalizedString?

But I could not find any such similar approach for segregating the Mainstoryboard.strings file per target. Should i make 2 copies of the MAinstoryboard.strings file and assign for each target. I haven't tried this this but something tells me that this might not be the best approach.

Surprisingly nothing on this on Apple tutorials. Any suggestions ?

like image 828
Dibzmania Avatar asked Jan 12 '17 05:01

Dibzmania


2 Answers

A code snippet for adding a fake language that could be the solution:

language = Bundle.main.preferredLocalizations[0]

if target == SOME_TARGET {

    if language == "en" {
        language = "fr" // fake language    
    } else if language == "ar" {
        language = "rs" // another fake language
    } else {
        // default app language
        language = "whatever" // default fake language 
    }

    UserDefaults.standard.set([language], forKey: "AppleLanguages")
    UserDefaults.standard.synchronize()
} else {
    // do nothing
}

Another proposed solution. Is to have two storyboard localisation files for each language. and replace them manually using the OS X finder when you switch between targets. But, I guess that wont help for the strings on the storyboard itself.

like image 52
hasan Avatar answered Oct 22 '22 07:10

hasan


I did make a Github project for Localization problems.

Using my iOS components, you will be able to put localizedString directly in your Storyboard file.

Xcode Example

like image 34
CZ54 Avatar answered Oct 22 '22 07:10

CZ54