smartling_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af36d0e14d0cfd1842e31029fb8201199fa9a98b
4
+ data.tar.gz: 9e1d5075c788d9610e995bd178e3e14cbe86e348
5
+ SHA512:
6
+ metadata.gz: 389002303e955692bc9fc3da24a0ae4968437b7e304d88e8187c4720aa0895102d9bfa316752ba94e906095f2620ac3884b4ddd86494724eea83b1ac1013fcb2
7
+ data.tar.gz: 17e9c0e2f971d6dbea39013b5fecd995837445502346b5c985d9b73f9929eff332b9c0dcba3786348ee2441c3bfb1af220c37b54fb06abd84924b2e466a591a3
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # smartling-rails
2
+ Gem for uploading, checking and getting information from smartling into a rails app using I18N
data/lib/localizer.rb ADDED
@@ -0,0 +1,42 @@
1
+ =begin
2
+ require 'rubygems'
3
+ require 'smartling'
4
+ load 'localizer_files/cb_smartling.rb'
5
+ load 'localizer_files/localizer_helpers.rb'
6
+
7
+ ARGV << "--help" if ARGV.empty?
8
+
9
+ @command = ARGV.shift
10
+ @command = @command_aliases[@command] || @command
11
+ @my_smartling = nil
12
+
13
+ def make_my_smartling
14
+ @my_smartling ||= CBSmartling.new()
15
+ end
16
+
17
+ def print_help
18
+ print_msg("Localizer Help:", true)
19
+ @command_aliases.each do |command_alias, command|
20
+ print_msg(" #{command} or #{command_alias} does.....")
21
+ end
22
+ end
23
+
24
+ def execute_command
25
+ if command_is('h')
26
+ print_help()
27
+ elsif command_is('s')
28
+ @my_smartling.get_status()
29
+ elsif command_is('g')
30
+ @my_smartling.get_files()
31
+ elsif command_is('p')
32
+ @my_smartling.put_files()
33
+ end
34
+ end
35
+
36
+ def startup()
37
+ make_my_smartling()
38
+ execute_command()
39
+ end
40
+
41
+ startup()
42
+ =end
@@ -0,0 +1,30 @@
1
+ require 'smartling'
2
+ Dir[File.dirname(__FILE__) + '/smartling_rails/**/*.rb'].each { |file| require file }
3
+
4
+ module SmartlingRails
5
+
6
+ def self.configure
7
+ yield configuration
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= SmartlingRails::Config.new
12
+ end
13
+
14
+ def self.api_key
15
+ @configuration.api_key
16
+ end
17
+
18
+ def self.project_id
19
+ @configuration.project_id
20
+ end
21
+
22
+ def self.locales
23
+ @configuration.locales
24
+ end
25
+
26
+ def self.processor
27
+ @processor ||= SmartlingRails::SmartlingProcessor.new
28
+ end
29
+
30
+ end
@@ -0,0 +1,31 @@
1
+ module SmartlingRails
2
+ class Config
3
+ attr_accessor :api_key, :project_id, :locales
4
+
5
+ def initialize
6
+ #TODO source from yaml file
7
+ puts "locales should source from a yaml file"
8
+ @locales = {French: {smartling:'fr-FR', careerbuilder:'fr-fr'},
9
+ German: {smartling:'de-DE', careerbuilder:'de-de'},
10
+ Dutch: {smartling:'nl-NL', careerbuilder:'nl-nl'},
11
+ Italian: {smartling:'it-IT', careerbuilder:'it-it'},
12
+ Swedish: {smartling:'sv-SE', careerbuilder:'se-se'},
13
+ Chinese: {smartling:'zh-CN', careerbuilder:'zh-cn'},
14
+ Spanish: {smartling:'es-ES', careerbuilder:'es-es'},
15
+ FrenchCanadian: {smartling:'fr-CA', careerbuilder:'fr-ca'},
16
+ Greek: {smartling:'el-GR', careerbuilder:'gr-gr'}}
17
+ import_env_variables()
18
+ end
19
+
20
+ def import_env_variables
21
+ File.open(".env", "rb") do |f|
22
+ f.each_line do |line|
23
+ key_val = line.split("=")
24
+ @api_key = key_val[1].chop if key_val[0] == 'SMARTLING_API_KEY'
25
+ @project_id = key_val[1].chop if key_val[0] == 'SMARTLING_PROJECT_ID'
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module SmartlingRails
2
+ #def self.command_aliases
3
+ # {
4
+ # "s" => "status",
5
+ # "g" => "get",
6
+ # "p" => "put",
7
+ # "h" => "--help"
8
+ # }
9
+ #end
10
+
11
+ def self.print_msg(msg, padding = false)
12
+ puts if padding
13
+ puts msg
14
+ end
15
+
16
+ #def self.command_is(value)
17
+ # return @command == command_aliases[value]
18
+ #end
19
+
20
+ end
@@ -0,0 +1,46 @@
1
+ module SmartlingRails
2
+ class SmartlingFile
3
+ attr_accessor :file_contents, :locale_codes
4
+
5
+ def initialize(file_contents, locale_codes)
6
+ @file_contents = file_contents
7
+ @locale_codes = locale_codes
8
+ end
9
+
10
+ def fix_file_issues
11
+ puts 'Fixing Issues:'
12
+ fix_tab_size()
13
+ fix_space_after_tree_node()
14
+ fix_first_line_dashes()
15
+ fix_locale_root_node()
16
+ end
17
+
18
+ def fix_tab_size
19
+ puts ' fixing tabs from 4 spaces to 2 space'
20
+ @file_contents.gsub!(' ', ' ')
21
+ end
22
+
23
+ def fix_space_after_tree_node
24
+ puts ' removing space after branch root : \\n to :\\n'
25
+ @file_contents.gsub!(/: \n/,":\n")
26
+ end
27
+
28
+ def fix_first_line_dashes
29
+ puts ' remove "---" from first line'
30
+ if @file_contents.lines.first.match(/---\n/)
31
+ @file_contents.sub!(/---\n/,"")
32
+ puts ' yes, replaced dashes'
33
+ end
34
+
35
+ end
36
+
37
+ def fix_locale_root_node
38
+ puts ' converting smartling locale code to CB locale code'
39
+ @file_contents.sub!(locale_codes[:smartling],locale_codes[:careerbuilder])
40
+ end
41
+
42
+ def print_contents
43
+ puts @file_contents
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,91 @@
1
+ module SmartlingRails
2
+ class SmartlingProcessor
3
+ attr_accessor :my_smartling
4
+
5
+ def initialize()
6
+ puts SmartlingRails.configuration
7
+ @my_smartling = Smartling::File.new(:apiKey => SmartlingRails.api_key, :projectId => SmartlingRails.project_id)
8
+ #@my_smartling = Smartling::File.sandbox(:apiKey => @@api_key, :projectId => @@project_id)
9
+ #puts @my_smartling.list
10
+ SmartlingRails.print_msg "You are working with this remote file on smartling: #{upload_file_path}", true
11
+ SmartlingRails.print_msg "Smartling Ruby client #{Smartling::VERSION}"
12
+ end
13
+
14
+ def get_file_statuses
15
+ SmartlingRails.print_msg("Checking status for #{supported_locales}", true)
16
+ SmartlingRails.locales.each do |language, codes|
17
+ check_file_status(codes[:smartling])
18
+ end
19
+ end
20
+
21
+ def supported_locales
22
+ SmartlingRails.locales.map { |language, codes| language.to_s + ' ' + codes[:smartling] }
23
+ end
24
+
25
+ def check_file_status(language_code)
26
+ begin
27
+ res = @my_smartling.status(upload_file_path, :locale => language_code)
28
+ total_strings = res['stringCount'].to_i
29
+ completed_strings = res['completedStringCount'].to_i
30
+ file_complete = completed_strings >= total_strings
31
+ SmartlingRails.print_msg "#{language_code} completed: #{file_complete} (#{completed_strings} / #{total_strings})"
32
+ rescue Exception => e
33
+ puts e
34
+ end
35
+ end
36
+
37
+ def put_files
38
+ SmartlingRails.print_msg "Uploading the english file to smartling to process:", true
39
+ upload_english_file()
40
+ end
41
+
42
+ def upload_english_file()
43
+ SmartlingRails.print_msg "uploading #{local_file_path_for_locale('en-us')} to #{upload_file_path}"
44
+ @my_smartling.upload(local_file_path_for_locale('en-us'), upload_file_path, 'YAML')
45
+ end
46
+
47
+ def local_file_path_for_locale(cb_locale)
48
+ "config/locales/#{cb_locale}.yml"
49
+ end
50
+
51
+ def upload_file_path()
52
+ "/files/adam-test-resume-en-us-[#{get_current_branch}].yml"
53
+ end
54
+
55
+ def get_files
56
+ SmartlingRails.print_msg("Checking status for #{supported_locales}", true)
57
+ SmartlingRails.locales.each do |language, locale_codes|
58
+ fetch_fix_and_save_file_for_locale(locale_codes)
59
+ end
60
+ end
61
+
62
+ def fetch_fix_and_save_file_for_locale(locale_codes)
63
+ smartling_file = get_file_for_locale(locale_codes)
64
+ smartling_file.fix_file_issues()
65
+ save_to_local_file(smartling_file.file_contents, locale_codes[:careerbuilder])
66
+ end
67
+
68
+ def get_file_for_locale(locale_codes)
69
+ smartling_file = SmartlingFile.new('', locale_codes)
70
+ SmartlingRails.print_msg "Downloading #{locale_codes[:smartling]}:", true
71
+ begin
72
+ smartling_file.file_contents = @my_smartling.download(upload_file_path, :locale => locale_codes[:smartling])
73
+ SmartlingRails.print_msg "file loaded..."
74
+ rescue Exception => e
75
+ SmartlingRails.print_msg e
76
+ end
77
+ smartling_file
78
+ end
79
+
80
+ def save_to_local_file(file_contents, cb_locale)
81
+ File.open(local_file_path_for_locale(cb_locale), 'w') { |file| file.write(file_contents) }
82
+ end
83
+
84
+
85
+
86
+ def get_current_branch
87
+ b = `git branch`.split("\n").delete_if { |i| i[0] != "*" }
88
+ b.first.gsub("* ","")
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ module SmartlingRails
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartling_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - The CareerBuilder.com Consumer Development teams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: smartling
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 0.7.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: '0.7'
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.7.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.11'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '2.11'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-pride
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '2.2'
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 2.2.0
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: '2.2'
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 2.2.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.9'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '0.9'
109
+ description: Smartling support library for automation of rails platforms using I18N
110
+ email: ConsumerDevelopment@careerbuilder.com
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - lib/localizer.rb
116
+ - lib/smartling_rails/config.rb
117
+ - lib/smartling_rails/helpers/localizer_helpers.rb
118
+ - lib/smartling_rails/models/smartling_file.rb
119
+ - lib/smartling_rails/smartling_processor.rb
120
+ - lib/smartling_rails/version.rb
121
+ - lib/smartling_rails.rb
122
+ - README.md
123
+ homepage: http://m.careerbuilder.com
124
+ licenses: []
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.0.14
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Smartling support library for automation of rails platforms using I18N
146
+ test_files: []