localio-simonz 0.0.21.pre.2

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/CONTRIBUTING.md +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +197 -0
  7. data/Rakefile +9 -0
  8. data/bin/localize +11 -0
  9. data/lib/localio.rb +61 -0
  10. data/lib/localio/filter.rb +43 -0
  11. data/lib/localio/formatter.rb +20 -0
  12. data/lib/localio/localizable_writer.rb +28 -0
  13. data/lib/localio/locfile.rb +65 -0
  14. data/lib/localio/module.rb +15 -0
  15. data/lib/localio/processor.rb +18 -0
  16. data/lib/localio/processors/google_drive_processor.rb +105 -0
  17. data/lib/localio/processors/xls_processor.rb +84 -0
  18. data/lib/localio/processors/xlsx_processor.rb +82 -0
  19. data/lib/localio/segment.rb +14 -0
  20. data/lib/localio/segments_list_holder.rb +12 -0
  21. data/lib/localio/string_helper.rb +64 -0
  22. data/lib/localio/template_handler.rb +21 -0
  23. data/lib/localio/templates/android_localizable.erb +11 -0
  24. data/lib/localio/templates/ios_constant_localizable.erb +11 -0
  25. data/lib/localio/templates/ios_localizable.erb +17 -0
  26. data/lib/localio/templates/java_properties_localizable.erb +10 -0
  27. data/lib/localio/templates/json_localizable.erb +16 -0
  28. data/lib/localio/templates/rails_localizable.erb +13 -0
  29. data/lib/localio/templates/swift_constant_localizable.erb +11 -0
  30. data/lib/localio/term.rb +14 -0
  31. data/lib/localio/version.rb +3 -0
  32. data/lib/localio/writers/android_writer.rb +42 -0
  33. data/lib/localio/writers/ios_writer.rb +56 -0
  34. data/lib/localio/writers/java_properties_writer.rb +37 -0
  35. data/lib/localio/writers/json_writer.rb +38 -0
  36. data/lib/localio/writers/rails_writer.rb +38 -0
  37. data/lib/localio/writers/swift_writer.rb +56 -0
  38. data/localio.gemspec +35 -0
  39. metadata +197 -0
@@ -0,0 +1,21 @@
1
+ require 'erb'
2
+ require 'localio/segments_list_holder'
3
+
4
+ class TemplateHandler
5
+ def self.process_template(template_name, target_directory, generated_file_name, segments)
6
+ full_template_path = File.join(File.dirname(File.expand_path(__FILE__)), "templates/#{template_name}")
7
+ input_file = File.open(full_template_path, 'rb')
8
+ template = input_file.read
9
+ input_file.close
10
+ renderer = ERB.new(template)
11
+ output = renderer.result(segments.get_binding)
12
+ output_file = File.new(generated_file_name, 'w')
13
+ output_file.write(output)
14
+ output_file.close
15
+
16
+ destination_path = File.join(target_directory, generated_file_name)
17
+ FileUtils.mkdir_p(File.dirname(destination_path))
18
+ FileUtils.cp(generated_file_name, destination_path)
19
+ FileUtils.rm(generated_file_name)
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ <!-- Localizable created with localio on (<%= Time.now.localtime %>). DO NOT MODIFY. -->
2
+ <resources>
3
+ <%
4
+ @segments.each do |term|
5
+ if term.is_comment? %>
6
+ <!-- <%= term.translation %> -->
7
+ <% else %> <string name="<%= term.key %>"><%= term.translation %></string>
8
+ <% end
9
+ end
10
+ %>
11
+ </resources>
@@ -0,0 +1,11 @@
1
+ /*
2
+ LocalizableConstants.h
3
+
4
+ GENERATED - DO NOT MODIFY - use localio instead.
5
+
6
+ Created by localio on <%= Time.now.localtime %>.
7
+ */
8
+
9
+ <% @segments.each do |term| %>
10
+ #define <%= term.key %> NSLocalizedString(@"<%= term.translation %>",nil)<%
11
+ end %>
@@ -0,0 +1,17 @@
1
+ /*
2
+ Localizable.strings
3
+
4
+ GENERATED - DO NOT MODIFY - use the localio gem instead.
5
+
6
+ Created by localio on <%= Time.now.localtime %>.
7
+ */
8
+
9
+ <% @segments.each do |term| %>
10
+ <%
11
+ if term.is_comment?
12
+ %>
13
+ // <%= term.translation %>
14
+ <% else %>"<%= term.key %>" = "<%= term.translation %>";<%
15
+ end
16
+ end
17
+ %>
@@ -0,0 +1,10 @@
1
+ # Localizable created with localio on (<%= Time.now.localtime %>). DO NOT MODIFY.
2
+ #
3
+ # Language: <%= @language %>
4
+ <% @segments.each do |term|
5
+ if term.is_comment? %>
6
+ # <%= term.translation %>
7
+ <% else %><%= term.key %>=<%= term.translation %>
8
+ <% end
9
+ end
10
+ %>
@@ -0,0 +1,16 @@
1
+ {
2
+ "meta" : {
3
+ "info": "Localizable created with localio. DO NOT MODIFY.",
4
+ "last_modification": "<%= Time.now.localtime %>",
5
+ "language": "<%= @language %>"
6
+ },
7
+ "translations": {
8
+ <% @segments.each do |term|
9
+ term_value = term.translation
10
+ term_key = term.key
11
+
12
+ term_key = '___comment___' if term.is_comment?
13
+ %> "<%= term_key %>": "<%= term_value %>"<% unless term == @segments.last %>,<% end %>
14
+ <% end %>
15
+ }
16
+ }
@@ -0,0 +1,13 @@
1
+ # Localizable created with localio on (<%= Time.now.localtime %>). DO NOT MODIFY.
2
+ #
3
+ # Language: <%= @language %>
4
+
5
+ <%= @language %>:
6
+ <%
7
+ @segments.each do |term|
8
+ if term.is_comment? %>
9
+ # <%= term.translation %>
10
+ <% else %> <%= term.key %>: "<%= term.translation %>"
11
+ <% end
12
+ end
13
+ %>
@@ -0,0 +1,11 @@
1
+ /*
2
+ LocalizableConstants.swift
3
+
4
+ GENERATED - DO NOT MODIFY - use localio instead.
5
+
6
+ Created by localio on <%= Time.now.localtime %>.
7
+ */
8
+
9
+ <% @segments.each do |term| %>
10
+ let <%= term.key %>: String = { return NSLocalizedString("<%= term.translation %>", comment: "") }()<%
11
+ end %>
@@ -0,0 +1,14 @@
1
+ class Term
2
+
3
+ attr_accessor :values, :keyword
4
+
5
+ def initialize(keyword)
6
+ @keyword = keyword
7
+ @values = Hash.new
8
+ end
9
+
10
+ def is_comment?
11
+ @keyword.downcase == '[comment]'
12
+ end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module Localio
2
+ VERSION = "0.0.21.pre.2"
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+ require 'nokogiri'
6
+
7
+ class AndroidWriter
8
+ def self.write(languages, terms, path, formatter, options)
9
+ puts 'Writing Android translations...'
10
+ default_language = options[:default_language]
11
+
12
+ languages.keys.each do |lang|
13
+ output_path = File.join(path,"values-#{lang}/")
14
+ output_path = File.join(path,'values/') if default_language == lang
15
+
16
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
17
+
18
+ segments = SegmentsListHolder.new lang
19
+ terms.each do |term|
20
+ key = Formatter.format(term.keyword, formatter, method(:android_key_formatter))
21
+ translation = android_parsing term.values[lang]
22
+ segment = Segment.new(key, translation, lang)
23
+ segment.key = nil if term.is_comment?
24
+ segments.segments << segment
25
+ end
26
+
27
+ TemplateHandler.process_template 'android_localizable.erb', output_path, 'strings.xml', segments
28
+ puts " > #{lang.yellow}"
29
+ end
30
+
31
+ end
32
+
33
+ private
34
+
35
+ def self.android_key_formatter(key)
36
+ key.space_to_underscore.strip_tag.downcase
37
+ end
38
+
39
+ def self.android_parsing(value)
40
+ value.gsub('...', '…').escape_xml.escape_newline_and_tab
41
+ end
42
+ end
@@ -0,0 +1,56 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+
6
+ class IosWriter
7
+ def self.write(languages, terms, path, formatter, options)
8
+ puts 'Writing iOS translations...'
9
+
10
+ constant_segments = nil
11
+ languages.keys.each do |lang|
12
+ output_path = File.join(path, "#{lang}.lproj/")
13
+
14
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
15
+
16
+ segments = SegmentsListHolder.new lang
17
+ constant_segments = SegmentsListHolder.new lang
18
+ terms.each do |term|
19
+ key = Formatter.format(term.keyword, formatter, method(:ios_key_formatter))
20
+ translation = ios_parsing term.values[lang]
21
+ segment = Segment.new(key, translation, lang)
22
+ segment.key = nil if term.is_comment?
23
+ segments.segments << segment
24
+
25
+ unless term.is_comment?
26
+ constant_key = ios_constant_formatter term.keyword
27
+ constant_value = key
28
+ constant_segment = Segment.new(constant_key, constant_value, lang)
29
+ constant_segments.segments << constant_segment
30
+ end
31
+ end
32
+
33
+ TemplateHandler.process_template 'ios_localizable.erb', output_path, 'Localizable.strings', segments
34
+ puts " > #{lang.yellow}"
35
+ end
36
+
37
+ unless constant_segments.nil?
38
+ TemplateHandler.process_template 'ios_constant_localizable.erb', path, 'LocalizableConstants.h', constant_segments
39
+ puts ' > ' + 'LocalizableConstants.h'.yellow
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def self.ios_key_formatter(key)
46
+ '_'+key.space_to_underscore.strip_tag.capitalize
47
+ end
48
+
49
+ def self.ios_constant_formatter(key)
50
+ 'kLocale'+key.space_to_underscore.strip_tag.camel_case
51
+ end
52
+
53
+ def self.ios_parsing(value)
54
+ value.gsub(/\\/, '\\\\\\\\').gsub(/"/, "\\\"").gsub(/%(\d+\$)?s/, '%\1@').escape_newline_and_tab
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+
6
+ class JavaPropertiesWriter
7
+ def self.write(languages, terms, path, formatter, options)
8
+ puts 'Writing Java Properties translations...'
9
+
10
+ languages.keys.each do |lang|
11
+ output_path = path
12
+
13
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
14
+
15
+ segments = SegmentsListHolder.new lang
16
+ terms.each do |term|
17
+ key = Formatter.format(term.keyword, formatter, method(:java_properties_key_formatter))
18
+ translation = java_properties_parsing(term.values[lang])
19
+ segment = Segment.new(key, translation, lang)
20
+ segment.key = nil if term.is_comment?
21
+ segments.segments << segment
22
+ end
23
+ TemplateHandler.process_template 'java_properties_localizable.erb', output_path, "language_#{lang}.properties", segments
24
+ puts " > #{lang.yellow}"
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def self.java_properties_key_formatter(key)
31
+ key.space_to_underscore.strip_tag.downcase
32
+ end
33
+
34
+ def self.java_properties_parsing(value)
35
+ value
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+
6
+ class JsonWriter
7
+ def self.write(languages, terms, path, formatter, options)
8
+ puts 'Writing JSON translations...'
9
+
10
+ languages.keys.each do |lang|
11
+ output_path = path
12
+
13
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
14
+
15
+ segments = SegmentsListHolder.new lang
16
+ terms.each do |term|
17
+ key = Formatter.format(term.keyword, formatter, method(:json_key_formatter))
18
+ translation = json_parsing(term.values[lang])
19
+ segment = Segment.new(key, translation, lang)
20
+ segment.key = nil if term.is_comment?
21
+ segments.segments << segment
22
+ end
23
+
24
+ TemplateHandler.process_template 'json_localizable.erb', output_path, "strings-#{lang}.json", segments
25
+ puts " > #{lang.yellow}"
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def self.json_key_formatter(key)
32
+ key.space_to_underscore.strip_tag.downcase
33
+ end
34
+
35
+ def self.json_parsing(value)
36
+ value.gsub(/\\/, '\\\\\\\\').gsub(/"/, "\\\"").escape_newline_and_tab
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+
6
+ class RailsWriter
7
+ def self.write(languages, terms, path, formatter, options)
8
+ puts 'Writing Rails YAML translations...'
9
+
10
+ languages.keys.each do |lang|
11
+ output_path = path
12
+
13
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
14
+
15
+ segments = SegmentsListHolder.new lang
16
+ terms.each do |term|
17
+ key = Formatter.format(term.keyword, formatter, method(:rails_key_formatter))
18
+ translation = rails_parsing(term.values[lang])
19
+ segment = Segment.new(key, translation, lang)
20
+ segment.key = nil if term.is_comment?
21
+ segments.segments << segment
22
+ end
23
+
24
+ TemplateHandler.process_template 'rails_localizable.erb', output_path, "#{lang}.yml", segments
25
+ puts " > #{lang.yellow}"
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def self.rails_key_formatter(key)
32
+ key.space_to_underscore.strip_tag.downcase
33
+ end
34
+
35
+ def self.rails_parsing(value)
36
+ value
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ require 'localio/template_handler'
2
+ require 'localio/segments_list_holder'
3
+ require 'localio/segment'
4
+ require 'localio/formatter'
5
+
6
+ class SwiftWriter
7
+ def self.write(languages, terms, path, formatter, options)
8
+ puts 'Writing iOS translations...'
9
+
10
+ constant_segments = nil
11
+ languages.keys.each do |lang|
12
+ output_path = File.join(path, "#{lang}.lproj/")
13
+
14
+ # We have now to iterate all the terms for the current language, extract them, and store them into a new array
15
+
16
+ segments = SegmentsListHolder.new lang
17
+ constant_segments = SegmentsListHolder.new lang
18
+ terms.each do |term|
19
+ key = Formatter.format(term.keyword, formatter, method(:swift_key_formatter))
20
+ translation = swift_parsing(term.values[lang])
21
+ segment = Segment.new(key, translation, lang)
22
+ segment.key = nil if term.is_comment?
23
+ segments.segments << segment
24
+
25
+ unless term.is_comment?
26
+ constant_key = swift_constant_formatter term.keyword
27
+ constant_value = key
28
+ constant_segment = Segment.new(constant_key, constant_value, lang)
29
+ constant_segments.segments << constant_segment
30
+ end
31
+ end
32
+
33
+ TemplateHandler.process_template 'ios_localizable.erb', output_path, 'Localizable.strings', segments
34
+ puts " > #{lang.yellow}"
35
+ end
36
+
37
+ unless constant_segments.nil?
38
+ TemplateHandler.process_template 'swift_constant_localizable.erb', path, 'LocalizableConstants.swift', constant_segments
39
+ puts ' > ' + 'LocalizableConstants.swift'.yellow
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def self.swift_key_formatter(key)
46
+ '_'+key.space_to_underscore.strip_tag.capitalize
47
+ end
48
+
49
+ def self.swift_constant_formatter(key)
50
+ 'kLocale'+key.space_to_underscore.strip_tag.camel_case
51
+ end
52
+
53
+ def self.swift_parsing(value)
54
+ value
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'localio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "localio-simonz"
8
+ spec.version = Localio::VERSION
9
+ spec.authors = ["Nacho Lopez"]
10
+ spec.email = ["nacho@nlopez.io"]
11
+ spec.description = %q{Automatic Localizable file generation for multiple platforms (Rails YAML, Android, Java Properties, iOS, JSON)}
12
+ spec.summary = %q{Automatic Localizable file generation for multiple type of files, like Android string.xml, Xcode Localizable.strings, JSON files, Rails YAML files, Java properties, etc. reading from Google Drive and Excel spreadsheets as base.}
13
+ spec.homepage = "http://github.com/mrmans0n/localio"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.executables << "localize"
22
+
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.required_ruby_version = ">= 1.9.2"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.3"
28
+ spec.add_development_dependency "rake"
29
+
30
+ spec.add_dependency "micro-optparse", "~> 1.1"
31
+ spec.add_dependency "google_drive", "1.0.0"
32
+ spec.add_dependency "spreadsheet", "~> 1.0"
33
+ spec.add_dependency "simple_xlsx_reader", "~> 0.9"
34
+ spec.add_dependency "nokogiri", "~> 1.6"
35
+ end