Skip to content

Instantly share code, notes, and snippets.

@STAR-ZERO
Last active February 21, 2020 05:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save STAR-ZERO/9130355 to your computer and use it in GitHub Desktop.
Save STAR-ZERO/9130355 to your computer and use it in GitHub Desktop.
UnityのiOSビルド時にローカライズファイルを設定する
#!/usr/bin/env ruby
require 'xcodeproj'
require 'fileutils'
PROJECT = 'Unity-iPhone'
TARGET = 'Unity-iPhone'
LIBRARY = 'Libraries'
LOCALIZE = 'Localize'
# localizeファイルを追加
def add_localize_file(project, localizations)
project.targets.each do |target|
next unless TARGET == target.name
build_phase = target.resources_build_phase
library_group = project.main_group.children.find {|child| child.path == LIBRARY}
localizations.each do |localization|
next if exist_localize?(build_phase, "#{localization[:name]}.strings")
localize_group = project.new(Xcodeproj::Project::Object::PBXVariantGroup)
localize_group.name = "#{localization[:name]}.strings"
library_group << localize_group
localization[:local].each do |local|
copy_localize(local)
localize_ref = localize_group.new_reference("#{local}.lproj/#{localization[:name]}.strings")
localize_ref.name = local
end
build_phase.add_file_reference(localize_group)
end
end
end
# ローカライズファイル追加済みか
def exist_localize?(build_phase, name)
!build_phase.files_references.find {|file| file.name == name }.nil?
end
# localizeファイルをコピー
def copy_localize(name)
from = File.expand_path("../../#{LOCALIZE}/#{name}.lproj", __FILE__)
to = "#{ARGV[0]}/#{LIBRARY}/#{name}.lproj"
unless File.exists?(to)
FileUtils.copy_entry(from, to)
end
end
project_path = ARGV[0] + "/#{PROJECT}.xcodeproj"
project = Xcodeproj::Project.new(project_path)
project.initialize_from_file
# ローカライズ
add_localize_file(project, [ {name: 'Localizable', local: ['Base', 'ja']} ])
project.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment