merge_strings 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/merge_strings.rb +53 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 111198e906dc6707a5ffe16ee2429f4b83afb9e1
4
+ data.tar.gz: 66ca41c46093951c89464a51ccb1822f5603a159
5
+ SHA512:
6
+ metadata.gz: 5f0264e72a525d9a65f9d5e069b73063d7e07f36235972f66958a77aab3cd741612c6e5997a95e9c249806e66a1b4a2f355bc1bca9802482151e6de0c145c744
7
+ data.tar.gz: 3421d6eee7e477ac9f3898637f8d71f17fde8eff3b4480b6eb99c469eca3b6551fa16a3d812f2d4d79d0c37c588678949e0a5794a60e6dd3c0f58f3dd3d30b22
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # extract_comments("/* abc */ /* 123 */")
4
+ # => ["abc", "123"]
5
+ def extract_comments(str)
6
+ (str || "").scan(%r"/\*\s*(.*?)\s*\*/").flatten
7
+ end
8
+
9
+ # key_value_line("foo", "bar", ["abc", "123"])
10
+ # => '"foo" = "bar"; /* abc */ /* 123 */'
11
+ def key_value_line(key, value, comments)
12
+ line = "\"#{key}\" = \"#{value}\";"
13
+ unless comments.empty?
14
+ line = ([line] + comments.map{|c|"/* #{c} */"}).join(" ")
15
+ end
16
+ line
17
+ end
18
+
19
+ if ARGV.count < 2
20
+ puts <<-USAGE
21
+ Usage: merge_strings BASE.strings OTHER.strings [default:"TRANSLATION REQUIRED"]
22
+
23
+ See https://github.com/hiroshi/merge_strings for more information.
24
+ USAGE
25
+ exit 2
26
+ end
27
+ base_strings_path = ARGV[0]
28
+ other_strings_path = ARGV[1]
29
+ translation_required = ARGV[2] || "TRANSLATION REQUIRED"
30
+ # Extract values of other strings
31
+ other_strings = {} #=> {"key": {val: "...", comments: ["...", "..."]}, ...}
32
+ File.read(other_strings_path).each_line do |line|
33
+ if match = line.match(/"([^"]*)"\s*=\s*"([^"]*)"\s*;(.*)$/)
34
+ key, val, comments = $1, $2, extract_comments($3)
35
+ # puts "#{key} = #{val}"
36
+ other_strings[key] = {val: val, comments: comments}
37
+ end
38
+ end
39
+ # Copy base strings file then replace values with other_strings
40
+ File.open(other_strings_path, "w+") do |other_strings_file|
41
+ File.read(base_strings_path).each_line do |line|
42
+ line.sub!(/"([^"]*)"\s*=\s*"([^"]*)"\s*;(.*)$/) do |m|
43
+ key, val, comments = $1, $2, extract_comments($3)
44
+ #puts "#{key} : #{comments}"
45
+ if other = other_strings[key]
46
+ key_value_line(key, other[:val], comments | other[:comments])
47
+ else
48
+ key_value_line(key, key, comments | [translation_required])
49
+ end
50
+ end
51
+ other_strings_file.puts line
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merge_strings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Saito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A scirpt to help maintaining Localizable.strings.
14
+ email: hiroshi3110@gmail.com
15
+ executables:
16
+ - merge_strings.rb
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/merge_strings.rb
21
+ homepage: https://github.com/hiroshi/merge_strings
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: merge_strings.rb en.lproj/Localizable.strings ja.lproj/Localizable.strings
45
+ test_files: []