Xcodegen: Localized `strings` resources are not detected correctly

Created on 29 Jan 2020  路  6Comments  路  Source: yonaskolb/XcodeGen

I seem to be hitting the exact same issue as #80, namely that my Localizable.strings(dict) files (and InfoPlist.strings files) are not detected correctly and seen as loose files:

Screenshot 2020-01-29 at 02 19 00

As you can see, strings files for storyboards are seen correctly, whereas normal strings files are not seen as language variations of the same file.

The directory structure is correct though:

Application
  - Resources
    - Base.lproj
      - Authentication.storyboard
      - ... (only .storyboard files)
    - en.lproj
      - Authentication.strings
      - ... (other .strings files for storyboards)
      - InfoPlist.strings
      - Localizable.strings
      - Localizable.stringsdict
    - fr.lproj
      - Authentication.strings
      - ... (other .strings files for storyboards)
      - InfoPlist.strings
      - Localizable.strings
      - Localizable.stringsdict

My project file (mostly, the relevant bits):

name: MultiSelector
targets:
  MultiSelector:
    type: application
    platform: iOS
    sources:
      - Application
    settings:
      base:
        INFOPLIST_FILE: Application/Resources/Info.plist
        PRODUCT_NAME: $(TARGET_NAME)
        SWIFT_VERSION: 5.0

Also tried using XcodeGen in another project, same issue, which is worse there 'cause that project has +-10 languages.

All 6 comments

From my understanding, according to the implementation of #70, those files must also be in Base.lproj directory. PBXVariantGroups are created based on files sit in Base.lproj.

From Apple's own docs, they recommend to not add Localizable.strings (and such) to Base.lproj:

Add the file to your Xcode project, as described in Adding Languages. Don鈥檛 add Localizable.strings to the Base localization when the dialog appears.

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/MaintaingYourOwnStringsFiles/MaintaingYourOwnStringsFiles.html

So for interface builder files (storyboard, xib, nib) that are localised, the interface file should be in Base.lproj and the translation files (strings) in the corresponding language .lproj. For simple strings files such as Localizable.strings, InfoPlist.strings and others, they don't need to be in Base.lproj.

Note that you can have strings files in Base.lproj, but it is not required or expected by Xcode and other tooling.

Yeah I think so too. I just noted the current situation. This should be a valuable improvement/fix.

@djbe Title could be changed to "Localized .strings resources are not detected correctly"

Any info or workaround on this issues?

Hi all. This project grew out of my own needs, and I've never had any complicated localization requirements. I've always treated base as english (which would be the workaround here I believe).
Other contributors have added code over the years around localization. This fix would require changes around here https://github.com/yonaskolb/XcodeGen/blob/master/Sources/XcodeGenKit/SourceGenerator.swift#L460
Would welcome any PR's here, if they came with tests. That file has become a bit unwieldy over the years, and could do with some refactoring.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpassis picture rpassis  路  5Comments

mohammdsss1 picture mohammdsss1  路  6Comments

ismetanin picture ismetanin  路  3Comments

dabaddah picture dabaddah  路  4Comments

brentleyjones picture brentleyjones  路  6Comments