motion-phrase 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/motion/project/phrase.rb +45 -0
- data/lib/motion-phrase/api_client.rb +47 -0
- data/lib/motion-phrase/nsstring.rb +22 -0
- data/lib/motion-phrase/version.rb +3 -0
- data/lib/motion-phrase.rb +40 -0
- data/motion-phrase.gemspec +23 -0
- metadata +136 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 docstun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Motion::Phrase
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'motion-phrase'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install motion-phrase
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
class PhraseConfig
|
6
|
+
attr_accessor :auth_token
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def auth_token=(auth_token)
|
13
|
+
@auth_token = auth_token
|
14
|
+
create_phrase_config_file
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def create_phrase_config_file
|
19
|
+
return unless @auth_token
|
20
|
+
|
21
|
+
code = <<EOF
|
22
|
+
# This file is automatically generated. Do not edit.
|
23
|
+
PHRASE_AUTH_TOKEN = "#{@auth_token}"
|
24
|
+
PHRASE_API_BASE_URI = "http://localhost:3000/api/v1/"
|
25
|
+
EOF
|
26
|
+
config_file = './app/phrase_config.rb'
|
27
|
+
unless File.exist?(config_file)
|
28
|
+
File.open(config_file, 'w') { |f| f.write(code) }
|
29
|
+
end
|
30
|
+
files = @config.files.flatten
|
31
|
+
files << config_file unless files.find { |f| File.expand_path(f) == File.expand_path(config_file) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Motion
|
36
|
+
module Project
|
37
|
+
class Config
|
38
|
+
variable :phrase
|
39
|
+
|
40
|
+
def phrase
|
41
|
+
@phrase ||= PhraseConfig.new(self)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MotionPhrase
|
2
|
+
class ApiClient
|
3
|
+
def self.sharedClient
|
4
|
+
Dispatch.once { @instance ||= new }
|
5
|
+
@instance
|
6
|
+
end
|
7
|
+
|
8
|
+
def storeTranslation(keyName, content, fallbackContent, currentLocale)
|
9
|
+
return false unless development?
|
10
|
+
|
11
|
+
data = {
|
12
|
+
"locale" => currentLocale,
|
13
|
+
"key" => keyName,
|
14
|
+
"content" => content,
|
15
|
+
"skip_verification" => true,
|
16
|
+
"auth_token" => PHRASE_AUTH_TOKEN
|
17
|
+
}
|
18
|
+
client.post("translations/store", data) do |result|
|
19
|
+
if result.success?
|
20
|
+
log "Stored Translation for #{keyName}"
|
21
|
+
elsif result.failure?
|
22
|
+
log "Could not store translation for #{keyName}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def development?
|
29
|
+
RUBYMOTION_ENV == "development"
|
30
|
+
end
|
31
|
+
|
32
|
+
def client
|
33
|
+
@client ||= buildClient
|
34
|
+
end
|
35
|
+
|
36
|
+
def buildClient
|
37
|
+
AFMotion::Client.build_shared(PHRASE_API_BASE_URI) do
|
38
|
+
header "Accept", "application/json"
|
39
|
+
operation :json
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def log(msg="")
|
44
|
+
$stdout.puts msg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class NSString
|
2
|
+
def _localized(value=nil, table=nil)
|
3
|
+
@localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
|
4
|
+
storeTranslation(self, @localized, value, table) if development?
|
5
|
+
@localized
|
6
|
+
end
|
7
|
+
alias __ _localized
|
8
|
+
|
9
|
+
private
|
10
|
+
def storeTranslation(key, localized, defaultValue=nil, table=nil)
|
11
|
+
@client = MotionPhrase::ApiClient.sharedClient
|
12
|
+
@client.storeTranslation(key, localized, defaultValue, currentLocaleName)
|
13
|
+
end
|
14
|
+
|
15
|
+
def development?
|
16
|
+
RUBYMOTION_ENV == "development"
|
17
|
+
end
|
18
|
+
|
19
|
+
def currentLocaleName
|
20
|
+
App.current_locale.localeIdentifier
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require "motion/project/phrase"
|
6
|
+
require "motion-cocoapods"
|
7
|
+
require "bubble-wrap"
|
8
|
+
require "afmotion"
|
9
|
+
|
10
|
+
Motion::Project::App.setup do |app|
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'motion-phrase/**/*.rb')).each do |file|
|
12
|
+
app.files.unshift(file)
|
13
|
+
end
|
14
|
+
|
15
|
+
app.pods do
|
16
|
+
pod 'AFNetworking'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :phrase do
|
21
|
+
desc "Initialize PhraseApp for your RubyMotion project"
|
22
|
+
task :init do
|
23
|
+
auth_token = ENV['AUTH_TOKEN']
|
24
|
+
App.fail "Please specify your auth token, e.g. rake phrase:init AUTH_TOKEN=secret" unless auth_token
|
25
|
+
result = `phrase init --secret=#{auth_token}`
|
26
|
+
App.info "PHRASE", result
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Push your Localizable.strings files to PhraseApp"
|
30
|
+
task :push do
|
31
|
+
result = `phrase push --recursive ./resources`
|
32
|
+
App.info "PHRASE", result
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Pull your current localization files files from PhraseApp"
|
36
|
+
task :pull do
|
37
|
+
result = `phrase pull --target=resources --format=strings`
|
38
|
+
App.info "PHRASE", result
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'motion-phrase/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "motion-phrase"
|
8
|
+
gem.version = MotionPhrase::VERSION
|
9
|
+
gem.authors = ["PhraseApp"]
|
10
|
+
gem.email = ["info@phraseapp.com"]
|
11
|
+
gem.description = "RubyMotion library for PhraseApp"
|
12
|
+
gem.summary = "Connect your RubyMotion application to PhraseApp for the best i18n experience"
|
13
|
+
gem.homepage = "https://github.com/phrase/motion-phrase"
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.add_dependency 'phrase'
|
19
|
+
gem.add_dependency 'afmotion'
|
20
|
+
gem.add_dependency 'bubble-wrap'
|
21
|
+
gem.add_dependency 'motion-cocoapods'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-phrase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- PhraseApp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: phrase
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: afmotion
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bubble-wrap
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: motion-cocoapods
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: RubyMotion library for PhraseApp
|
95
|
+
email:
|
96
|
+
- info@phraseapp.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/motion-phrase.rb
|
107
|
+
- lib/motion-phrase/api_client.rb
|
108
|
+
- lib/motion-phrase/nsstring.rb
|
109
|
+
- lib/motion-phrase/version.rb
|
110
|
+
- lib/motion/project/phrase.rb
|
111
|
+
- motion-phrase.gemspec
|
112
|
+
homepage: https://github.com/phrase/motion-phrase
|
113
|
+
licenses: []
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.23
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Connect your RubyMotion application to PhraseApp for the best i18n experience
|
136
|
+
test_files: []
|