如何在国际化我的应用程序之前更改 Xcode 中的开发语言?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30695493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change the Development language in Xcode before internationalizing my app?
提问by Sebastien
I'm taking over an app that was written entirely in French. Strings are hardcoded in French in the code, and all the messages in the storyboard are in French. But the initial development region in Info.plist
was left to English. So I changed CFBundleDevelopmentRegion
to fr
so that it matches the real language that was used. But XCode keeps telling me that my Development language is English:
我正在接管一个完全用法语编写的应用程序。代码中的字符串是用法语硬编码的,故事板中的所有消息都是法语。但是最初的开发区域Info.plist
留给了英语。所以我更改CFBundleDevelopmentRegion
为fr
使其与使用的真实语言相匹配。但是 XCode 一直告诉我我的开发语言是英语:
How can I correct that? The goal is to be able to activate Base Internationalization and have it use French as the Base language instead of English.
我该如何纠正?目标是能够激活基础国际化并使其使用法语而不是英语作为基础语言。
回答by Vladimir Kofman
The following procedure worked for me, but it includes manually editing project.pbxproj
file:
以下过程对我有用,但它包括手动编辑project.pbxproj
文件:
- Quit XCode
- Open the
project.pbxproj
file with your favorite text editor - Update the following section (near
developmentRegion
):
- 退出 XCode
project.pbxproj
使用您喜欢的文本编辑器打开文件- 更新以下部分(靠近
developmentRegion
):
OLD:
老的:
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
NEW:
新的:
developmentRegion = fr;
hasScannedForEncodings = 0;
knownRegions = (
fr,
Base,
);
I've created a GitHub repositorywith a sample project that was initially created with Englishas default Development Language, and then updated by the procedure above to use Frenchas Development Language.
我创建了一个带有示例项目的GitHub 存储库,该项目最初使用英语作为默认开发语言创建,然后通过上述过程更新为使用法语作为开发语言。
回答by geon
I might have figured it out.
我可能已经想通了。
I have built an app in Swedish, but the development language is set to English.
我用瑞典语构建了一个应用程序,但开发语言设置为英语。
I edited MyProject.xcodeproj/project.pbxproj
manually. There are two lines like this:
我MyProject.xcodeproj/project.pbxproj
手动编辑。有两行是这样的:
91C8245918BDFA6100A9972F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
and this section:
和本节:
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
Changing all "en" to "sv" like this:
像这样将所有“en”更改为“sv”:
91C8245918BDFA6100A9972F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = "<group>"; };
and
和
developmentRegion = Swedish;
hasScannedForEncodings = 0;
knownRegions = (
sv,
Base,
);
and moving the file MyProject/en.lproj/InfoPlist.strings
to MyProject/sv.lproj/InfoPlist.strings
seems to have fixed it. Now the "Development Language" shows up as Swedish, and I can add an English translation.
并将文件移动MyProject/en.lproj/InfoPlist.strings
到MyProject/sv.lproj/InfoPlist.strings
似乎已修复它。现在“开发语言”显示为瑞典语,我可以添加英文翻译。
After adding the translation, the storyboard has an expand-triangle where the base language is the existing Swedish version, and the translation is a strings-file in english.
添加翻译后,故事板有一个扩展三角形,其中基本语言是现有的瑞典语版本,翻译是英文的字符串文件。
回答by Simon
I wanted to develop the project in my own "developer" language by using placeholders instead of real texts in example "WLAN_NOT_AVAILABLE" inside of NSLocalizedString which later on will be translated in different languages including english, off course. I do not like when I must write whole sentences right in the code.
我想通过在 NSLocalizedString 内部的示例“WLAN_NOT_AVAILABLE”中使用占位符而不是真实文本,以我自己的“开发人员”语言开发项目,稍后将被翻译成不同的语言,包括英语,当然。我不喜欢我必须在代码中写出完整的句子。
I did just open *.pbxproj file inside of *.xcodeproj folder and changed the following line to:
我只是在 *.xcodeproj 文件夹中打开了 *.pbxproj 文件并将以下行更改为:
developmentRegion = Base;
After that English was no more set as development language and I was able to treat it as any one else. This gives you as developer the possibility to write short text placeholders and delegate the correct spelling to another in your team.
在那之后,英语不再被设置为开发语言,我可以像对待其他任何语言一样对待它。这使您作为开发人员可以编写短文本占位符并将正确的拼写委托给团队中的其他人。
回答by dergab
Select the Info.plist
file under Supporting Files
group in the Project Navigator (on the right). Then, in the editor-view in the Localization native development region
click on the up-and-down-arrows on the right of 'English' and select France
.
在项目导航器(右侧)中选择组Info.plist
下的文件Supporting Files
。然后,在编辑器视图中,Localization native development region
单击“English”右侧的上下箭头并选择France
。
This should be it. Although, Xcode sometimes doesn't update the "Info" view of the project settings.
应该是这样。虽然,Xcode 有时不会更新项目设置的“信息”视图。
回答by Arthur Gevorkyan
I hope I understood the question. AFAIK, it's quite simple to achieve what you want using the Xcode's GUI as described here: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/InternationalizingYourUserInterface/InternationalizingYourUserInterface.html
我希望我理解了这个问题。AFAIK,使用 Xcode 的 GUI 实现您想要的内容非常简单,如下所述:https: //developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/InternationalizingYourUserInterface/InternationalizingYourUserInterface.html
回答by ralf
Here is a Ruby script to change the development region in the Xcode project using the cocoapods libraries:
这是使用 cocoapods 库更改 Xcode 项目中的开发区域的 Ruby 脚本:
require 'fileutils'
require 'Xcodeproj'
filename = ARGV.first
raise "Argument '#{filename}' is not a valid .xcodeproject" unless filename && File.directory?(filename) && File.extname(filename).downcase == ".xcodeproj"
puts "Region to set: "
region = $stdin.gets.chomp
project = Xcodeproj::Project.open(filename)
project.root_object.development_region = region
project.save
puts "#{project.path}", "development_region = #{project.root_object.development_region}"
https://www.ralfebert.de/snippets/ios/xcode-change-development-language/
https://www.ralfebert.de/snippets/ios/xcode-change-development-language/