今天客户要求把所有的页面和JavaScript中的提示行信息按
模块,中文,英文的格式
全部摘出来写个excel,为了检查英文是否“地道”
我设计的那部分系统的所有字符串资源都统一放在一个文件中,比较好处理
但是同事写代码时,所有字符串都写在出现的地方
手工一个一个来那可费死劲了,还容易遗漏
于是写了一个脚本 extract_alert.rb
require "find"
Find.find('./') do |path|
if not File.directory?path and path[/\.jsp$/] then
found_line = []
File.open("#{Dir.pwd}#{path[1..path.size]}","r").each_with_index do|line,lno|
if line=~/[^\/]alert/ then
found_line<<"#{lno}:\t#{line.strip}"
end
end
if found_line.size!=0 then
puts path
puts found_line
puts "\n"
end
end
end
本来说写一个遍历文件夹的函数,查了下Ruby Cookbook,原来Ruby早就写好了一个Find模块,使用起来很方便
extract_alert.rb>>a.txt
为满足客户检查需求,本文介绍了一种使用Ruby脚本自动从项目文件中批量提取JavaScript警告信息的方法,以便验证英文表述的专业性。
108

被折叠的 条评论
为什么被折叠?



