2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Localizable.stringsをCSVに吐き出す適当なRuby的ななにか

Last updated at Posted at 2013-05-15

iOSアプリを開発していて、Localizable.stringsを翻訳するのってとてもめんどくさくないですか?

特に、ディレクター・エンジニアのチームで、ディレクターが翻訳をする場合、すぐに「エクセルで!」とか言ってくるので、めんどくせーなーと思ったりしながらやりますよね?

そこで、最近学びたてのRubyで勉強がてらちょっとしたスクリプトを書いてみました。(のでほんとにテキトーです。だれか書きなおして下さい)

ほんとにやってることは簡単で、Localizable.stringsの一行目がダブルクォーテーションがあるものを、適当に切ってCSVに書き出しているだけ。

動かしてみたところなんとなく動いてるっぽい。

運用としては、

  1. 日本語のLocalizable.stringsファイルを作る
  2. CSVで吐き出す
  3. 翻訳する
  4. エクセルで、他の言語のLocalizable.stringを作る
  5. エクセルからコピペ!

コピペ!ですが、まぁコレぐらいなら楽かな。これで抜け漏れなくなるかなぁと思います。

まぁ、ただこれどこの文言?みたいになりそうですがね!

"ここをしっかり書いておく" = "文言"

のここをしっかり書いておくを頑張ればなんとかなるのではないでしょうか?

というか、他に方法ないのかなぁ。。。と思ったり。

require "csv"
require "nkf"

# please set defaults language folder
localizedFolderName = "ja.lproj"
s = ""
File::open(localizedFolderName + "/Localizable.strings" ,"rb:UTF-16LE") do |f|
	s = f.read
end
s = s.encode("UTF-8")
CSV.open("localizable.txt","w") do |csv|
	csv << ["key","ja","en","for system",'=""""&$A1&""""&"="&""""&B1&""";"']
	keyAry = []
	s.each_line do |line|
		if /^"/ =~ line
			lineAry = line.split(/\"/)
			splitFlag = 0
			keysStr = ""
			wordsStr= ""
			lineAry.each do |word|
				if splitFlag == 0 
					if /=/ =~ word
						splitFlag = 1
					else
						keysStr += word
					end
				else
					if /;/ =~ word
						break
					end
					wordsStr += word
				end
			end
			cell = []
			cell << keysStr
			cell << wordsStr
			csv << cell
		end 
	end
end	
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?