Created
August 23, 2012 22:14
-
-
Save florianmski/3442664 to your computer and use it in GitHub Desktop.
Convert your Localizable.strings (iOS) to strings.xml (Android)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# based on https://github.com/tmurakam/cashflow/blob/0a01ac9e0350dfb04979986444244f8daf4cb5a8/android/convertStrings.rb | |
# support comments and Converter such as "%@", "%d", "%0.1f"... | |
# in your directory : ./main.rb Localizable.strings | |
file = File.open("strings.xml", "w"); | |
file.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>" | |
file.puts "<resources>" | |
multiple_line_comment = false | |
ARGF.each do |line| | |
if (line =~ /\"(.*)\"\s*=\s*\"(.*)\"/) | |
name = $1 | |
value = $2 | |
name.gsub!(/[ .]/, "_") | |
value.gsub!(/&/, "&") | |
value.gsub!(/</, "<") | |
i = 0 | |
# convert %@ to %1$s | |
value.gsub!(/%([0-9.]*[@sScCdoxXfeEgabBhH])/) {|s| | |
i += 1 | |
match = $1 | |
match.gsub!(/@/, "s") | |
"%#{i}$#{match}" | |
} | |
file.puts " <string name=\"#{name}\">\"#{value}\"</string>" | |
# one line comment // The cake is a lie | |
# multiple line comment on one line /* The cake is a lie */ | |
elsif (line =~ /\/\/(.*)/ || line =~ /\/\*(.*)\*\//) | |
file.puts "<!--#{$1}-->" | |
# multiple line comment (start) | |
elsif (line =~ /\/\*(.*)/) | |
file.puts "<!--#{$1}" | |
multiple_line_comment = true | |
# multiple line comment (middle or end) | |
elsif (multiple_line_comment) | |
#end of the multiple line comment | |
if (line =~ /(.*)\*\//) | |
file.puts "#{$1}-->" | |
multiple_line_comment = false | |
else | |
file.puts line | |
end | |
elsif (line =~ /\n/) | |
file.puts line | |
end | |
end | |
file.puts "</resources>" |
Thank you for the script! It appears to be correct and functional. This Python script is a helpful tool for developers who are converting from iOS to Android and need to migrate their localization strings. By automating the conversion process, this script saves developers time and reduces the risk of human error. The script is easy to use and well-documented, making it a valuable resource for developers who are new to Android development and may not be familiar with Android-specific syntax.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I want to report and issue:
Input:
"ABOUT..." = "About...";
Output:
As you can see the
.
was converted in_
Bye