motion-phrase 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -6
- data/lib/motion-phrase.rb +2 -0
- data/lib/motion-phrase/api_client.rb +16 -8
- data/lib/motion-phrase/nsstring.rb +6 -2
- data/lib/motion-phrase/version.rb +1 -1
- data/lib/motion/project/phrase.rb +12 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -36,12 +36,18 @@ Add the Auth Token to your application's Rakefile:
|
|
36
36
|
|
37
37
|
Motion::Project::App.setup do |app|
|
38
38
|
app.name = "Test Application"
|
39
|
-
|
40
|
-
app.
|
41
|
-
|
39
|
+
|
40
|
+
app.development do
|
41
|
+
app.phrase do
|
42
|
+
app.phrase.enabled = true
|
43
|
+
app.phrase.auth_token = "YOUR_AUTH_TOKEN"
|
44
|
+
end
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
|
-
This will automatically create the `phrase_config.rb` configuration file in your app folder during
|
48
|
+
This will automatically create the `phrase_config.rb` configuration file in your app folder during every build process.
|
49
|
+
|
50
|
+
**Please make sure that you only enable PhraseApp in development mode and never in release mode!**
|
45
51
|
|
46
52
|
Now you can initialize your PhraseApp setup using rake:
|
47
53
|
|
@@ -77,7 +83,6 @@ or (when using a fallback translation):
|
|
77
83
|
Of course you can use more generic names for your keys as well, such as:
|
78
84
|
|
79
85
|
"HOME_WELCOME_BUTTON_LABEL".__
|
80
|
-
|
81
86
|
|
82
87
|
|
83
88
|
[Learn more about localization in iOS](https://developer.apple.com/internationalization/)
|
@@ -136,5 +141,5 @@ Please remember the following hints (especially when something goes wrong):
|
|
136
141
|
|
137
142
|
## Support
|
138
143
|
|
139
|
-
* [PhraseApp
|
144
|
+
* [PhraseApp Documentation](https://phraseapp.com/docs)
|
140
145
|
* [PhraseApp Support Channel](https://phraseapp.com/support)
|
data/lib/motion-phrase.rb
CHANGED
@@ -9,8 +9,8 @@ module MotionPhrase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def storeTranslation(keyName, content, fallbackContent, currentLocale)
|
12
|
-
return unless
|
13
|
-
|
12
|
+
return unless auth_token_present?
|
13
|
+
|
14
14
|
content ||= fallbackContent
|
15
15
|
data = {
|
16
16
|
locale: currentLocale,
|
@@ -30,10 +30,6 @@ module MotionPhrase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
-
def development?
|
34
|
-
RUBYMOTION_ENV == "development"
|
35
|
-
end
|
36
|
-
|
37
33
|
def client
|
38
34
|
@client ||= buildClient
|
39
35
|
end
|
@@ -50,7 +46,19 @@ module MotionPhrase
|
|
50
46
|
end
|
51
47
|
|
52
48
|
def authenticated(params={})
|
53
|
-
params.merge(auth_token:
|
54
|
-
end
|
49
|
+
params.merge(auth_token: auth_token)
|
50
|
+
end
|
51
|
+
|
52
|
+
def auth_token
|
53
|
+
if defined?(PHRASE_AUTH_TOKEN)
|
54
|
+
PHRASE_AUTH_TOKEN
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def auth_token_present?
|
61
|
+
!auth_token.nil? && auth_token != ""
|
62
|
+
end
|
55
63
|
end
|
56
64
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class NSString
|
2
2
|
def _localized(value=nil, table=nil)
|
3
3
|
@localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
|
4
|
-
storeTranslation(self, @localized, value, table) if
|
4
|
+
storeTranslation(self, @localized, value, table) if phraseEnabled?
|
5
5
|
@localized
|
6
6
|
end
|
7
7
|
alias __ _localized
|
@@ -12,8 +12,12 @@ private
|
|
12
12
|
@client.storeTranslation(key, localized, defaultValue, currentLocaleName)
|
13
13
|
end
|
14
14
|
|
15
|
+
def phraseEnabled?
|
16
|
+
PHRASE_ENABLED == true && development?
|
17
|
+
end
|
18
|
+
|
15
19
|
def development?
|
16
|
-
|
20
|
+
App.development?
|
17
21
|
end
|
18
22
|
|
19
23
|
def currentLocaleName
|
@@ -3,12 +3,13 @@ unless defined?(Motion::Project::Config)
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class PhraseConfig
|
6
|
-
attr_accessor :auth_token
|
6
|
+
attr_accessor :auth_token, :enabled
|
7
7
|
|
8
8
|
CONFIG_FILE = './app/phrase_config.rb'
|
9
9
|
|
10
10
|
def initialize(config)
|
11
11
|
@config = config
|
12
|
+
@enabled = false
|
12
13
|
end
|
13
14
|
|
14
15
|
def auth_token=(auth_token)
|
@@ -16,6 +17,11 @@ class PhraseConfig
|
|
16
17
|
create_phrase_config_file
|
17
18
|
end
|
18
19
|
|
20
|
+
def enabled=(enabled)
|
21
|
+
@enabled = enabled
|
22
|
+
create_phrase_config_file
|
23
|
+
end
|
24
|
+
|
19
25
|
private
|
20
26
|
def create_phrase_config_file
|
21
27
|
return unless @auth_token
|
@@ -24,7 +30,7 @@ private
|
|
24
30
|
File.open(CONFIG_FILE, 'w') { |f| f.write(config_file_content) }
|
25
31
|
end
|
26
32
|
files = @config.files.flatten
|
27
|
-
files
|
33
|
+
files.unshift(CONFIG_FILE) unless files.find { |f| File.expand_path(f) == File.expand_path(CONFIG_FILE) }
|
28
34
|
end
|
29
35
|
|
30
36
|
def config_file_exists?
|
@@ -38,7 +44,8 @@ private
|
|
38
44
|
def config_file_content
|
39
45
|
content = <<EOF
|
40
46
|
# This file is automatically generated. Do not edit.
|
41
|
-
|
47
|
+
PHRASE_ENABLED = #{enabled}
|
48
|
+
PHRASE_AUTH_TOKEN = "#{auth_token}"
|
42
49
|
EOF
|
43
50
|
content
|
44
51
|
end
|
@@ -51,6 +58,8 @@ module Motion
|
|
51
58
|
|
52
59
|
def phrase
|
53
60
|
@phrase ||= PhraseConfig.new(self)
|
61
|
+
yield @phrase if block_given?
|
62
|
+
@phrase
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-phrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: phrase
|