Skip to content

Instantly share code, notes, and snippets.

@nakajijapan
Created October 15, 2020 03:01
Show Gist options
  • Save nakajijapan/07479581c35172f922b4b8baf1a32194 to your computer and use it in GitHub Desktop.
Save nakajijapan/07479581c35172f922b4b8baf1a32194 to your computer and use it in GitHub Desktop.
LangファイルをCSVにする
require 'bundler'
require 'pathname'
require 'colorize'
project_root = Pathname.new(File.dirname(__FILE__) + '/../')
LANG_FILE = "#{project_root}/Project/Base.lproj/Localizable.strings"
puts LANG_FILE.colorize(:blue)
puts "Input".colorize(:green)
strings = []
File.open(LANG_FILE, mode = "rt"){|f|
f.each_line{|line|
if line =~ /^\/\/ NOTE/i
deleted_note_line = line.gsub(/\/\/ Note:\s?/i, '')
formatted_string = "\nNOTE: #{deleted_note_line.chomp}\n"
strings.append(formatted_string)
puts formatted_string.colorize(:yellow)
else
lang_strings = line.gsub(/\"/i, '').gsub(/;$/i, '').split(" = ")
formatted_string = lang_strings.last + "\n"
strings.append(formatted_string)
puts formatted_string.colorize(:yellow)
end
}
}
puts "Output".colorize(:green)
File.open("output.txt", mode = "w") { |file|
strings.map { |line| file.write(line ) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment