source: res/RcTextExt.rb @ 205

Revision 205, 1.6 KB checked in by Eoin, 13 years ago (diff)
Line 
1# This ruby script ...
2
3if ARGV.size == 0 
4        puts "usage RcTextExt resource_file languages" 
5        exit
6end
7
8resource_file_name = ARGV.shift
9resource_array = Array.new
10resource_file = File.open(resource_file_name).gets(nil)
11
12puts "Working with "+resource_file_name
13
14# First we strip comments and lines starting with '#' so they don't confuse the map
15resource_file.gsub!(/\/\/.*/, '')
16resource_file.gsub!(/#.*/, '')
17resource_file.gsub!(Regexp.new('\/\*.*?\*\/', Regexp::MULTILINE), '')
18
19# Collect all string in the resource file
20resource_file.scan(/\".*?\"/) do |text_string|
21        if not resource_array.include?(text_string)
22                resource_array.push(text_string)
23        end
24end
25
26ARGV.each do |arg| 
27        # Parse any translated strings already present.
28       
29        lang_file_name = "../lang/"+arg+'.txt'
30        puts "Processing "+lang_file_name
31       
32        lang_file = File.open(lang_file_name, File::CREAT).gets(nil)
33        lang_map = Hash.new
34       
35        if lang_file
36                lang_file.scan(/(\".*?\")\s*--->\s*(\".*?\")/) {|original, trans| lang_map[original] = trans}
37        end
38       
39        resource_lang_file = File.open(resource_file_name).gets(nil)
40       
41    resource_lang_file.gsub!(/\".*?\"/) do |text_string|
42        if lang_map.has_key?(text_string)
43            lang_map[text_string]
44        else
45            text_string
46        end
47    end
48
49    File.new(arg+'.rc', "w").print(resource_lang_file)
50       
51        lang_file = File.new(lang_file_name, File::CREAT|File::TRUNC|File::RDWR)
52       
53        resource_array.each do |value| 
54                if lang_map.has_key?(value)
55            lang_file.print(value + " ---> " + lang_map[value] + "\n")
56        else
57            lang_file.print(value + " --->  ??? \n")
58        end
59        end     
60end
Note: See TracBrowser for help on using the repository browser.