icapps-translations 0.1.1 → 0.2.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: 52e55cb3269943bc37d2e63447b3af16a7515dca
4
- data.tar.gz: afee69382593bc252df6b378567511f916237fe0
3
+ metadata.gz: 43a4c063cd284480ac0ba00710f15b9ee3dc66a0
4
+ data.tar.gz: 18501eeac2975dbe452748dd98d508a7d6fe1d92
5
5
  SHA512:
6
- metadata.gz: 15d5da02de340929798b0d421aa5070f6f61a3b9154a6e2a1af7a64ef4d0ec6aaf817ba8f8b835cdb02584e2a85982c4c331c10d294eaf7e033ab8db6453d25c
7
- data.tar.gz: b66c01d63b42ff82b54d35906dfb454eadb68696a88f935e0de329198ae63bef784f0aac9a4cebfe2efb82ce523f402d67e03ef880486fbe8ef756e52f5a322b
6
+ metadata.gz: 452909028b55b33562ddb0e126dd3cf1850a996f475c50f8066c416292c891c9ba0686d6a6e561abe069ed179c87d7fd483e6a2b95d61a09fb03a3325d6c3dd7
7
+ data.tar.gz: f4b52bf360483b47acff530231299d5b44be5eb62d109c7115c093df1e2a94705db959f8df80b44d2f3855690ae69eb07aaa39050832890cd293c3d05f8e6fe9
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
  - `translations init`: Run from your project root in order to setup the translations configuration.
24
24
  - `translations import`: Run from your project root in order to import the translations into the matching _.strings_ files.
25
25
 
26
+ _You can pass the `--verbose` parameter to both commands in order to get more detailed information on what is happening._
27
+
26
28
  ## Build gem
27
29
 
28
30
  Start by updating the version number in the `lib/icapps/translations/version.rb` file.
@@ -34,7 +36,7 @@ Then build the gem by running the following commands:
34
36
 
35
37
  ## Contributing
36
38
 
37
- 1. Fork it ( https://github.com/[my-github-username]/icapps-translations/fork )
39
+ 1. Fork it ( https://github.com/icapps/translations/fork )
38
40
  2. Create your feature branch (`git checkout -b my-new-feature`)
39
41
  3. Commit your changes (`git commit -am 'Add some feature'`)
40
42
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,6 +1,7 @@
1
1
  require "icapps/translations/version"
2
2
  require "icapps/translations/cli"
3
- require "icapps/translations/strings"
3
+ require "icapps/translations/import/xcode"
4
+ require "icapps/translations/import/gradle"
4
5
 
5
6
  module Icapps
6
7
  module Translations
@@ -15,8 +16,24 @@ module Icapps
15
16
  # Validate the configuration file. Abort when invalid.
16
17
  config.validate
17
18
 
18
- # Import the strings files.
19
- Strings.import
19
+ # Import the files.
20
+ if is_xcode?
21
+ puts "[VERBOSE] Detected an Xcode project.".colorize(:white) if options[:verbose]
22
+ Import::Xcode.import
23
+ elsif is_android?
24
+ puts "[VERBOSE] Detected an Android project with a .gradle file.".colorize(:white) if options[:verbose]
25
+ Import::Gradle.import
26
+ else
27
+ abort '[ERROR] No Xcode or Android gradle file detected.'.colorize(:red) unless @project_key
28
+ end
29
+ end
30
+
31
+ def is_android?
32
+ Dir.glob("**/*.gradle").count > 0
33
+ end
34
+
35
+ def is_xcode?
36
+ Dir.glob("**/*.xcodeproj").count > 0
20
37
  end
21
38
  end
22
39
  end
@@ -2,6 +2,7 @@ require 'thor'
2
2
  require 'colorize'
3
3
 
4
4
  require "icapps/translations/configuration"
5
+ require "icapps/translations/import/xcode"
5
6
 
6
7
  module Icapps
7
8
  module Translations
@@ -0,0 +1,40 @@
1
+ require 'colorize'
2
+
3
+ require "icapps/translations/http"
4
+
5
+ module Icapps
6
+ module Translations
7
+ module Import
8
+ class Base
9
+ class << self
10
+ def import
11
+ puts "[VERBOSE] Importing translations from project with key #{options.project_key}".colorize(:white) if options[:verbose]
12
+
13
+ languages_json = fetch_languages
14
+ puts "[VERBOSE] There are currently #{languages_json.count} language(s) for this project.".colorize(:white) if options[:verbose]
15
+
16
+ languages_json.each { |language| fetch_language_file language }
17
+ puts "[MESSAGE] Finished importing translation.".colorize(:green)
18
+ end
19
+
20
+ def options
21
+ ::Icapps::Translations.options
22
+ end
23
+
24
+ def config
25
+ ::Icapps::Translations.config
26
+ end
27
+
28
+ def fetch_languages
29
+ ::Icapps::Translations::Http.authenticated_response('languages.json', true)
30
+ end
31
+
32
+ def write_to_file(content, files, language)
33
+ File.open(files.first, 'w+') { |file| file.puts content }
34
+ puts "[VERBOSE] Written #{language['short_name']} translations to #{files.first}.".colorize(:green) if options[:verbose]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ require 'colorize'
2
+
3
+ require "icapps/translations/http"
4
+ require "icapps/translations/import/base"
5
+
6
+ module Icapps
7
+ module Translations
8
+ module Import
9
+ class Gradle < Base
10
+ class << self
11
+ def fetch_language_file(language)
12
+ short_name = language['short_name']
13
+ puts "[VERBOSE] Fetching #{short_name} translations.".colorize(:white) if options[:verbose]
14
+
15
+ file_path = "app/src/main/res/#{values_name(short_name)}/#{config.filename}"
16
+ xml_files = Dir.glob(file_path)
17
+
18
+ if xml_files.count == 0
19
+ puts "[WARNING] No '#{file_path}' file found for the #{short_name} language.".colorize(:yellow)
20
+ elsif xml_files.count > 1
21
+ puts "[WARNING] Multiple '#{file_path}' files found for the #{short_name} language.".colorize(:yellow)
22
+ else
23
+ xml = ::Icapps::Translations::Http.authenticated_response("translations/#{language['id']}.xml")
24
+ write_to_file xml, xml_files, language
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def values_name(short_name)
31
+ if short_name == 'en'
32
+ # Default language is English.
33
+ 'values'
34
+ else
35
+ # Android requires the country code to be prefixed with an 'r'.
36
+ # ex. nl-BE becomes nl-rBE
37
+ "values-#{short_name.gsub('-', '-r')}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,28 @@
1
+ require 'colorize'
2
+
3
+ require "icapps/translations/http"
4
+ require "icapps/translations/import/base"
5
+
6
+ module Icapps
7
+ module Translations
8
+ module Import
9
+ class Xcode < Base
10
+ class << self
11
+ def fetch_language_file(language)
12
+ short_name = language['short_name']
13
+ puts "[VERBOSE] Fetching #{short_name} translations.".colorize(:white) if options[:verbose]
14
+ string_files = Dir.glob("**/#{short_name}.lproj/#{config.filename}")
15
+ if string_files.count == 0
16
+ puts "[WARNING] No 'Localizable.string' file found for the #{short_name} language.".colorize(:yellow)
17
+ elsif string_files.count > 1
18
+ puts "[WARNING] Multiple 'Localizable.string' files found for the #{short_name} language.".colorize(:yellow)
19
+ else
20
+ strings = ::Icapps::Translations::Http.authenticated_response("translations/#{language['id']}.strings")
21
+ write_to_file strings, string_files, language
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Icapps
2
2
  module Translations
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icapps-translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jelle Vandebeeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,9 @@ files:
85
85
  - lib/icapps/translations/cli.rb
86
86
  - lib/icapps/translations/configuration.rb
87
87
  - lib/icapps/translations/http.rb
88
- - lib/icapps/translations/strings.rb
88
+ - lib/icapps/translations/import/base.rb
89
+ - lib/icapps/translations/import/gradle.rb
90
+ - lib/icapps/translations/import/xcode.rb
89
91
  - lib/icapps/translations/version.rb
90
92
  homepage: https://github.com/icapps/translations
91
93
  licenses:
@@ -1,55 +0,0 @@
1
- require 'colorize'
2
-
3
- require "icapps/translations/http"
4
-
5
- module Icapps
6
- module Translations
7
- class Strings
8
- class << self
9
- def import
10
- puts "[VERBOSE] Importing translations from project with key #{options.project_key}".colorize(:white) if options[:verbose]
11
-
12
- languages_json = fetch_languages
13
- puts "[VERBOSE] There are currently #{languages_json.count} language(s) for this project.".colorize(:white) if options[:verbose]
14
-
15
- languages_json.each { |language| fetch_language_strings_file language }
16
- puts "[MESSAGE] Finished importing translation.".colorize(:green)
17
- end
18
-
19
- private
20
-
21
- def options
22
- ::Icapps::Translations.options
23
- end
24
-
25
- def config
26
- ::Icapps::Translations.config
27
- end
28
-
29
- def fetch_languages
30
- ::Icapps::Translations::Http.authenticated_response('languages.json', true)
31
- end
32
-
33
- def fetch_language_strings_file(language)
34
- short_name = language['short_name']
35
- puts "[VERBOSE] Fetching #{short_name} translations.".colorize(:white) if options[:verbose]
36
- string_files = Dir.glob("**/#{short_name}.lproj/#{config.filename}")
37
- if string_files.count == 0
38
- puts "[WARNING] No 'Localizable.string' file found for the #{short_name} language.".colorize(:yellow)
39
- elsif string_files.count > 1
40
- puts "[WARNING] Multiple 'Localizable.string' files found for the #{short_name} language.".colorize(:yellow)
41
- else
42
- strings = ::Icapps::Translations::Http.authenticated_response("translations/#{language['id']}.strings")
43
- write_to_strings_file strings, string_files, language
44
- end
45
- end
46
-
47
- def write_to_strings_file(strings, string_files, language)
48
- path = string_files.first
49
- File.open(path, 'w+') { |file| file.puts strings }
50
- puts "[VERBOSE] Written #{language['short_name']} translations to #{path}.".colorize(:green) if options[:verbose]
51
- end
52
- end
53
- end
54
- end
55
- end