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 8872072..b2c80e2 100644 --- a/babelish.gemspec +++ b/babelish.gemspec @@ -1,42 +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" - 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' - 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', '~> 3.0.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.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/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"]) 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 diff --git a/lib/babelish/csv2base.rb b/lib/babelish/csv2base.rb index 35df277..7b3c060 100644 --- a/lib/babelish/csv2base.rb +++ b/lib/babelish/csv2base.rb @@ -179,10 +179,20 @@ 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) + 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) + key + end + + def value_to_output(value) + value + end end end 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 diff --git a/lib/babelish/csv2strings.rb b/lib/babelish/csv2strings.rb index e87b838..b899132 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,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) + row_to_camel_case(key) + end + + def value_to_output(value) + value.gsub "%s", "%@" + end + def extension "strings" end @@ -27,5 +36,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/csv2yaml.rb b/lib/babelish/csv2yaml.rb new file mode 100644 index 0000000..8417149 --- /dev/null +++ b/lib/babelish/csv2yaml.rb @@ -0,0 +1,42 @@ +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 + 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) + entry = '' + indent = ' ' + 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? + entry << "#{indent * @deep}#{row_key}: \"#{row_value}\"\n" + end + + def extension + 'yml' + 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") diff --git a/lib/babelish/version.rb b/lib/babelish/version.rb index acb41f4..fcfd382 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'.freeze end