applyrics 0.0.3.pre → 0.0.4

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: 7f8c09970f5298b306a1f05ff6c89f36fb8db206
4
- data.tar.gz: d7226737efbd8949a1e5eaa135809d7a20457251
3
+ metadata.gz: e5a8c442b98fb9151e37f70ec88480b448871054
4
+ data.tar.gz: cbed507f90c7651baf3225c941dc68f968766978
5
5
  SHA512:
6
- metadata.gz: 9c05ad2a2ee39d8854a7487f96ac1efaa4e70c4f7c828df7a8785a547a43bd430f0d7ca1f6a6eb629009e1cc218e6d03fa3359ac2f8489d2a5e35d1872a92180
7
- data.tar.gz: a65d253e07a1cf8a45e2a9362073b9bc7114344321869cf47684583591bf58e3e0488854f62a8f0b4b5f917c091a3f569d4839e4903bf86f898aaece54f0abdb
6
+ metadata.gz: 6e94add58e7b6b4615a94cfb242905499073290b7fb813a4cd4a1443e329a24f4ee0d4e61c9785c1118c4c808b551972b6e2c7d4b167f2cb79a50575c344e77a
7
+ data.tar.gz: 60ba3c94c66bbcd5fca2394a5be362c79a5148b071819430d51c411d321574bf7a3e768a87da966faea03b2d7c6fcade283004396818f73b5dec312871dba027
@@ -2,6 +2,8 @@ require 'applyrics/info'
2
2
  require 'applyrics/tools/genstrings'
3
3
  require 'applyrics/setup'
4
4
  require 'applyrics/lyricsfile'
5
+ require 'applyrics/stringsfile'
6
+ require 'applyrics/languagefile'
5
7
  module Applyrics
6
8
  class << self
7
9
  end
@@ -16,9 +16,7 @@ module Applyrics
16
16
  program :version, Applyrics::VERSION
17
17
  program :description, Applyrics::DESCRIPTION
18
18
  program :help_formatter, :compact
19
- global_option '--project PATH', String, 'Path to iOS or Android project'
20
19
  global_option '--[no-]rebuild', TrueClass, 'Rebuild language files from source'
21
- global_option '--lang CODE', String, 'Only perform the action for the specified language'
22
20
 
23
21
  command :init do |c|
24
22
  c.syntax = "applyrics init"
@@ -55,7 +53,6 @@ module Applyrics
55
53
  command :extract do |c|
56
54
  c.syntax = "applyrics extract"
57
55
  c.description = "Pull strings from the project into a strings.json file"
58
- c.option '--force-split', TrueClass, 'Saves one language file per language instead of a single one for all languages'
59
56
  c.action do |args, options|
60
57
 
61
58
  project = Applyrics::Project.new()
@@ -85,8 +82,22 @@ module Applyrics
85
82
  c.description = "Applies language from a .json file"
86
83
  c.option '--data STRING', String, 'Path to .json file (Default: strings.json)'
87
84
  c.action do |args, options|
88
- options.default :project => './', :data => './lyrics.json'
89
- puts "Not implemented yet... Sorry!"
85
+ options.default :project => './', :data => './strings.json'
86
+
87
+ language_file = LanguageFile.new(options.data)
88
+
89
+ puts "Loaded language file with #{language_file.languages.length} languages".green
90
+
91
+ project = Applyrics::Project.new()
92
+ detect_lang = project.detected_languages
93
+
94
+ langs = project.string_files()
95
+
96
+ langs = langs.merge(language_file.to_hash)
97
+
98
+ project.apply_languages(langs)
99
+
100
+
90
101
  end
91
102
  end
92
103
 
@@ -1,4 +1,4 @@
1
1
  module Applyrics
2
- VERSION = "0.0.3.pre"
2
+ VERSION = "0.0.4"
3
3
  DESCRIPTION = "Handle localization for all your mobile projects"
4
4
  end
@@ -34,6 +34,10 @@ module Applyrics
34
34
  @hash = MultiJson.load(data)
35
35
  end
36
36
 
37
+ def to_hash
38
+ @hash
39
+ end
40
+
37
41
  def write()
38
42
  File.open(@path, 'w') { |file| file.write(MultiJson.dump(@hash, :pretty => true)) }
39
43
  end
@@ -72,6 +72,10 @@ module Applyrics
72
72
  @project.rebuild_files()
73
73
  end
74
74
 
75
+ def apply_languages(data)
76
+ @project.apply_languages(data)
77
+ end
78
+
75
79
  def platform
76
80
  @platform
77
81
  end
@@ -36,7 +36,7 @@ module Applyrics
36
36
  def language_files
37
37
  folder = self.platform_project_settings("SOURCE_ROOT") unless !folder.nil?
38
38
  out = {}
39
- Dir[File.join(folder, "**","*.strings")].each do |file|
39
+ Dir[File.join(folder, "**", "*.lproj", "*.strings")].each do |file|
40
40
  lang = /(\w*).lproj/.match(file)[1]
41
41
  lang = (lang == "Base" ? default_language : lang)
42
42
 
@@ -76,12 +76,13 @@ module Applyrics
76
76
  Dir[File.join(folder, "**", "*.lproj", "*.strings")].each do |file|
77
77
  strings = StringsFile.new(file)
78
78
  lang = /(\w*).lproj/.match(file)[1]
79
+ lang = (lang == "Base" ? default_language : lang)
79
80
 
80
81
  if !out.key?(lang)
81
82
  out[lang] = {}
82
83
  end
83
84
 
84
- out[lang][File.basename(file)] = strings.hash
85
+ out[lang][File.basename(file)] = strings.to_hash
85
86
  end
86
87
 
87
88
  out
@@ -105,12 +106,31 @@ module Applyrics
105
106
 
106
107
  Dir[File.join(tmp_folder, "*.strings")].each do |file|
107
108
  strings = StringsFile.new(file)
108
- langHash[File.basename(file)] = strings.hash
109
+ langHash[File.basename(file)] = strings.to_hash
109
110
  end
110
111
 
111
112
  FileUtils.remove_dir(tmp_folder)
112
113
 
113
114
  out
114
115
  end
116
+
117
+ def apply_languages(data)
118
+ folder = self.platform_project_settings("SOURCE_ROOT")
119
+
120
+ data.each do |lang, files|
121
+ files.each do |file, data|
122
+
123
+ lang_folder = Dir[File.join(folder, "**", (lang == default_language ? "Base" : lang) + ".lproj")].first
124
+
125
+ if !Dir.exist?(lang_folder)
126
+ Dir.mkdir(lang_folder, 0700)
127
+ puts "Created #{lang_folder}".yellow
128
+ end
129
+
130
+ strings = StringsFile.new(File.join(lang_folder, file), data)
131
+ strings.write
132
+ end
133
+ end
134
+ end
115
135
  end
116
136
  end
@@ -7,16 +7,12 @@ module Applyrics
7
7
  def run(config = {})
8
8
  platform = nil
9
9
  if is_ios?
10
- puts "Found iOS project..."
11
10
  platform = :ios
12
11
  elsif is_android?
13
- puts "Found Android project..."
14
12
  platform = :android
15
13
  elsif is_unity?
16
- puts "Found Unity project..."
17
14
  platform = :unity
18
15
  else
19
- puts "Didn't find any project!"
20
16
  return
21
17
  end
22
18
 
@@ -10,13 +10,6 @@ module Applyrics
10
10
  end
11
11
  end
12
12
 
13
- def read
14
- @hash = {}
15
- parser = Parser.new(@hash)
16
- File.open(@path, 'rb:bom|utf-16LE:utf-8') { |fd| parser.parse fd }
17
- self
18
- end
19
-
20
13
  def keys
21
14
  # Not implemented...
22
15
  end
@@ -29,11 +22,42 @@ module Applyrics
29
22
  # Not implemented...
30
23
  end
31
24
 
32
- def hash
25
+ def to_hash
33
26
  @hash
34
27
  end
35
28
 
29
+ def read
30
+ @hash = {}
31
+ parser = Parser.new(@hash)
32
+ File.open(@path, 'rb:bom|utf-16LE:utf-8') { |fd| parser.parse fd }
33
+ self
34
+ end
35
+
36
+ def write
37
+ temp = Tempfile.new(File.basename(@path))
38
+ begin
39
+ gen = Generator.new(@hash)
40
+ gen.run { |line| temp.puts line }
41
+ FileUtils.mv(temp.path, @path)
42
+ ensure
43
+ temp.close
44
+ end
45
+ end
46
+
47
+ class Generator
48
+ def initialize(data)
49
+ @hash = data
50
+ end
51
+
52
+ def run
53
+ @hash.each do |key,value|
54
+ yield "\"#{key}\" = \"#{value}\"\n" if block_given?
55
+ end
56
+ end
57
+ end
58
+
36
59
  class Parser
60
+
37
61
  def initialize(hash)
38
62
  @hash = hash
39
63
  @property_regex = %r/\A(.*?)=(.*)\z/u
@@ -4,6 +4,3 @@ project:[[PROJECT_KEY]]
4
4
 
5
5
  # Name of local language file
6
6
  filename:[[FILENAME]]
7
-
8
- # Don't build string from these files
9
- ignore:[[IGNORE]]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: applyrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.pre
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Wallner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -153,12 +153,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - '>='
155
155
  - !ruby/object:Gem::Version
156
- version: '0'
156
+ version: '1.9'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - '>'
159
+ - - '>='
160
160
  - !ruby/object:Gem::Version
161
- version: 1.3.1
161
+ version: '0'
162
162
  requirements: []
163
163
  rubyforge_project:
164
164
  rubygems_version: 2.0.14