motion-localization 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/lib/motion/localization/version.rb +5 -0
- data/lib/motion/localization.rb +7 -0
- data/lib/motion-localization.rake +51 -0
- data/lib/motion-localization.rb +5 -0
- data/motion-localization.gemspec +24 -0
- data/spec/for_test_dir/for_test_files +0 -0
- data/spec/motion-localization_spec.rb +143 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 akahigeg
|
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,58 @@
|
|
1
|
+
# Motion::Localization
|
2
|
+
|
3
|
+
To add localization rake task to your RubyMotion project.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'motion-localization'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
And add this line to your application's Rakefile:
|
16
|
+
|
17
|
+
require 'motion-localization'
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Creating localization files
|
22
|
+
|
23
|
+
Move to your RubyMotion project directory and run rake task `localization:create` with `lang_code`
|
24
|
+
|
25
|
+
rake localization:create lang_code=en
|
26
|
+
rake localization:create lang_code=ja
|
27
|
+
|
28
|
+
## After creating localization files
|
29
|
+
|
30
|
+
Google it for more informatoin.
|
31
|
+
|
32
|
+
### Edit localization files
|
33
|
+
|
34
|
+
* InfoPlist.strings: App name localization.
|
35
|
+
* Localizable.strings: In app string localization.
|
36
|
+
|
37
|
+
### Use localize method in your code
|
38
|
+
|
39
|
+
NSBundle.mainBundle.localizedStringForKey(key, value:default, table:nil)
|
40
|
+
|
41
|
+
#### with BubbleWrap
|
42
|
+
|
43
|
+
BubbleWrap.localized_string(:foo, 'fallback')
|
44
|
+
BW.localized_string(:foo, 'fallback')
|
45
|
+
|
46
|
+
#### with sugercube
|
47
|
+
|
48
|
+
"hello".localized # => NSBundle.mainBundle.localizedStringForKey("hello", value:nil, table:nil)
|
49
|
+
"hello"._ # == "hello".localized
|
50
|
+
"hello".localized('Hello!', 'hello_table') # => ...("hello", value:'Hello!', table:'hello_table')
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
desc "create localization files (options: lang_code=xx )."
|
2
|
+
namespace :localization do
|
3
|
+
task :create do
|
4
|
+
raise "require argument 'lang_code=[lang_code]' ex. lang=en" if ENV['lang_code'].nil?
|
5
|
+
raise "can't find resources dir." unless File.exist? 'resources'
|
6
|
+
|
7
|
+
lang_dir = File.join('resources', "#{ENV['lang_code']}.lproj")
|
8
|
+
info_plist = File.join(lang_dir, 'InfoPlist.strings')
|
9
|
+
localizable = File.join(lang_dir, 'Localizable.strings')
|
10
|
+
|
11
|
+
created_files = []
|
12
|
+
existed_files = []
|
13
|
+
|
14
|
+
if File.exist?(lang_dir)
|
15
|
+
existed_files << lang_dir
|
16
|
+
else
|
17
|
+
Dir.mkdir(lang_dir)
|
18
|
+
created_files << lang_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
if File.exist?(info_plist)
|
22
|
+
existed_files << info_plist
|
23
|
+
else
|
24
|
+
File.open(info_plist, 'w') do |f|
|
25
|
+
f.puts('CFBundleName = "YourAppName";')
|
26
|
+
f.puts('CFBundleDisplayName = "YourAppName";')
|
27
|
+
end
|
28
|
+
created_files << info_plist
|
29
|
+
end
|
30
|
+
|
31
|
+
if File.exist?(localizable)
|
32
|
+
existed_files << localizable
|
33
|
+
else
|
34
|
+
File.open(localizable, 'w') do |f|
|
35
|
+
f.puts('"key" = "localized string";')
|
36
|
+
end
|
37
|
+
created_files << localizable
|
38
|
+
end
|
39
|
+
|
40
|
+
unless ENV['silent']
|
41
|
+
created_files.each do |f|
|
42
|
+
STDOUT.puts "#{f} is created."
|
43
|
+
end
|
44
|
+
existed_files.each do |f|
|
45
|
+
STDOUT.puts "#{f} is already exist."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ENV['lang_code'] = nil
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'motion/localization/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "motion-localization"
|
8
|
+
spec.version = Motion::Localization::VERSION
|
9
|
+
spec.authors = ["akahigeg"]
|
10
|
+
spec.email = ["akahigeg@gmail.com"]
|
11
|
+
spec.description = %q{Localization rake task for RubyMotion}
|
12
|
+
spec.summary = %q{Localization rake task for RubyMotion}
|
13
|
+
spec.homepage = "http://github.com/akahigeg/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
File without changes
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
# TODO: READMEの整備
|
8
|
+
# TODO: gemspecの正義
|
9
|
+
# TODO: gemとしてリリース
|
10
|
+
|
11
|
+
describe 'motion-localization' do
|
12
|
+
before(:all) do
|
13
|
+
@rake = Rake::Application.new
|
14
|
+
Rake.application = @rake
|
15
|
+
Rake.application.rake_require("motion-localization", [File.join(File.dirname(__FILE__), '..', 'lib')])
|
16
|
+
|
17
|
+
@lang_dir = File.join('resources', 'en.lproj')
|
18
|
+
@info_plist = File.join(@lang_dir, 'InfoPlist.strings')
|
19
|
+
@localizable = File.join(@lang_dir, 'Localizable.strings')
|
20
|
+
|
21
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'for_test_dir')
|
22
|
+
|
23
|
+
FileUtils.mkdir_p @tmp_dir
|
24
|
+
Dir.chdir @tmp_dir
|
25
|
+
FileUtils.mkdir_p 'resources'
|
26
|
+
|
27
|
+
ENV['silent'] = 'true'
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:all) do
|
31
|
+
FileUtils.rm_rf 'resources'
|
32
|
+
ENV['silent'] = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "rake localization:create" do
|
36
|
+
context "when execute with lang_code=en" do
|
37
|
+
before do
|
38
|
+
ENV['lang_code'] = 'en'
|
39
|
+
@rake["localization:create"].execute
|
40
|
+
end
|
41
|
+
|
42
|
+
it "en.lproj dir should be created." do
|
43
|
+
File.exist?(@lang_dir).should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "en.lproj/InfoPlist.strings" do
|
47
|
+
subject {File.exist?(@info_plist)}
|
48
|
+
it { expect{subject}.to be_created }
|
49
|
+
|
50
|
+
subject {File.read(@info_plist)}
|
51
|
+
it { should include('CFBundleName')}
|
52
|
+
it { should include('YourAppName')}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "en.lproj/Localizable.strings should be created." do
|
56
|
+
File.exist?(@localizable).should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "ENV['lang_code'] should be cleared at finish" do
|
60
|
+
ENV['lang_code'].should be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when execute with lang_code=ja" do
|
65
|
+
before do
|
66
|
+
ENV['lang_code'] = 'ja'
|
67
|
+
@rake["localization:create"].execute
|
68
|
+
|
69
|
+
@ja = {:dir => File.join('resources', 'ja.lproj')}
|
70
|
+
@ja[:info_plist] = File.join(@ja[:dir], 'InfoPlist.strings')
|
71
|
+
@ja[:localizable] = File.join(@ja[:dir], 'Localizable.strings')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "ja.lproj dir should be created." do
|
75
|
+
File.exist?(@ja[:dir]).should be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "ja.lproj/InfoPlist.strings should be created." do
|
79
|
+
File.exist?(@ja[:info_plist]).should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "ja.lproj/Localizable.strings should be created." do
|
83
|
+
File.exist?(@ja[:localizable]).should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when localization files already exist" do
|
88
|
+
before do
|
89
|
+
ENV['lang_code'] = 'en'
|
90
|
+
@rake["localization:create"].execute
|
91
|
+
|
92
|
+
File.open(@info_plist, 'w') do |f|
|
93
|
+
f.puts('CFBundleName = "ChangedName";')
|
94
|
+
end
|
95
|
+
|
96
|
+
File.open(@localizable, 'w') do |f|
|
97
|
+
f.write('"some_key" = "some_value"')
|
98
|
+
end
|
99
|
+
|
100
|
+
ENV['lang_code'] = 'en'
|
101
|
+
@rake["localization:create"].execute
|
102
|
+
end
|
103
|
+
|
104
|
+
it "InfoPlist.strings should not change." do
|
105
|
+
File.read(@info_plist).should include('ChangedName')
|
106
|
+
end
|
107
|
+
|
108
|
+
it "Localizable.strings should not change." do
|
109
|
+
File.read(@localizable).should include('some_key')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when lang_code is not specified" do
|
114
|
+
it "should raise error" do
|
115
|
+
expect{@rake["localization:create"].execute}.to raise_error(RuntimeError)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when resources dir is not exist" do
|
120
|
+
before(:all) do
|
121
|
+
ENV['lang_code'] = 'en'
|
122
|
+
FileUtils.rm_rf 'resources'
|
123
|
+
end
|
124
|
+
|
125
|
+
after(:all) do
|
126
|
+
FileUtils.mkdir_p 'resources'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should raise error" do
|
130
|
+
expect{@rake["localization:create"].execute}.to raise_error(RuntimeError)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# for matchar
|
137
|
+
def created?
|
138
|
+
true
|
139
|
+
end
|
140
|
+
|
141
|
+
# RSpec::Matchers.define :be_created do |expected|
|
142
|
+
# match {|actual| actual > expected }
|
143
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-localization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- akahigeg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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
|
+
description: Localization rake task for RubyMotion
|
63
|
+
email:
|
64
|
+
- akahigeg@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/motion-localization.rake
|
75
|
+
- lib/motion-localization.rb
|
76
|
+
- lib/motion/localization.rb
|
77
|
+
- lib/motion/localization/version.rb
|
78
|
+
- motion-localization.gemspec
|
79
|
+
- spec/for_test_dir/for_test_files
|
80
|
+
- spec/motion-localization_spec.rb
|
81
|
+
homepage: http://github.com/akahigeg/
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Localization rake task for RubyMotion
|
106
|
+
test_files:
|
107
|
+
- spec/for_test_dir/for_test_files
|
108
|
+
- spec/motion-localization_spec.rb
|