Permalink
Browse files

Added merge

  • Loading branch information...
1 parent 5adf6ad commit 18f86258cc693a4d1dd842bdde702e6c332fa668 @PokerChang committed Sep 22, 2011
Showing with 33 additions and 6 deletions.
  1. +8 −2 README.md
  2. +25 −4 convert.rb
View
10 README.md
@@ -1,5 +1,11 @@
-<h1>Convert an Android strings.xml into Ruby on Rails i18n yml file</h1>
+<h1>Merge an Android strings.xml into Ruby on Rails i18n yml file</h1>
<h1>Usage</h1>
ruby convert.rb android_strings_xml_path rails_yml_path
+<h1>Desscription</h1>
+This simple ruby script will merge Android strings file into Ruby on Rails i18n yml file. The result is sorted alphabetically. It's safe to rerun. Current only English is tested but it can be easily convert to other languages.
+
<h1>TODO</h1>
-Automatically enumerate all possible android locales and create according locales for Rails
+<ol>
+<li>Merge both ways</li>
+<li>Automatically enumerate all possible android locales and create according locales for Rails</li>
+</ol>
View
29 convert.rb
@@ -5,18 +5,39 @@
puts banner
exit
end
-file = File.open(ARGV[1], "a")
+file = File.open(ARGV[1], "r")
xml = File.read(ARGV[0])
doc= REXML::Document.new(xml)
# order alphabetically
result = []
doc.elements.each('/resources/string') do |p|
- result << (' ' + p.attributes['name']+': "'+ p.text + '"')
+ result << (' ' + p.attributes['name']+': "'+ p.text.gsub(/\n/,' ').squeeze(' ') + '"')
+end
+result = result
+
+
+
+output = []
+header = []
+while (line = file.gets)
+ if line.start_with? ' '
+ output << line.chop
+ else
+ header << line.chop
+ end
+end
+
+result = (output | result).sort{|a, b| a.downcase <=> b.downcase}
+
+routput = File.open(ARGV[1], "w")
+header.each do |r|
+ routput.puts r
+ #puts r
end
-result = result.sort{|a, b| a.downcase <=> b.downcase}
result.each do |r|
- file.puts r
+ routput.puts r
+ #puts r
end

0 comments on commit 18f8625

Please sign in to comment.