motion-phrase 0.0.3 → 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.
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.phrase.auth_token = "YOUR_AUTH_TOKEN"
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 the first build process.
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 documentation](https://phraseapp.com/docs)
144
+ * [PhraseApp Documentation](https://phraseapp.com/docs)
140
145
  * [PhraseApp Support Channel](https://phraseapp.com/support)
data/lib/motion-phrase.rb CHANGED
@@ -11,6 +11,8 @@ Motion::Project::App.setup do |app|
11
11
  Dir.glob(File.join(File.dirname(__FILE__), 'motion-phrase/**/*.rb')).each do |file|
12
12
  app.files.unshift(file)
13
13
  end
14
+
15
+ app.files.unshift("./app/phrase_config.rb")
14
16
 
15
17
  app.pods do
16
18
  pod 'AFNetworking'
@@ -9,8 +9,8 @@ module MotionPhrase
9
9
  end
10
10
 
11
11
  def storeTranslation(keyName, content, fallbackContent, currentLocale)
12
- return unless development?
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: PHRASE_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 development?
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
- RUBYMOTION_ENV == "development"
20
+ App.development?
17
21
  end
18
22
 
19
23
  def currentLocaleName
@@ -1,3 +1,3 @@
1
1
  module MotionPhrase
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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 << CONFIG_FILE unless files.find { |f| File.expand_path(f) == File.expand_path(CONFIG_FILE) }
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
- PHRASE_AUTH_TOKEN = "#{@auth_token}"
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.3
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-05 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: phrase