-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
…t all The instructions in the script are all based on my folder config, but with a little tweaking will work for anyone. However, we should only need to do this one time as the iOS strings aren't changing. All new strings have been manually added at the end of the XML files after the iOS ones. Note that all strings within the XML are now surrounded by double quotes. This removes the need to escape the apostrophes which appear in many strings.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/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 | ||
|
||
# Here's how we use it in Soundscape to convert from iOS. | ||
# | ||
# 1. Clone the soundscape repo | ||
# git clone https://github.com/soundscape-community/soundscape.git | ||
# | ||
# 2. Change to the localization directory: | ||
# cd ~/STA/Soundscape-iOS/apps/ios/GuideDogs/Assets/Localization | ||
# | ||
# 2a. Convert to UTF-8 from UTF-16LE | ||
# find -name Localizable.strings -print0 | xargs -0 -n1 -i sh -c 'iconv -f UTF-16LE -t UTF-8 {} -o {}.utf8' | ||
# | ||
# 3. Run the conversion script: | ||
# find -name Localizable.strings.utf8 -print0 | xargs -0 -n1 ~/STA/Soundscape-AndroidTest/app/src/main/res/convertIOStoAndroid.rb {} | ||
# | ||
# 3a. Tidy up empty files: | ||
# rm en-US.lproj/Localizable.strings.utf8.xml | ||
# | ||
# 4. We now have the files in Android format e.g. da-DK.lproj/Localizable.strings.xml | ||
# | ||
# 5. Now copy them into place: | ||
# mkdir -p ~/STA/Soundscape-AndroidTest/app/src/main/res/values-en | ||
# find -name Localizable.strings.utf8.xml -print0 | xargs -0 -n1 -i sh -c 'lang=`echo $"{}" | cut -c4-5`; mv "{}" ~/STA/Soundscape-AndroidTest/app/src/main/res/values-$lang/strings.xml' | ||
# mv ~/STA/Soundscape-AndroidTest/app/src/main/res/values-en/strings.xml ~/STA/Soundscape-AndroidTest/app/src/main/res/values/strings.xml | ||
# rm -fr ~/STA/Soundscape-AndroidTest/app/src/main/res/values-en | ||
# | ||
# Note that this script was amended to strip out comments (they were all empty in the iOS files), | ||
# and remove blank lines. | ||
|
||
printf "Opening input %s\n", ARGV[1] | ||
|
||
input_file = File.open(ARGV[1], "r"); | ||
output_file = File.open(ARGV[1] + ".xml", "w"); | ||
|
||
output_file.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>" | ||
output_file.puts "<resources>" | ||
|
||
multiple_line_comment = false | ||
|
||
input_file.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") | ||
"%#{match}" | ||
} | ||
|
||
output_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 =~ /\/\*(.*)\*\//) | ||
# multiple line comment (start) | ||
elsif (line =~ /\/\*(.*)/) | ||
multiple_line_comment = true | ||
# multiple line comment (middle or end) | ||
elsif (multiple_line_comment) | ||
#end of the multiple line comment | ||
if (line =~ /(.*)\*\//) | ||
multiple_line_comment = false | ||
end | ||
end | ||
end | ||
|
||
output_file.puts "</resources>" | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.