-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathLang
More file actions
executable file
·72 lines (62 loc) · 1.69 KB
/
Copy pathLang
File metadata and controls
executable file
·72 lines (62 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby
# Author:: Dirk Meyer
# Copyright:: Copyright (c) 2025 - 2025 Dirk Meyer
# License:: Distributes under the same terms as Ruby
# SPDX-FileCopyrightText: 2025-2025 Dirk Meyer
# SPDX-License-Identifier: Ruby
require 'fileutils'
def read_lang( filename )
list = File.read( filename ).split( "\n" ).map { |e| e.split( ' ', 2 ) }
list.each_with_object({}) { |(key, value), h| h[key] = value.gsub( '\\', '\\\\' ) }
end
def make_subs( lang )
@en = read_lang( 'en.txt' )
@translated = read_lang( "#{lang}.txt" )
@subs = []
@en.each_pair do |nr, text|
next if text == @translated[ nr ]
@subs.push( [ text, @translated[ nr ] ] )
end
end
def write_changed( filename, text )
if File.exist?( filename )
old = File.read( filename )
return if old == text
end
puts "Saving: #{filename}"
File.write( filename, text )
end
def translate_file( file, dest )
text = File.read( file ).split( "\n" )
text.map! do |line|
unless line.include?( 'NOTRANSLATE' )
@subs.each do |(pattern, translated)|
line.gsub!( pattern) { translated }
end
end
line
end
text.push( nil )
write_changed( dest, text.join( "\n" ) )
end
def translate_dir( lang )
puts "parsing #{lang}"
make_subs( lang )
@dir = "src.#{lang}"
FileUtils.mkdir_p( @dir )
files = Dir.glob( [ "src/*.h", "src/[bcpsu]*.c" ] )
files.each do |file|
dest = "#{@dir}/#{file.split( '/' ).last}"
FileUtils.cp( file, dest, preserve: true )
end
files = Dir.glob( [ "src/iroffer*.c", "src/dinoex*.c" ] )
files.each do |file|
dest = "#{@dir}/#{file.split( '/' ).last}"
translate_file( file, dest )
end
end
ARGV.each do |arg|
translate_dir( arg )
end
exit 0
# eof