Localized project with several targets with localized app names

12,684

Solution 1

I cracked this nut in an XCode project which, I believe, tackles the same issue as you have, so hopefully this will help you. The solution contains two targets built from the same codebase (with a different app name) and which are fully localized, including the app's names. (It builds my freemium app called Growth (French: Croissance, Spanish: Crecer) and the paid version called Growth+ (French: Croissance+, Spanish: Crecer+).

I also stumbled on the InfoPlist.string files (which contain only the app's name). I got around the issue through the use of subfolders in my solution, and changing the targets to include the localized set of InfoPlist.strings from the relevant subfolder. Specifically, I have this structure:


    Root
    +-- en.lproj
    ¦   +-- Localizable.strings
    ¦   +-- SomeXib.xib
    +-- es.lproj
    ¦   +-- Localizable.strings
    ¦   +-- SomeXib.xib
    +-- fr.lproj
    ¦   +-- Localizable.strings
    ¦   +-- SomeXib.xib
    +-- OnlyInAppA
    ¦   +-- en.lproj
    ¦   ¦   +-- InfoPlist.strings
    ¦   +-- es.lproj
    ¦   ¦   +-- InfoPlist.strings
    ¦   +-- fr.lproj
    ¦       +-- InfoPlist.strings
    +-- OnlyInAppB
    ¦   +-- en.lproj
    ¦   ¦   +-- InfoPlist.strings
    ¦   +-- es.lproj
    ¦   ¦   +-- InfoPlist.strings
    ¦   +-- fr.lproj
    ¦       +-- InfoPlist.strings
    +-- AppA.plist
    +-- AppB.plist

And the only difference among my targets (other than different preprocessor symbols and different .plist file) is that AppA's build settings includes the InfoPlist.strings files under OnlyInAppA, whereas AppB's build settings includes the InfoPlist.strings files under OnlyInAppB.

The naming convention I used (OnlyInAppA/OnlyInAppB folders, AppB/AppB plist files) is obvious enough to make this a satisfactory approach, in my personal opinion.

Edit:

Please see these two XCode 4 screenshots to see where exactly to find the settings which are changed in the targets.

  1. In the target build settings, a different plist file is specified (note: XCode automatically does this for you when you add a new target) Build settings screenshot

  2. In the target build phases, in section Copy Bundle Resources, pick the version of InfoPlist.strings from the relevant OnlyInAppX subfolder (notice the gray text next to InfoPlist.strings on this screenshot--this will show a different location for the other target). You can achieve this by using the +/- buttons and replace the file with the intended one. Build phases screenshot

Solution 2

If this problem still persist: I have found a solution on how to add multiple InfoPlist.string localized for each target in your project. Please follow these steps:

  1. I assume you already have multiple targets.
  2. Go to the project folder in Finder.
  3. Create a folder specific for each target:

    create folders

  4. Create an InfoPlist.strings file in each folder:

    create files

  5. Add folders to targets specifying proper (and only!) target for each folder in your project:

    add folders to targets

  6. Remove target dependency for original InfoPlist.strings file for each new target.

    remove target dependencies for old .strings file

  7. Localize new InfoPlist.strings files:

    localize new files localize new files

  8. Build targets and check by changing language settings:

    french version english version

Solution 3

Just keep all the InfoPlist.strings files, under separate paths. Each would only be a member of one target.

Or did I not understand the question?

Solution 4

I have a similar setup where my the same software supports multiple domains, each domain accesses the exact same paths for various modules (e.g. blog, forums). In order to retain individuality per domain especially when the database service becomes unavailable I retain critical information in files, basically meta information. For localization I would keep a variable retaining each site/project's default language. You could determine the files containing the information to have their own domain or store all the projects in the same file, either way you would want to use that for your ultimate fallback or if you simply lack further public options to any/everyone with lower permissions than you until you implement such options (users being able to override the language option).

Share:
12,684
Paul Peelen
Author by

Paul Peelen

Happy guy coding in swift for ios, tvos, macos and vapor amongst others.

Updated on June 05, 2022

Comments

  • Paul Peelen
    Paul Peelen almost 2 years

    I have recently merged together 5 of my stand-alone projects into one project to have a common code base. So now I have one project with 5 targets instead.

    Each target has the same fileset, except for some files which differ for each target (such as Default.png, and icons files amongst others). My application is translated to 7 languages with English as default. The other languages are: Swedish, Dutch, German, French, Polish and Spanish.
    Now I would also like to translate the name of the application depending the language used. For instance, for my Swedish aviation app, the app should be called "Flyget ARN" in Swedish, but for English it should be called "Aviation ARN". All this is not a problem since this is done in the InfoPlist.string, however combining this with the localization of the app Is a problem.

    I recently wrote this question: Several localizations yet still showing English only and found out that I cannot combine several .strings files. (see the answer I wrote).

    So my question is the following:
    How can I have a localized app from a project containing several targets and also localize my applications name without having a DRY-violation (Duplicate code).

    Update
    This is still an issue, the answers given do not solve my problem.