CMake generate xcode project with localizations
Asked Answered
C

2

8

We've are developing our OSX project using cMake as a tool to create the Xcode project.

However, it turns out we now need some localization, for which we need both English and German .xib files (or .strings to generate them, that's not the important bit).

We have the files in the right place and correctly created, but when cMake generates the project, the files are inserted into the Xcode project as two completely separate and independent files, such as:

Foo.xib Foo.xib

Instead of two "sub-files" under the same name:

Foo.xib - Foo.xib (English) - Foo.xib (German)

If i drag and drop the xib's that are in en.lproj and sv.lproj directly to the resources folder in the project explorer: Xcode automatically detects that this is some different languages of the same UI, hence the languages are added in the project settings automatically. Also the xibs get a MainMenu.xib group in the project explorer three, consisting of both the languages.

I try to add the localized xib's to the project through cmake. They get added to the resources folder but not as identified localizations, I only get two xibs in the project explorer three no localization no connection between them.

How can I make the localization work through cmake generation?

set(CEFCLIENT_RESOURCES_MAC_ENGLISH_LPROJ_SRCS_MACOSX
  mac/en.lproj/MainMenu.xib
  )

  set(CEFCLIENT_RESOURCES_MAC_SWEDISH_LPROJ_SRCS_MACOSX
  mac/sv.lproj/MainMenu.xib
  )

set(CEFCLIENT_RESOURCES_SRCS
  ${CEFCLIENT_RESOURCES_MAC_SRCS}
  ${CEFCLIENT_RESOURCES_MAC_ENGLISH_LPROJ_SRCS}
  ${CEFCLIENT_RESOURCES_MAC_SWEDISH_LPROJ_SRCS}
  ${CEFCLIENT_RESOURCES_RES_SRCS}
  )

Is there a way to generate the Xcode projects through cmake with the .lproj bundles working?

Compressibility answered 8/4, 2015 at 14:18 Comment(4)
Did you find any solution? I'm also struggeling with I18N and L17N.Acanthus
Ended up writing our own language handling instead, replacing text in the app on runtime...Compressibility
Have you ever thought of using Build Phases to do this? I wrote a localization system that did this. While we our XIB themselves were not localized (we opted to have strings that needed to be localized get updated through code).Folliculin
@MobileBen How do you do that in CMake?Disinfectant
F
3

We just did this ourselves. Unfortunately the solution is not pretty. I ended up writing my own python script using mod_pbxproj to modify the xcode project after cmake generated it. If you can get away with using a regular xcode project instead of a cmake generated one, I think you are better off. What you have to do to make XCode recognize a set of files as localizations is pretty complex.

Fidellia answered 10/8, 2017 at 5:57 Comment(0)
M
0

You can find an example of handling xib files for Xcode project here: https://github.com/open-eid/updater/blob/master/CMakeLists.txt.

Summary: one can use custom command + set MACOSX_PACKAGE_LOCATION property on resulting nib:

add_custom_command( OUTPUT MainMenu.nib
    COMMAND ibtool --errors --warnings --notices --output-format human-readable-text
        --compile MainMenu.nib ${CMAKE_CURRENT_SOURCE_DIR}/mac/en.lproj/MainMenu.xib
)
set_source_files_properties( MainMenu.nib
    PROPERTIES MACOSX_PACKAGE_LOCATION Resources/en.lproj )
Mckinnie answered 20/12, 2020 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.