如何在国际化我的应用程序之前更改 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:14:52  来源:igfitidea点击:

How do I change the Development language in Xcode before internationalizing my app?

iosxcodeinternationalization

提问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.plistwas left to English. So I changed CFBundleDevelopmentRegionto frso that it matches the real language that was used. But XCode keeps telling me that my Development language is English:

我正在接管一个完全用法语编写的应用程序。代码中的字符串是用法语硬编码的,故事板中的所有消息都是法语。但是最初的开发区域Info.plist留给了英语。所以我更改CFBundleDevelopmentRegionfr使其与使用的真实语言相匹配。但是 XCode 一直告诉我我的开发语言是英语:

XCode 6.3.2 project Info tab

XCode 6.3.2 project Info tab

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.pbxprojfile:

以下过程对我有用,但它包括手动编辑project.pbxproj文件:

  1. Quit XCode
  2. Open the project.pbxprojfile with your favorite text editor
  3. Update the following section (near developmentRegion):
  1. 退出 XCode
  2. project.pbxproj使用您喜欢的文本编辑器打开文件
  3. 更新以下部分(靠近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 存储库,该项目最初使用英语作为默认开发语言创建,然后通过上述过程更新为使用法语作为开发语言。

Project ScreenShot

Project ScreenShot

回答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.pbxprojmanually. 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.stringsto MyProject/sv.lproj/InfoPlist.stringsseems to have fixed it. Now the "Development Language" shows up as Swedish, and I can add an English translation.

并将文件移动MyProject/en.lproj/InfoPlist.stringsMyProject/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.

添加翻译后,故事板有一个扩展三角形,其中基本语言是现有的瑞典语版本,翻译是英文的字符串文件。

The storyboard have an English translation. Yay.

The storyboard have an English translation. Yay.

回答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.plistfile under Supporting Filesgroup in the Project Navigator (on the right). Then, in the editor-view in the Localization native development regionclick on the up-and-down-arrows on the right of 'English' and select France.

在项目导航器(右侧)中选择组Info.plist下的文件Supporting Files。然后,在编辑器视图中,Localization native development region单击“English”右侧的上下箭头并选择France

Open base-language selection

Open base-language selection

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/