Skip to content
7 changes: 4 additions & 3 deletions babelish.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Gem::Specification.new do |s|
- .strings (iOS)
- .xml (Android)
- .json
- .php"
s.authors = ["François Benaiteau", "Markus Paeschke"]
s.email = ['francois.benaiteau@gmail.com', 'markus.paeschke@gmail.com']
- .php
- .yaml (Rails)"
s.authors = ["François Benaiteau", "Markus Paeschke", "Nikolay Moskvin"]
s.email = ['francois.benaiteau@gmail.com', 'markus.paeschke@gmail.com', 'nikolay.moskvin@gmail.com']
s.homepage = 'http://netbe.github.io/Babelish/'
s.license = 'MIT'

Expand Down
1 change: 1 addition & 0 deletions lib/babelish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def to_utf8
require "babelish/csv2android"
require "babelish/csv2php"
require "babelish/csv2json"
require "babelish/csv2yaml"

# To CSV
require "babelish/base2csv"
Expand Down
1 change: 1 addition & 0 deletions lib/babelish/csv2android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def process_value(row_value, default_value)

def get_row_format(row_key, row_value, comment = nil, indentation = 0)
entry = comment.to_s.empty? ? "" : "\n\t<!-- #{comment} -->\n"
row_key = "#{@output_basename}_#{row_key}" unless @output_basename.empty?
entry + "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
end

Expand Down
7 changes: 6 additions & 1 deletion lib/babelish/csv2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ def hash_to_output(content = {})
if content && content.size > 0
content.each do |key, value|
comment = @comments[key]
output += get_row_format(key, value, comment, indentation - key.length)
key_out = key_to_output(key)
output += get_row_format(key_out, value, comment, indentation - key_out.length)
end
end
return output
end

def key_to_output key
key
end
end
end
18 changes: 16 additions & 2 deletions lib/babelish/csv2strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class CSV2Strings < Csv2Base
def language_filepaths(language)
require 'pathname'
filepaths = []
basename = filename_to_camel_case(output_basename)
if language.regions.empty?
filepaths << Pathname.new(@output_dir) + "#{language.code}.lproj/#{output_basename}.#{extension}"
filepaths << Pathname.new(@output_dir) + "#{language.code}.lproj/#{basename}.#{extension}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [98/80]

else
language.regions.each do |region|
filepaths << Pathname.new(@output_dir) + "#{language.code}-#{region}.lproj/#{output_basename}.#{extension}"
filepaths << Pathname.new(@output_dir) + "#{language.code}-#{region}.lproj/#{basename}.#{extension}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [110/80]

end
end
filepaths
Expand All @@ -20,12 +21,25 @@ def get_row_format(row_key, row_value, comment = nil, indentation = 0)
entry + "\"#{row_key}\"" + " " * indentation + " = \"#{row_value}\";\n"
end

def key_to_output key
row_to_camel_case(key)
end

def extension
"strings"
end

def output_basename
@output_basename || 'Localizable'
end

def row_to_camel_case underscope_text

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use def with parentheses when there are parameters.

enumerator = underscope_text.split('_').each_with_index

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

enumerator.map{|word, index| index == 0 ? word : word.capitalize}.join

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing to the left of {.
Space between { and | missing.
Use index.zero? instead of index == 0.
Space missing inside }.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing to the left of {.
Space between { and | missing.
Use index.zero? instead of index == 0.
Space missing inside }.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
Style/NumericPredicate: Use index.zero? instead of index == 0.
Layout/SpaceInsideBlockBraces: Space missing inside }.

end

def filename_to_camel_case underscope_text

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use def with parentheses when there are parameters.

underscope_text.split('_').map{|word| word.capitalize}.join

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Space missing to the left of {.
Space between { and | missing.
Pass &:capitalize as an argument to map instead of a block.
Space missing inside }.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
Style/SymbolProc: Pass &:capitalize as an argument to map instead of a block.
Layout/SpaceInsideBlockBraces: Space missing inside }.

end
end
end
42 changes: 42 additions & 0 deletions lib/babelish/csv2yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Babelish

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubocop | grep frozen_string_literal does not have it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

# Converter from csv format to Rails like yaml format
class CSV2YAML < Csv2Base
attr_accessor :is_first_row
attr_accessor :deep

def initialize(filename, langs, args = {})
super(filename, langs, args)
@is_first_row = true
@deep = 1
end

def language_filepaths(language)
require 'pathname'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not agree with the bot

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

filename = @output_basename || language.code
filepath = Pathname.new("#{@output_dir}/#{filename}.#{language.code}.#{extension}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [89/80]

@language = language
filepath ? [filepath] : []
end

def get_row_format(row_key, row_value, comment = nil, indentation = 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method argument - indentation. If it's necessary, use _ or _indentation as an argument name to indicate that it won't be used.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method argument - indentation. If it's necessary, use _ or _indentation as an argument name to indicate that it won't be used.

entry = ''

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not fix it!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

indent = ' '

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

if @is_first_row
entry << "#{@language.code}:\n"
@deep = 1
unless @output_basename.empty?
entry << "#{indent}#{@output_basename}:\n"
@deep = 2
end
@is_first_row = false
end
entry << "#{indent*@deep}# #{comment}\n" unless comment.to_s.empty?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrounding space missing for operator *.

entry << "#{indent*@deep}#{row_key}: \"#{row_value}\"\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrounding space missing for operator *.

end

def extension
'yaml'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not fix it!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

end
end
2 changes: 1 addition & 1 deletion lib/babelish/strings2csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load_strings(strings_filename)
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
contents = ic.iconv(contents + ' ')[0..-2]
end
rescue Encoding::InvalidByteSequenceError => e
rescue Encoding::InvalidByteSequenceError => _e
# silent error
# faults back to utf8
contents = File.open(strings_filename, "r:utf-8")
Expand Down
2 changes: 1 addition & 1 deletion lib/babelish/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Babelish
VERSION = "0.5.4"
VERSION = "0.6.0".freeze
end