-
Notifications
You must be signed in to change notification settings - Fork 84
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
Implemented having comments in CSV #99
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,40 @@ def initialize(args = {:filenames => []}) | |
super(args) | ||
end | ||
|
||
def parse_comment_line(line) | ||
line.strip! | ||
if line[0] != ?# && line[0] != ?= | ||
m = line.match(/^\/\*(.*)\*\/\s*$/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use %r around regular expression. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @netbe This function I copied from strings2csv.rb, so unsure if I should still change this according to houndci-bot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Dchau95 yes please make any change @houndci-bot mention and add tests to check comments on android |
||
return m[1].strip! unless m.nil? | ||
end | ||
end | ||
|
||
def load_strings(strings_filename) | ||
strings = {} | ||
comments = {} | ||
xml_file = File.open(strings_filename) | ||
|
||
parser = Nokogiri::XML(xml_file) do |config| | ||
config.strict.noent | ||
end | ||
parser.xpath("//string").each do |node| | ||
|
||
previous_comment = nil | ||
parser.xpath("//resources").children.each do |node| | ||
if !node.nil? && !node["name"].nil? | ||
strings.merge!(node["name"] => node.inner_html) | ||
comments[node["name"]] = previous_comment if previous_comment | ||
previous_comment = nil | ||
end | ||
if node.comment? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use next to skip iteration. |
||
comment = node.content | ||
parsed_comment = parse_comment_line(comment) | ||
previous_comment = parsed_comment || comment | ||
end | ||
end | ||
|
||
xml_file.close | ||
|
||
[strings, {}] | ||
[strings, comments] | ||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- This is the app name --> | ||
<string name="app_name">android2csv</string> | ||
<!-- This is a greeting --> | ||
<string name="action_greetings">Hello</string> | ||
<!-- This is another string --> | ||
<string name="ANOTHER_STRING">testEN</string> | ||
<!-- This is an empty string --> | ||
<string name="empty"></string> | ||
|
||
</resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use the character literal - use string literal instead.