From 3e17922372d86c8c236e6b0437a39bbc78f11a6e Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Tue, 27 Feb 2018 16:50:42 +0700 Subject: [PATCH 01/10] Implemented csv2yaml convertor --- babelish.gemspec | 7 ++++--- lib/babelish.rb | 1 + lib/babelish/csv2yaml.rb | 34 ++++++++++++++++++++++++++++++++++ lib/babelish/version.rb | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 lib/babelish/csv2yaml.rb diff --git a/babelish.gemspec b/babelish.gemspec index 8872072..5519096 100644 --- a/babelish.gemspec +++ b/babelish.gemspec @@ -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' diff --git a/lib/babelish.rb b/lib/babelish.rb index 290bc14..3009d49 100644 --- a/lib/babelish.rb +++ b/lib/babelish.rb @@ -14,6 +14,7 @@ def to_utf8 require "babelish/csv2android" require "babelish/csv2php" require "babelish/csv2json" +require "babelish/csv2yaml" # To CSV require "babelish/base2csv" diff --git a/lib/babelish/csv2yaml.rb b/lib/babelish/csv2yaml.rb new file mode 100644 index 0000000..277e81a --- /dev/null +++ b/lib/babelish/csv2yaml.rb @@ -0,0 +1,34 @@ +module Babelish + class CSV2YAML < Csv2Base + attr_accessor :is_first_row + + def initialize(filename, langs, args = {}) + super(filename, langs, args) + @is_first_row = true + end + + def language_filepaths(language) + require 'pathname' + filename = @output_basename || language.code + filepath = Pathname.new("#{@output_dir}/#{filename}.#{extension}") + @language = language + return filepath ? [filepath] : [] + end + + def get_row_format(row_key, row_value, comment = nil, indentation = 0) + entry = "" + if @is_first_row + entry += "#{@language.code}:\n" + @is_first_row = false + end + indent = ' ' + entry += comment.to_s.empty? ? "" : "#{indent}# #{comment}\n" + entry += "#{indent}#{row_key}: \"#{row_value}\"\n" + end + + def extension + "yaml" + end + end +end + diff --git a/lib/babelish/version.rb b/lib/babelish/version.rb index acb41f4..3de9eae 100644 --- a/lib/babelish/version.rb +++ b/lib/babelish/version.rb @@ -1,3 +1,3 @@ module Babelish - VERSION = "0.5.4" + VERSION = "0.6.0" end From c459f2c28b7ac90ef8c660d355936a8daa7f30f1 Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Sat, 24 Mar 2018 11:49:20 +0700 Subject: [PATCH 02/10] Fixed comments from houndci-bot. Checked by `rubocop lib/babelish/csv2yaml.rb` --- lib/babelish/csv2yaml.rb | 14 +++++++------- lib/babelish/version.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/babelish/csv2yaml.rb b/lib/babelish/csv2yaml.rb index 277e81a..cc78fb1 100644 --- a/lib/babelish/csv2yaml.rb +++ b/lib/babelish/csv2yaml.rb @@ -1,4 +1,5 @@ module Babelish + # Converter from csv format to Rails like yaml format class CSV2YAML < Csv2Base attr_accessor :is_first_row @@ -12,23 +13,22 @@ def language_filepaths(language) filename = @output_basename || language.code filepath = Pathname.new("#{@output_dir}/#{filename}.#{extension}") @language = language - return filepath ? [filepath] : [] + filepath ? [filepath] : [] end - def get_row_format(row_key, row_value, comment = nil, indentation = 0) - entry = "" + def get_row_format(row_key, row_value, comment = nil, _indentation = 0) + entry = '' if @is_first_row entry += "#{@language.code}:\n" @is_first_row = false end indent = ' ' - entry += comment.to_s.empty? ? "" : "#{indent}# #{comment}\n" - entry += "#{indent}#{row_key}: \"#{row_value}\"\n" + entry << "#{indent}# #{comment}\n" unless comment.to_s.empty? + entry << "#{indent}#{row_key}: \"#{row_value}\"\n" end def extension - "yaml" + 'yaml' end end end - diff --git a/lib/babelish/version.rb b/lib/babelish/version.rb index 3de9eae..197c896 100644 --- a/lib/babelish/version.rb +++ b/lib/babelish/version.rb @@ -1,3 +1,3 @@ module Babelish - VERSION = "0.6.0" + VERSION = "0.6.0".freeze end From f17032f9baee966318c0d07125b29b1ef35c82be Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Mon, 26 Mar 2018 17:05:14 +0700 Subject: [PATCH 03/10] [csv2yaml] Added prefix and changed filename for yaml files --- lib/babelish/csv2yaml.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/babelish/csv2yaml.rb b/lib/babelish/csv2yaml.rb index cc78fb1..e15e2a5 100644 --- a/lib/babelish/csv2yaml.rb +++ b/lib/babelish/csv2yaml.rb @@ -2,33 +2,41 @@ module Babelish # 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' filename = @output_basename || language.code - filepath = Pathname.new("#{@output_dir}/#{filename}.#{extension}") + filepath = Pathname.new("#{@output_dir}/#{filename}.#{language.code}.#{extension}") @language = language filepath ? [filepath] : [] end - def get_row_format(row_key, row_value, comment = nil, _indentation = 0) + def get_row_format(row_key, row_value, comment = nil, indentation = 0) entry = '' + indent = ' ' if @is_first_row - entry += "#{@language.code}:\n" + entry << "#{@language.code}:\n" + @deep = 1 + unless @output_basename.empty? + entry << "#{indent}#{@output_basename}:\n" + @deep = 2 + end @is_first_row = false end - indent = ' ' - entry << "#{indent}# #{comment}\n" unless comment.to_s.empty? - entry << "#{indent}#{row_key}: \"#{row_value}\"\n" + entry << "#{indent*@deep}# #{comment}\n" unless comment.to_s.empty? + entry << "#{indent*@deep}#{row_key}: \"#{row_value}\"\n" end def extension 'yaml' end + end end From c36acd074dbf6b078b92be4ae2901667a0d84746 Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Mon, 26 Mar 2018 17:20:56 +0700 Subject: [PATCH 04/10] [csv2android] Added prefix for android files --- lib/babelish/csv2android.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/babelish/csv2android.rb b/lib/babelish/csv2android.rb index 76f2239..a0a2459 100644 --- a/lib/babelish/csv2android.rb +++ b/lib/babelish/csv2android.rb @@ -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\n" + row_key = "#{@output_basename}_#{row_key}" unless @output_basename.empty? entry + "\t#{row_value}\n" end From 8828bea21a28e8e48bff05a27f1cd1844a35fb3a Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Tue, 27 Mar 2018 17:02:02 +0700 Subject: [PATCH 05/10] [csv2strings] Added convertor for all keys from underscore case to camel case [csv2strings] Added convertor for filename from underscore case to camel case --- lib/babelish/csv2base.rb | 7 ++++++- lib/babelish/csv2strings.rb | 18 ++++++++++++++++-- lib/babelish/strings2csv.rb | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/babelish/csv2base.rb b/lib/babelish/csv2base.rb index 35df277..6d7c43d 100644 --- a/lib/babelish/csv2base.rb +++ b/lib/babelish/csv2base.rb @@ -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 diff --git a/lib/babelish/csv2strings.rb b/lib/babelish/csv2strings.rb index e87b838..b5aebb1 100644 --- a/lib/babelish/csv2strings.rb +++ b/lib/babelish/csv2strings.rb @@ -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}" 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}" end end filepaths @@ -20,6 +21,10 @@ 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 @@ -27,5 +32,14 @@ def extension def output_basename @output_basename || 'Localizable' end + + def row_to_camel_case underscope_text + enumerator = underscope_text.split('_').each_with_index + enumerator.map{|word, index| index == 0 ? word : word.capitalize}.join + end + + def filename_to_camel_case underscope_text + underscope_text.split('_').map{|word| word.capitalize}.join + end end end diff --git a/lib/babelish/strings2csv.rb b/lib/babelish/strings2csv.rb index 5e783fa..26cd941 100644 --- a/lib/babelish/strings2csv.rb +++ b/lib/babelish/strings2csv.rb @@ -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") From 7690d9a88d82a3a303ecc626e30c172ad30c407d Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Fri, 6 Apr 2018 11:57:25 +0700 Subject: [PATCH 06/10] [csv2strings] Added convert from %s to %@ --- lib/babelish/csv2base.rb | 9 +++++++-- lib/babelish/csv2strings.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/babelish/csv2base.rb b/lib/babelish/csv2base.rb index 6d7c43d..7b3c060 100644 --- a/lib/babelish/csv2base.rb +++ b/lib/babelish/csv2base.rb @@ -180,14 +180,19 @@ def hash_to_output(content = {}) content.each do |key, value| comment = @comments[key] key_out = key_to_output(key) - output += get_row_format(key_out, value, comment, indentation - key_out.length) + value_out = value_to_output(value) + output += get_row_format(key_out, value_out, comment, indentation - key_out.length) end end return output end - def key_to_output key + def key_to_output(key) key end + + def value_to_output(value) + value + end end end diff --git a/lib/babelish/csv2strings.rb b/lib/babelish/csv2strings.rb index b5aebb1..b899132 100644 --- a/lib/babelish/csv2strings.rb +++ b/lib/babelish/csv2strings.rb @@ -21,10 +21,14 @@ 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 + def key_to_output(key) row_to_camel_case(key) end + def value_to_output(value) + value.gsub "%s", "%@" + end + def extension "strings" end @@ -33,12 +37,12 @@ def output_basename @output_basename || 'Localizable' end - def row_to_camel_case underscope_text + def row_to_camel_case(underscope_text) enumerator = underscope_text.split('_').each_with_index enumerator.map{|word, index| index == 0 ? word : word.capitalize}.join end - def filename_to_camel_case underscope_text + def filename_to_camel_case(underscope_text) underscope_text.split('_').map{|word| word.capitalize}.join end end From 1f5baa5910a9eb8334d8c8049da823790130af91 Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Fri, 6 Apr 2018 12:22:23 +0700 Subject: [PATCH 07/10] Added rubocop --- .rubocop.yml | 1 + .rubocop_todo.yml | 582 +++++++++++++++++++++++++++++++++++++++ Gemfile | 5 +- Rakefile | 6 +- babelish.gemspec | 32 +-- lib/babelish/csv2yaml.rb | 10 +- lib/babelish/version.rb | 2 +- 7 files changed, 611 insertions(+), 27 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..700d275 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,582 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2018-04-06 12:20:10 +0700 using RuboCop version 0.54.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_parameter, with_fixed_indentation +Layout/AlignParameters: + Exclude: + - 'test/babelish/test_csv2json.rb' + - 'test/babelish/test_csv2php.rb' + - 'test/babelish/test_csv2strings.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. +# SupportedStylesAlignWith: start_of_line, def +Layout/DefEndAlignment: + Exclude: + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'test/babelish/test_commandline.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'lib/babelish/commandline.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_commandline.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 27 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'test/babelish/commands/test_command_csv2strings.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/IndentHash: + Exclude: + - 'test/babelish/commands/test_command_csv2android.rb' + - 'test/babelish/commands/test_command_csv2strings.rb' + - 'test/babelish/test_base2csv.rb' + - 'test/babelish/test_csv2base.rb' + - 'test/babelish/test_json2csv.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'lib/babelish/xcode_macros.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_csv2strings.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: normal, rails +Layout/IndentationConsistency: + Exclude: + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'test/test_helper.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'test/babelish/commands/test_command_android2csv.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'test/babelish/test_csv2base.rb' + - 'test/babelish/test_json2csv.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'test/babelish/test_android2csv.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceAroundOperators: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/xcode_macros.rb' + - 'test/babelish/test_strings2csv.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/babelish/csv2strings.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/babelish/csv2strings.rb' + +# Offense count: 118 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +Layout/Tab: + Exclude: + - 'test/babelish/commands/test_command_csv2android.rb' + - 'test/babelish/commands/test_command_csv2strings.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +Layout/TrailingWhitespace: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/csv2strings.rb' + - 'lib/babelish/strings2csv.rb' + - 'lib/babelish/xcode_macros.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 1 +Lint/NonLocalExitFromIterator: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Exclude: + - 'lib/babelish/commandline.rb' + - 'lib/babelish/xcode_macros.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'lib/babelish/base2csv.rb' + - 'lib/babelish/csv2android.rb' + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/csv2php.rb' + +# Offense count: 1 +# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. +Lint/UselessAccessModifier: + Exclude: + - 'lib/babelish/base2csv.rb' + +# Offense count: 10 +Lint/UselessAssignment: + Exclude: + - 'lib/babelish/json2csv.rb' + - 'test/babelish/test_android2csv.rb' + - 'test/babelish/test_csv2strings.rb' + - 'test/babelish/test_json2csv.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 11 +Metrics/AbcSize: + Max: 54 + +# Offense count: 3 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 50 + +# Offense count: 4 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 161 + +# Offense count: 3 +Metrics/CyclomaticComplexity: + Max: 18 + +# Offense count: 38 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 36 + +# Offense count: 3 +Metrics/PerceivedComplexity: + Max: 21 + +# Offense count: 25 +# Configuration parameters: Blacklist. +# Blacklist: END, (?-mix:EO[A-Z]{1}) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/babelish/xcode_macros.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_csv2strings.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + - 'test/babelish/test_xcode_macros.rb' + +# Offense count: 5 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/CompareWithBlock: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'lib/babelish/strings2csv.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/StringReplacement: + Exclude: + - 'lib/babelish/xcode_macros.rb' + +# Offense count: 2 +Security/Eval: + Exclude: + - 'lib/babelish/commandline.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/xcode_macros.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: + Exclude: + - 'lib/babelish/strings2csv.rb' + - 'test/babelish/test_base2csv.rb' + - 'test/babelish/test_csv2android.rb' + - 'test/babelish/test_csv2base.rb' + - 'test/babelish/test_csv2strings.rb' + - 'test/babelish/test_json2csv.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Style/CharacterLiteral: + Exclude: + - 'lib/babelish/php2csv.rb' + - 'lib/babelish/strings2csv.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: Keywords. +# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW +Style/CommentAnnotation: + Exclude: + - 'test/babelish/commands/test_command_android2csv.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + +# Offense count: 18 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/babelish/android2csv.rb' + - 'lib/babelish/base2csv.rb' + - 'lib/babelish/commandline.rb' + - 'lib/babelish/csv2android.rb' + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/csv2json.rb' + - 'lib/babelish/csv2php.rb' + - 'lib/babelish/csv2strings.rb' + - 'lib/babelish/google_doc.rb' + - 'lib/babelish/json2csv.rb' + - 'lib/babelish/language.rb' + - 'lib/babelish/php2csv.rb' + - 'lib/babelish/strings2csv.rb' + - 'lib/babelish/xcode_macros.rb' + +# Offense count: 2 +Style/EvalWithLocation: + Exclude: + - 'lib/babelish/commandline.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'bin/babelish' + - 'lib/babelish/commandline.rb' + +# Offense count: 5 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/babelish/base2csv.rb' + - 'lib/babelish/commandline.rb' + - 'lib/babelish/php2csv.rb' + - 'lib/babelish/strings2csv.rb' + +# Offense count: 202 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Enabled: false + +# Offense count: 1 +Style/IfInsideElse: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/babelish/android2csv.rb' + - 'lib/babelish/commandline.rb' + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/google_doc.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/babelish/commandline.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/NilComparison: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/csv2strings.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'lib/babelish/google_doc.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'test/babelish/commands/test_command_android2csv.rb' + - 'test/babelish/commands/test_command_csv2strings.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_android2csv.rb' + - 'test/babelish/test_base2csv.rb' + - 'test/babelish/test_json2csv.rb' + - 'test/babelish/test_php2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: compact, exploded +Style/RaiseArgs: + EnforcedStyle: compact + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/babelish/base2csv.rb' + - 'lib/babelish/csv2android.rb' + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/csv2json.rb' + - 'lib/babelish/csv2php.rb' + - 'lib/babelish/google_doc.rb' + - 'lib/babelish/json2csv.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/babelish/csv2base.rb' + - 'lib/babelish/strings2csv.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'lib/babelish/strings2csv.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + Exclude: + - 'bin/babelish' + - 'test/babelish/test_bins.rb' + +# Offense count: 592 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'lib/babelish/csv2strings.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/babelish/base2csv.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'lib/babelish/commandline.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'test/babelish/commands/test_command_csv2strings.rb' + - 'test/babelish/test_commandline.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. +# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym +Style/TrivialAccessors: + Exclude: + - 'lib/babelish/csv2base.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/UnneededInterpolation: + Exclude: + - 'lib/babelish/commandline.rb' + - 'lib/babelish/csv2php.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinSize, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + Exclude: + - 'test/babelish/commands/test_command_android2csv.rb' + - 'test/babelish/commands/test_command_strings2csv.rb' + - 'test/babelish/test_base2csv.rb' + - 'test/babelish/test_strings2csv.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'lib/babelish/csv2android.rb' + - 'lib/babelish/csv2base.rb' + +# Offense count: 101 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 166 diff --git a/Gemfile b/Gemfile index ecbb687..8647120 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,9 @@ -source "http://rubygems.org" +source 'http://rubygems.org' # Specify your gem's dependencies in teachmehowtomakearubygem.gemspec gemspec group :test do - gem 'coveralls', :require => false, :platforms => [:ruby_19, :ruby_20] + gem 'coveralls', require: false, platforms: %i[ruby_19 ruby_20] + gem 'rubocop' end diff --git a/Rakefile b/Rakefile index 90b1e85..f901eae 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,9 @@ -require "bundler/gem_tasks" +require 'bundler/gem_tasks' require 'rake/testtask' require 'yard' Rake::TestTask.new do |t| - t.libs << "test" + t.libs << 'test' t.test_files = FileList['test/babelish/**/test_*.rb'] # t.warning = true t.verbose = true @@ -14,4 +14,4 @@ YARD::Rake::YardocTask.new do |t| # t.options = ['--any', '--extra', '--opts'] end -task :default => :test +task default: :test diff --git a/babelish.gemspec b/babelish.gemspec index 5519096..5f8c407 100644 --- a/babelish.gemspec +++ b/babelish.gemspec @@ -1,43 +1,43 @@ -# -*- encoding: utf-8 -*- -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'babelish/version' Gem::Specification.new do |s| s.name = 'babelish' s.version = Babelish::VERSION - s.date = Time.now.strftime("%Y-%m-%d") - s.summary = "CSV converter for localization files" + s.date = Time.now.strftime('%Y-%m-%d') + s.summary = 'CSV converter for localization files' s.description = "This set of commands converts a CSV file to the following formats: - .strings (iOS) - .xml (Android) - .json - .php - .yaml (Rails)" - s.authors = ["François Benaiteau", "Markus Paeschke", "Nikolay Moskvin"] + 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' - s.add_dependency "thor" + s.add_dependency 'thor' - s.add_dependency "google_drive", "~> 2.1.7" - s.add_dependency "nokogiri" + s.add_dependency 'google_drive', '~> 2.1.7' + s.add_dependency 'nokogiri' # google_drive dependency to ask for mail and password - s.add_dependency "highline" + s.add_dependency 'highline' # specify version of rack so works on ruby <2.2.2 - s.add_dependency "rack", "1.6.4" + s.add_dependency 'rack', '1.6.4' # json support - s.add_dependency "json" + s.add_dependency 'json' - s.add_development_dependency "rake" - s.add_development_dependency "test-unit" - s.add_development_dependency "simplecov" - s.add_development_dependency "yard" + s.add_development_dependency 'rake' + s.add_development_dependency 'simplecov' + s.add_development_dependency 'test-unit' + s.add_development_dependency 'yard' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_path = 'lib' end diff --git a/lib/babelish/csv2yaml.rb b/lib/babelish/csv2yaml.rb index e15e2a5..b02b03e 100644 --- a/lib/babelish/csv2yaml.rb +++ b/lib/babelish/csv2yaml.rb @@ -13,12 +13,13 @@ def initialize(filename, langs, args = {}) def language_filepaths(language) require 'pathname' filename = @output_basename || language.code - filepath = Pathname.new("#{@output_dir}/#{filename}.#{language.code}.#{extension}") + path = "#{@output_dir}/#{filename}.#{language.code}.#{extension}" + filepath = Pathname.new(path) @language = language filepath ? [filepath] : [] end - def get_row_format(row_key, row_value, comment = nil, indentation = 0) + def get_row_format(row_key, row_value, comment = nil, _indentation = 0) entry = '' indent = ' ' if @is_first_row @@ -30,13 +31,12 @@ def get_row_format(row_key, row_value, comment = nil, indentation = 0) end @is_first_row = false end - entry << "#{indent*@deep}# #{comment}\n" unless comment.to_s.empty? - entry << "#{indent*@deep}#{row_key}: \"#{row_value}\"\n" + entry << "#{indent * @deep}# #{comment}\n" unless comment.to_s.empty? + entry << "#{indent * @deep}#{row_key}: \"#{row_value}\"\n" end def extension 'yaml' end - end end diff --git a/lib/babelish/version.rb b/lib/babelish/version.rb index 197c896..fcfd382 100644 --- a/lib/babelish/version.rb +++ b/lib/babelish/version.rb @@ -1,3 +1,3 @@ module Babelish - VERSION = "0.6.0".freeze + VERSION = '0.6.0'.freeze end From 1332d23c741f5f458506871af6e894f62e1dc34c Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Sat, 7 Apr 2018 14:12:01 +0700 Subject: [PATCH 08/10] [csv2yaml] Changed extension name to yml --- lib/babelish/csv2yaml.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/babelish/csv2yaml.rb b/lib/babelish/csv2yaml.rb index b02b03e..8417149 100644 --- a/lib/babelish/csv2yaml.rb +++ b/lib/babelish/csv2yaml.rb @@ -36,7 +36,7 @@ def get_row_format(row_key, row_value, comment = nil, _indentation = 0) end def extension - 'yaml' + 'yml' end end end From fc7514807fe067f8cc4af0ad587cac5ee6fad888 Mon Sep 17 00:00:00 2001 From: Nikolay Moskvin Date: Wed, 11 Apr 2018 18:28:18 +0700 Subject: [PATCH 09/10] [csv2json] Added language code to name of file --- lib/babelish/csv2json.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/babelish/csv2json.rb b/lib/babelish/csv2json.rb index 4f10130..37e4d1a 100644 --- a/lib/babelish/csv2json.rb +++ b/lib/babelish/csv2json.rb @@ -5,7 +5,7 @@ class CSV2JSON < Csv2Base def language_filepaths(language) require 'pathname' filename = @output_basename || language.code - filepath = Pathname.new("#{@output_dir}#{filename}.#{extension}") + filepath = Pathname.new("#{@output_dir}/#{filename}.#{language.code}.#{extension}") return filepath ? [filepath] : [] end From 0f77221e8b2ec51375d4c9aff72ed924260e9be9 Mon Sep 17 00:00:00 2001 From: stolyarov Date: Fri, 20 Aug 2021 14:26:29 +0700 Subject: [PATCH 10/10] [gems] updated gems --- babelish.gemspec | 2 +- lib/babelish/commandline.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/babelish.gemspec b/babelish.gemspec index 5f8c407..b2c80e2 100644 --- a/babelish.gemspec +++ b/babelish.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'thor' - s.add_dependency 'google_drive', '~> 2.1.7' + s.add_dependency 'google_drive', '~> 3.0.7' s.add_dependency 'nokogiri' # google_drive dependency to ask for mail and password s.add_dependency 'highline' diff --git a/lib/babelish/commandline.rb b/lib/babelish/commandline.rb index 29ce582..e6d35ab 100644 --- a/lib/babelish/commandline.rb +++ b/lib/babelish/commandline.rb @@ -177,8 +177,6 @@ def self.exit_on_failure? true end - private - def options original_options = super return original_options unless File.exist?(original_options["config"])