applyrics 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c9c5d1a8b7ca2ceeb42846d525159c6b3f5e6b9
4
- data.tar.gz: 8073a60f281b76a59d135f005ad276316fd55c85
3
+ metadata.gz: b4ca2e8f98970107cda93dab4aa1319ce15eec97
4
+ data.tar.gz: e5273c52d624cb091b1d062ee342b03650dbf308
5
5
  SHA512:
6
- metadata.gz: 3424593e1a0309458242b5b14d0527a188f9045389911e3fa36f0428b89d941143ef14ebb659b49d7ccdf64ba36487111a22dc31ba5ed7888104348c9c21b3ce
7
- data.tar.gz: 882a30f205e864f941ac9fb05224a348cdd3a36d90033863f1c4bf489b7b19af7ace3a7fc40dc6dcf2843269d57f38496177ebf83a541038d1da04fa6782d874
6
+ metadata.gz: 0eb761243e8dbd25564b16d3c5cee3e2aa67834d1adfed9c55ce3c3d33a67286a09502f97aaabe7489388c919740085ef2a110777fa213db121e783586d6443a
7
+ data.tar.gz: 866a96e777269425eab3eb6750fb747e2572a48b96d2f0db6f4dae668c266517edf28882a76ac74467839c69a513082c5cef041a095831b5ff9d2881a1e4db4b
@@ -19,24 +19,7 @@ module Applyrics
19
19
  c.syntax = "applyrics init"
20
20
  c.description = "Sets up the project"
21
21
  c.action do |args, options|
22
-
23
- config = {}
24
- if agree("Connect to Applyrics.io?")
25
- ask("Username:")
26
- ask("Password: ") { |q| q.echo = "*" }
27
- choice = choose("Project?", :first, :second, :third)
28
- config[:account_id] = "awesome-account"
29
- config[:project_key] = choice.to_s
30
- elsif agree("Use local files?")
31
- config[:filename] = "lyrics.json"
32
- end
33
-
34
- project = Applyrics::Setup.new.run(config)
35
-
36
- if agree("Rebuild language files?")
37
- puts "will rebuild..."
38
- project.rebuild_files()
39
- end
22
+ puts "Not implemented yet... Sorry!"
40
23
  end
41
24
  end
42
25
 
@@ -47,7 +30,8 @@ module Applyrics
47
30
  c.action do |args, options|
48
31
  options.default :project => './'
49
32
  puts "rebuilding..."
50
- Applyrics::GenStrings.run("#{options.project}", "#{options.project}")
33
+ project = Applyrics::Project.new()
34
+ project.rebuild_files()
51
35
  end
52
36
  end
53
37
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'pty'
2
4
  require 'colored'
3
5
 
@@ -1,4 +1,4 @@
1
1
  module Applyrics
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  DESCRIPTION = "Handle localization for all your mobile projects"
4
4
  end
@@ -2,15 +2,44 @@ require 'i18n_data'
2
2
  require 'applyrics/project_ios'
3
3
  module Applyrics
4
4
  class Project
5
- def initialize(platform, path="")
5
+ class << self
6
+ def is_ios?
7
+ (Dir["*.xcodeproj"] + Dir["*.xcworkspace"]).count > 0
8
+ end
9
+
10
+ def is_android?
11
+ Dir["*.gradle"].count > 0
12
+ end
13
+
14
+ def is_unity?
15
+ false
16
+ end
17
+
18
+ def detected_platform
19
+ if is_ios?
20
+ :ios
21
+ elsif is_android?
22
+ :android
23
+ elsif is_unity?
24
+ :unity
25
+ else
26
+ nil
27
+ end
28
+ end
29
+ end
30
+
31
+ def initialize(platform=nil, path="")
32
+
33
+ if platform.nil?
34
+ platform = self.class.detected_platform
35
+ end
36
+
6
37
  @platform = platform
7
38
 
8
39
  if @platform == :ios
9
40
  @project = Applyrics::Project_iOS.new(path)
10
41
  end
11
42
 
12
- puts path
13
- @path = path
14
43
  end
15
44
 
16
45
  # @return [Array] An array of languages detected in the project.
@@ -1,5 +1,9 @@
1
+ # encoding: utf-8
1
2
  require 'i18n_data'
3
+ require 'multi_json'
2
4
  require 'applyrics/tools/genstrings'
5
+ require 'applyrics/tools/ibtool'
6
+ require 'applyrics/stringsfile'
3
7
  module Applyrics
4
8
  class Project_iOS
5
9
  def initialize(path)
@@ -11,6 +15,7 @@ module Applyrics
11
15
  end
12
16
  @path = path
13
17
  @platform_settings = nil
18
+ @langs = {}
14
19
  end
15
20
 
16
21
  # Return a list of detected languages in the project
@@ -18,12 +23,12 @@ module Applyrics
18
23
  folder = self.platform_project_settings("SOURCE_ROOT")
19
24
  base_language = I18nData.language_code(self.platform_project_settings("DEVELOPMENT_LANGUAGE")).downcase
20
25
  lang_folders = Dir.glob(File.join(folder, "**", "*.lproj"))
21
- @langs = {}
22
26
  lang_folders.each do |lang_folder|
23
27
  lang = /([A-Za-z\-]*?)\.lproj/.match(lang_folder)[1]
24
28
  lang = (lang == "Base" ? base_language : lang)
25
29
  @langs[lang] = lang_folder
26
30
  end
31
+ return @langs
27
32
  end
28
33
 
29
34
  def platform_project_settings(name)
@@ -39,7 +44,25 @@ module Applyrics
39
44
 
40
45
  def rebuild_files
41
46
  folder = self.platform_project_settings("SOURCE_ROOT")
42
- Applyrics::GenStrings.run("#{folder}", "#{folder}")
47
+ tmp_folder = "./.tmp/"
48
+
49
+ if !Dir.exist?(tmp_folder)
50
+ Dir.mkdir(tmp_folder, 0700)
51
+ end
52
+
53
+ GenStrings.run("#{folder}", tmp_folder)
54
+ IBTool.run("#{folder}", tmp_folder)
55
+
56
+ out = {}
57
+ Dir[File.join(tmp_folder, "*.strings")].each do |file|
58
+ puts file
59
+ strings = StringsFile.new(file)
60
+ out[File.basename(file)] = strings.hash
61
+ end
62
+
63
+ File.open(File.join("./", "strings.json"), 'w') { |file| file.write(MultiJson.dump(out, :pretty => true)) }
64
+
65
+
43
66
  end
44
67
  end
45
68
  end
@@ -0,0 +1,81 @@
1
+ # encoding=utf-8
2
+ module Applyrics
3
+ class StringsFile
4
+
5
+ def initialize(filename, data=nil)
6
+ @filename = filename
7
+ @hash = data.nil? ? {} : data
8
+ if data.nil?
9
+ read
10
+ end
11
+ end
12
+
13
+ def read
14
+ @hash = {}
15
+ parser = Parser.new(@hash)
16
+ File.open(@filename, 'rb:utf-16LE:utf-8') { |fd| parser.parse fd }
17
+ self
18
+ end
19
+
20
+ def keys
21
+ # Not implemented...
22
+ end
23
+
24
+ def have_key?
25
+ # Not implemented...
26
+ end
27
+
28
+ def string_for_key(key)
29
+ # Not implemented...
30
+ end
31
+
32
+ def hash
33
+ @hash
34
+ end
35
+
36
+ class Parser
37
+ def initialize(hash)
38
+ @hash = hash
39
+ @property_regex = %r/\A(.*?)=(.*)\z/u
40
+ @quote = %r/"([^"]+)"/u
41
+ @open_quote = %r/\A\s*(".*)\z/u
42
+ @comment_regex = %r/\/\*([^*]+)\*\//u
43
+ end
44
+
45
+ def parse(data)
46
+ @hash.clear
47
+ found_bad_bytes = false
48
+ data.each_line do |line|
49
+ @line = line.chomp
50
+ if !found_bad_bytes
51
+ first_bytes = @line[0..1].bytes.to_a
52
+ if first_bytes.length == 2 && first_bytes[0] == 255
53
+ @line = @line[2,@line.length].force_encoding('UTF-8')
54
+ found_bad_bytes = true
55
+ end
56
+ end
57
+
58
+ case @line
59
+ when @comment_regex
60
+ # Not implemented
61
+ when @property_regex
62
+ key = strip($1)
63
+ value = strip($2)
64
+ @hash[key] = value
65
+ end
66
+ end
67
+
68
+ @hash
69
+ end
70
+
71
+ def strip(value)
72
+ str = @quote.match(value.strip)
73
+ if str.nil?
74
+ value.strip
75
+ else
76
+ str[1]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'applyrics/command'
2
3
  module Applyrics
3
4
  class GenStrings
@@ -1,14 +1,30 @@
1
+ # encoding: utf-8
1
2
  require 'applyrics/command'
2
3
  module Applyrics
3
4
  class IBTool
4
5
  class << self
5
6
  def run(folder, output_folder=nil)
7
+
6
8
  output_folder = folder if output_folder.nil?
7
9
 
8
10
  folder = File.expand_path(folder)
9
11
  output_folder = File.expand_path(output_folder)
10
12
 
11
-
13
+ files = files(folder)
14
+
15
+ files.each do |file|
16
+ filename = File.basename(file, ".*")
17
+ output_file = File.join(output_folder, filename) + ".strings"
18
+ cmd = ["set -o pipefail &&"]
19
+ cmd << Command.which("ibtool")
20
+ cmd << "--export-strings-file " + Shellwords.escape("#{output_file}")
21
+ cmd << Shellwords.escape("#{file}")
22
+ puts Command.execute(cmd)
23
+ end
24
+ end
25
+
26
+ def files(folder)
27
+ return Dir.glob(File.join(folder, "**", "*.{xib,nib,storyboard}"))
12
28
  end
13
29
  end
14
30
  end
@@ -0,0 +1 @@
1
+ # /usr/bin/plutil -lint
@@ -4,3 +4,6 @@ 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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: applyrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Wallner
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 1.11.2
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: '1.11'
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: 1.11.2
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -109,8 +129,10 @@ files:
109
129
  - lib/applyrics/project.rb
110
130
  - lib/applyrics/project_ios.rb
111
131
  - lib/applyrics/setup.rb
132
+ - lib/applyrics/stringsfile.rb
112
133
  - lib/applyrics/tools/genstrings.rb
113
134
  - lib/applyrics/tools/ibtool.rb
135
+ - lib/applyrics/tools/plutil.rb
114
136
  - lib/applyrics.rb
115
137
  - lib/assets/LyricsfileTemplate
116
138
  - bin/applyrics