[英]How to add a Xcode localization language via Fastlane script
I have a project with multiple app targets and need to be able to add an existing English localized string file to one of the targets for development use only. 我有一个包含多个应用程序目标的项目,需要能够将现有的英语本地化字符串文件添加到其中一个目标中,仅供开发使用。
Here is my scenario: 这是我的场景:
However, to help during development we currently manually add the English strings to Target B's localization files (using the existing file from Target A when prompted) , and remove it prior to App Store submission. 但是,为了在开发过程中提供帮助,我们目前手动将英文字符串添加到Target B的本地化文件(在提示时使用目标A中的现有文件) ,并在App Store提交之前将其删除。
Since we run Fastlane setup/teardown scripts already, I would like to automate adding/removing the English strings from the scripts so we don't have to do it manually every time. 由于我们已经运行Fastlane安装/拆卸脚本,我想自动添加/删除脚本中的英文字符串,这样我们就不必每次都手动执行。
In the Fastfile, I know how to add a file to Target B, but since the Localization files/references are structured a bit differently in Xcode than regular files I am not sure what the proper way to do it is. 在Fastfile中,我知道如何将文件添加到目标B,但由于本地化文件/引用在Xcode中的结构与常规文件略有不同,我不确定正确的方法是什么。
Here is what I have so far: 这是我到目前为止:
def add_english_localization()
require 'xcodeproj'
project = Xcodeproj::Project.open("../Code/#{XCODE_PROJ}")
app_target = project.targets.first #Target B
english_file_ref = project.main_group.new_file('../Code/TargetA/Application/Supporting Files/en.lproj') #Existing english file in Target A's directory
app_target.add_file_references([english_file_ref]) #This adds the file but doesn't properly update Xcode's Localization references...?
project.save
end
Screenshots: 截图:
Here's a little ruby script, using xcodeproj to remove and add localization: 这是一个小ruby脚本,使用xcodeproj删除和添加本地化:
To remove language (french in this example): 删除语言(本例中为法语):
require 'xcodeproj'
project_path = './Whatever.xcodeproj'
project = Xcodeproj::Project.open(project_path)
for o in project.objects do
if o.is_a? Xcodeproj::Project::Object::PBXGroup
if o.hierarchy_path == "/TargetA/Localizable.strings"
group = o
break
end
end
end
files = group.files
for file in files do
if file.path == "fr.lproj/Localizable.strings"
file.remove_from_project
puts "Removed " + file.path
end
end
project.save
To add language (also french): 添加语言(也是法语):
require 'xcodeproj'
project_path = './Whatever.xcodeproj'
project = Xcodeproj::Project.open(project_path)
for o in project.objects do
if o.is_a? Xcodeproj::Project::Object::PBXGroup
if o.hierarchy_path == "/TargetA/Localizable.strings"
group = o
break
end
end
end
file = project.new_file("fr.lproj/Localizable.strings")
file.move(group)
file.name = "fr"
project.save
You should be able to call it in fastfile, but I didn't check that... You could call it directly using sh("ruby ./name.rb")
你应该可以在fastfile中调用它,但我没有检查...你可以使用sh("ruby ./name.rb")
直接调用它sh("ruby ./name.rb")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.