Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apostrophe Issue #130

Open
ExPl0siF opened this issue May 22, 2020 · 1 comment
Open

Apostrophe Issue #130

ExPl0siF opened this issue May 22, 2020 · 1 comment
Labels

Comments

@ExPl0siF
Copy link

First thank you for your project, which is really helpful and time economiser. I have french localization inside my CSV file, and when I just replace the file inside my Android Studio Project it gave me the error: AAPT: error: unescaped apostrophe in string. So after looking, I have to put a backslash before every apostrophe in my translation (') could you please add it at the "compilation/parsing" time ? Only for csv2android :)

Thank you in advance,

@falkorichter
Copy link
Contributor

we have a workaround:

csv2android.rb:

require 'uri'
module Babelish
 class CSV2Android < Csv2Base
 attr_accessor :file_path
 def initialize(filename, langs, args = {})
 super(filename, langs, args)
 @file_path = args[:output_dir].to_s
 end
 def language_filepaths(language)
 require 'pathname'
 filepath = Pathname.new(@file_path) + "values-#{language.code}" + "strings.xml"
 return filepath ? [filepath] : []
 end
 def process_value(row_value, default_value)
 value = super(row_value, default_value)
 value.gsub!(/'/, "'" => "\\'") # escape single quote only for Android
 value.gsub!(/&/, "&" => '&amp;')
 # if the value begins and ends with a quote we must leave them unescaped
 if value.size > 4 && value[0, 2] == "\\\"" && value[value.size - 2, value.size] == "\\\""
 value[0, 2] = "\""
 value[value.size - 2, value.size] = "\""
 end
 value.to_utf8
 end
 def get_row_format(row_key, row_value, comment = nil, indentation = 0)
 entry = comment.to_s.empty? ? "" : "\n\t<!-- #{comment} -->\n"
 entry + "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
 end
 def hash_to_output(content = {})
 output = ''
 if content && content.size > 0
 output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
 output += "<resources>\n"
 content.each do |key, value|
 comment = @comments[key]
 output += get_row_format(key, value, comment)
 end
 output += "</resources>\n"
 end
 return output
 end
 def extension
 "xml"
 end
 end
end

I hope to find some time and prepare a pull request these days...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants