yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
7.06k stars 819 forks source link

Localized `strings` resources are not detected correctly #763

Open djbe opened 4 years ago

djbe commented 4 years ago

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.

ikesyo commented 4 years ago

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.

djbe commented 4 years ago

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’t 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.

ikesyo commented 4 years ago

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

Adobels commented 4 years ago

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

klauslanza commented 4 years ago

Any info or workaround on this issues?

yonaskolb commented 4 years ago

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.

sassiwalid commented 3 years ago

Hi all, I think that I have the same issue.

Capture d’écran 2021-01-04 à 13 29 12

Any info or workaround on this issues?

podkovyrin commented 3 years ago

Came up with a kind of solution. Since we don't use Interface Builder in our project there is a workaround to disable Base Internationalization entirely using useBaseInternationalization: false. With that option enabled .strings and .stringdict files in en.lproj were detected correctly. https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#options

EyreFree commented 3 years ago

Came up with a kind of solution. Since we don't use Interface Builder in our project there is a workaround to disable Base Internationalization entirely using useBaseInternationalization: false. With that option enabled .strings and .stringdict files in en.lproj were detected correctly. https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#options

Succeeded after deleting Base.lproj, 😀

99arobe commented 9 months ago

@djbe I had a very similar project structure to you. I found a workaround that isn't great but might help some folks.

I added an empty Localizable.strings directory inside of Base.lproj and Xcode then picked up all the strings files elsewhere. It then seems to generate the appropriate PBXVariantGroup children for each locale.

So if you had:

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

I did this:

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

Note that empty directories obviously aren't indexed by git so if you (or seeing as 4 years have gone by, I imagine someone else reading this) decide go with this approach then stick a file in the directory.

Overall, this is obviously vulnerable to the implementation changing. So a proper fix here is still needed at some point.