Created
September 15, 2012 06:12
-
-
Save douo/3726548 to your computer and use it in GitHub Desktop.
将android layout 的xml 文件中的 raw string 转换到 strings.xml 的ruby 脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#usage: ruby test.rb layout/ | |
$counter =1 | |
$strs=[] | |
def gen(ctn) | |
reg = /android:text="([^@?]*?)"/ | |
while res = ctn.match(reg) | |
id = "autogen_text_#{$counter}" | |
$counter=$counter+1 | |
ctn.sub!(reg,"android:text=\"@string/#{id}\"") | |
$strs << "<string name=\"#{id}\">#{res[1]}</string>" | |
end | |
return ctn | |
end | |
def wToString() | |
puts $strs | |
end | |
path =ARGV[0] || '.' | |
reg = /.*xml/i | |
Dir.foreach(path).select {|fn| fn =~ reg}.each do |fn| | |
result ="" | |
File.open(File.join(path,fn),'r:UTF-8') do |f| | |
result =gen f.read | |
f.close | |
end | |
File.open(File.join(path,fn),'w:UTF-8') do |f| | |
f.write result | |
f.close | |
end | |
end | |
wToString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment