简体   繁体   English

CMake 生成带有本地化的 xcode 项目

[英]CMake generate xcode project with localizations

We've are developing our OSX project using cMake as a tool to create the Xcode project.我们一直在使用 cMake 作为创建 Xcode 项目的工具来开发我们的 OSX 项目。

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).然而,事实证明我们现在需要一些本地化,为此我们需要英语和德语 .xib 文件(或 .strings 来生成它们,这不是重要的一点)。

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:我们将文件放在正确的位置并正确创建,但是当 cMake 生成项目时,这些文件作为两个完全独立且独立的文件插入到 Xcode 项目中,例如:

Foo.xib Foo.xib foo.xib foo.xib

Instead of two "sub-files" under the same name:而不是同名的两个“子文件”:

Foo.xib - Foo.xib (English) - Foo.xib (German) Foo.xib - Foo.xib(英语)- Foo.xib(德语)

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.如果我将 en.lproj 和 sv.lproj 中的 xib 直接拖放到项目资源管理器中的资源文件夹:Xcode 会自动检测到这是同一 UI 的一些不同语言,因此在项目设置中添加了这些语言自动地。 Also the xibs get a MainMenu.xib group in the project explorer three, consisting of both the languages.此外,xib 在项目资源管理器 3 中获得一个 MainMenu.xib 组,由两种语言组成。

I try to add the localized xib's to the project through cmake.我尝试通过 cmake 将本地化的 xib 添加到项目中。 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.它们被添加到资源文件夹中,但不是已识别的本地化,我在项目资源管理器中只有两个 xib,三个没有本地化,它们之间没有连接。

How can I make the localization work through cmake generation?如何通过 cmake 生成使本地化工作?

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?有没有办法通过 cmake 使用 .lproj 包生成 Xcode 项目?

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.我最终使用mod_pbxproj编写了我自己的 python 脚本,以在 cmake 生成它后修改 xcode 项目。 If you can get away with using a regular xcode project instead of a cmake generated one, I think you are better off.如果您可以使用常规的 xcode 项目而不是由 cmake 生成的项目,我认为您会更好。 What you have to do to make XCode recognize a set of files as localizations is pretty complex.要让 XCode 将一组文件识别为本地化,您必须做的事情非常复杂。

You can find an example of handling xib files for Xcode project here: https://github.com/open-eid/updater/blob/master/CMakeLists.txt .您可以在此处找到处理 Xcode 项目的xib文件的示例: https : //github.com/open-eid/updater/blob/master/CMakeLists.txt

Summary: one can use custom command + set MACOSX_PACKAGE_LOCATION property on resulting nib :总结:可以使用自定义命令 + 在生成的nib上设置MACOSX_PACKAGE_LOCATION属性:

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 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM