locraft 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 479b59e57f182cdc0ca5491c6fa4707884b43c86
4
- data.tar.gz: 293bc25cef87c61e78c9cc2ad5d307174dafdddb
3
+ metadata.gz: 5867d944d5438805333a0ce1cc252684a6498c8d
4
+ data.tar.gz: d00b212715f1758228fdb982c8582d952489be58
5
5
  SHA512:
6
- metadata.gz: 24e1c6ac452106676862b02f90946318c446eb0a81bc68c88b6f55efae18f7dd3252ac8329b451e0cf7fe375bf5a954145adee8c5a894861ad00f54a39f2efc9
7
- data.tar.gz: 68ea320324f3369cdf2d9185a3517916c5daf7c8333bf389389ade68909b47765410549abb6836d88b0e878313b2947051316082a02776c31cd30f7d471a9dc8
6
+ metadata.gz: ae1379a7eea25ee41d8a003ade1b05d4ba16ee875806c83977c6aa65e39bcf51b475e1d541f78a45b62686007d037327a67d4e89b6544045f76efc8772d97ad0
7
+ data.tar.gz: 48a81fa6e522f72ad4df705fc3a732112a036286f0209e5c429792ad57ca393e1405c4a77110aae9ba1cec2c851fde249204ce47f0249ab5de324adbe12c04f6
data/bin/locraft CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path('../../lib/locraft', __FILE__)
4
- Locraft::Runner.start(ARGV)
4
+ Locraft::Runner.start(ARGV)
@@ -16,6 +16,7 @@ module Locraft
16
16
  attr_accessor :dev_lang
17
17
  attr_accessor :dev_prefix
18
18
  attr_accessor :macro_file
19
+ attr_accessor :keys_separator
19
20
  attr_accessor :macro_destination_dir
20
21
  attr_accessor :strings_basename
21
22
  attr_accessor :info_plist_basename
@@ -29,12 +30,13 @@ module Locraft
29
30
  self.destination_dir = './Localizations'
30
31
  self.default_lang = 'English'
31
32
  self.gdoc_sheet = 0
32
- self.gdoc_keys_column = 0
33
- self.gdoc_comments_column = 0
33
+ self.gdoc_keys_column = 'Keys'
34
+ self.gdoc_comments_column = 'Comments'
34
35
  self.dev_lang = OBJC
35
36
  self.dev_prefix = 'XYZ'
36
37
  self.macro_file = 'LocalizedConstants'
37
38
  self.macro_destination_dir = './'
39
+ self.keys_separator = '.'
38
40
  self.langs = {
39
41
  'English' => 'en',
40
42
  'Russian' => 'ru'
@@ -69,7 +69,7 @@ module Locraft
69
69
  end
70
70
 
71
71
  def constant_from(key)
72
- inside = key.split('.').map { |s| s.capitalize }.join
72
+ inside = key.split(@config.keys_separator).map { |s| s.capitalize }.join
73
73
  %Q{k#{@config.dev_prefix}#{inside}Localized}
74
74
  end
75
75
 
@@ -0,0 +1,47 @@
1
+ require_relative 'config'
2
+ require 'csv'
3
+ require 'fileutils'
4
+
5
+ module Locraft
6
+ class CSVParser
7
+
8
+ def initialize(csv_file, config)
9
+ @config = config
10
+ @csv_body = File.read(csv_file)
11
+ end
12
+
13
+ def parse_to_strings
14
+ csv = CSV.new(@csv_body, :headers => true)
15
+ rows = csv.to_a.map { |row| row.to_hash }
16
+ @config.langs.keys.each do |lang|
17
+ self.parse_rows_for_lang(rows, lang)
18
+ end
19
+ end
20
+
21
+ # return file path
22
+ def parse_rows_for_lang(rows, lang)
23
+ lproj_dir = %Q{#{@config.relative_destination_dir}/#{@config.langs[lang]}.lproj}
24
+ FileUtils::mkdir_p lproj_dir unless Dir.exists?(lproj_dir)
25
+ localizable_file = %Q(#{lproj_dir}/#{@config.strings_basename}#{STRINGS_EXTENSION})
26
+ File.open(localizable_file, 'w+') do |file|
27
+ rows.each do |row|
28
+ hash = self.row_hash(row, lang)
29
+ unless hash[:key].nil?
30
+ file.puts '/* %{comment} */' % hash unless hash[:comment].nil?
31
+ file.puts %Q{"%{key}" = "%{value}";\n\n} % hash
32
+ end
33
+ end
34
+ end
35
+ localizable_file
36
+ end
37
+
38
+ def row_hash(row, lang)
39
+ {
40
+ :comment => row[@config.gdoc_comments_column],
41
+ :value => row[lang] || row[@config.default_lang],
42
+ :key => row[@config.gdoc_keys_column] || row[@config.default_lang]
43
+ }
44
+ end
45
+
46
+ end
47
+ end
@@ -1,7 +1,8 @@
1
1
  require_relative 'config'
2
+ require_relative 'csv_parser'
2
3
  require_relative 'info_plist_generator'
3
4
  require_relative 'constants_generator'
4
- require 'babelish'
5
+ require_relative 'google_drive_wrapper'
5
6
 
6
7
  module Locraft
7
8
  class Extractor
@@ -12,7 +13,9 @@ module Locraft
12
13
 
13
14
  def extract
14
15
  # generate localized strings files
15
- extract_strings
16
+ csv_file = GoogleDriveWrapper.new(@config).export_worksheet
17
+ csv_parser = CSVParser.new(csv_file, @config)
18
+ csv_parser.parse_to_strings
16
19
 
17
20
  # generate .plist files
18
21
  InfoPlistGenerator.new(@config).generate
@@ -21,19 +24,5 @@ module Locraft
21
24
  ConstantsGenerator.new(@config).generate
22
25
  end
23
26
 
24
- def extract_strings
25
- langs = ''
26
- @config.langs.each { |k,v| langs += %Q('#{k}:#{v}' ) }
27
- arg1 = %Q(--filename='#{@config.gdoc_file}')
28
- arg2 = %Q(--langs=#{langs})
29
- arg3 = %Q(--default-lang='#{@config.default_lang}')
30
- arg4 = %Q(--keys-column=#{@config.gdoc_keys_column})
31
- arg5 = %Q(--comments-column=#{@config.gdoc_comments_column})
32
- arg6 = %Q(--output-basenames=#{@config.strings_basename})
33
- arg7 = %Q(--sheet=#{@config.gdoc_sheet})
34
- arg8 = %Q(--output-dir='#{@config.relative_destination_dir}')
35
- system("babelish csv2strings #{arg1} #{arg2} #{arg3} #{arg4} #{arg5} #{arg6} #{arg7} #{arg8} --fetch")
36
- end
37
-
38
27
  end
39
28
  end
@@ -0,0 +1,42 @@
1
+ require_relative 'config'
2
+ require 'google_drive'
3
+ require 'fileutils'
4
+
5
+ module Locraft
6
+ class GoogleDriveWrapper
7
+
8
+ EXPORTED_CSV_FILE = 'google_doc_sheet.csv'
9
+ SESSION_TOKEN_FILE = '.locraft_gdrive_token'
10
+
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def authenticate
16
+ FileUtils::mkdir_p @config.relative_destination_dir unless Dir.exists?(@config.relative_destination_dir)
17
+ token_file = File.join(@config.relative_destination_dir, SESSION_TOKEN_FILE)
18
+ @session = GoogleDrive.saved_session(token_file)
19
+ end
20
+
21
+ def doc_named(name)
22
+ unless @session
23
+ authenticate
24
+ end
25
+ @session.spreadsheet_by_title(name)
26
+ end
27
+
28
+ # return exported file path
29
+ def export_worksheet
30
+ worksheets = self.doc_named(@config.gdoc_file).worksheets
31
+ if worksheets.count > @config.gdoc_sheet
32
+ sheet = worksheets[@config.gdoc_sheet]
33
+ file = File.join(@config.relative_destination_dir, EXPORTED_CSV_FILE)
34
+ sheet.export_as_file(file)
35
+ file
36
+ else
37
+ warn 'gdrive_wrapper worksheet export error: sheet number in config out of bounds!'
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -15,8 +15,9 @@ Locraft::Config.new do |conf|
15
15
  conf.destination_dir = './Localizations' # strings destination directory related to this file, default: './Localizations'
16
16
  conf.default_lang = 'English' # default: 'English'
17
17
  conf.gdoc_sheet = 0 # default: 0
18
- conf.gdoc_keys_column = 0 # default: 0
19
- conf.gdoc_comments_column = 0 # default: 0
18
+ conf.gdoc_keys_column = 'Keys' # default: 'Keys'
19
+ conf.gdoc_comments_column = 'Comments' # default: 'Comments'
20
+ conf.keys_separator = '.' # default: '.'
20
21
  conf.dev_prefix = 'XYZ' # default: 'XYZ'
21
22
  conf.dev_lang = OBJC # OBJC or SWIFT, default: OBJC
22
23
  conf.macro_file = 'LocalizedConstants' # default: 'LocalizedConstants'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sroik
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: babelish
14
+ name: google_drive
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -92,7 +92,9 @@ files:
92
92
  - lib/locraft.rb
93
93
  - lib/locraft/config.rb
94
94
  - lib/locraft/constants_generator.rb
95
+ - lib/locraft/csv_parser.rb
95
96
  - lib/locraft/extractor.rb
97
+ - lib/locraft/google_drive_wrapper.rb
96
98
  - lib/locraft/info_plist_generator.rb
97
99
  - lib/locraft/initializer.rb
98
100
  - lib/locraft/resources/constants_files_header.txt