MotionLocalize 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +75 -0
- data/lib/MotionLocalize/android/string.rb +20 -0
- data/lib/MotionLocalize/android/yaml.rb +15 -0
- data/lib/MotionLocalize/cocoa/ns_string.rb +18 -0
- data/lib/MotionLocalize/motion_localize.rb +5 -0
- data/lib/MotionLocalize/symbol.rb +8 -0
- data/lib/MotionLocalize.rb +20 -0
- data/lib/tasks/localize.rb +52 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e073fca5417d821e9e09aa6c568d51cbefa06d81
|
4
|
+
data.tar.gz: c88699598fc1ea8f298c6ffa62b8fb856995b2a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb8c78ddd0fb359e35ff68e491f9be19a26faa2fb71aa44eb691828344ce4ee8dd8f2d016d71441ee97cc7b75f558e1672756cd18b8b3e2bad55df93123c17bd
|
7
|
+
data.tar.gz: 0c11537fb8296c20050d5d437d6301ac75f6bfb7eed4bc2fad4033f696b92b4e791a27fdfc690a9d48045964b96b608681f46591d1dabe19f9c399e846d59a66
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# MotionLocalize
|
2
|
+
|
3
|
+
This gem allows you to translate your Android and iOS apps easily.
|
4
|
+
|
5
|
+
## Warning
|
6
|
+
This gem is currently in very early-stage. Use it at your own risk :)
|
7
|
+
|
8
|
+
[![Build Status](https://travis-ci.org/bmichotte/MotionLocalize.svg?branch=master)](https://travis-ci.org/bmichotte/MotionLocalize) [![Gem Version](https://badge.fury.io/rb/MotionLocalize.svg)](http://badge.fury.io/rb/MotionLocalize)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'MotionLocalize'
|
14
|
+
```
|
15
|
+
|
16
|
+
Then:
|
17
|
+
|
18
|
+
```sh-session
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Add a `config/locales` dir and put your `locale.yml` files in it.
|
25
|
+
|
26
|
+
You can generate the platform specific files with `rake localize`. This task is automaticaly executed when you build your application.
|
27
|
+
|
28
|
+
```yml
|
29
|
+
# en.yml
|
30
|
+
hello: Hello
|
31
|
+
how_are_you: How are you ?
|
32
|
+
show_my_age: I'm %{age} old
|
33
|
+
|
34
|
+
# fr.yml
|
35
|
+
hello: Bonjour
|
36
|
+
how_are_you: Comment allez-vous ?
|
37
|
+
show_my_age: J'ai %{age} ans
|
38
|
+
```
|
39
|
+
|
40
|
+
On Android, the files `resources/values-en/strings.xml` and `resources/values-fr/strings.xml` will be created.
|
41
|
+
On iOS, the files `resources/en.lproj/Localizable.strings` and `resources/fr.lproj/Localizable.strings` will be created.
|
42
|
+
|
43
|
+
On your code, you can get the translation with
|
44
|
+
```ruby
|
45
|
+
# use a symbol
|
46
|
+
puts :hello._
|
47
|
+
|
48
|
+
# use a string
|
49
|
+
puts 'hello'._
|
50
|
+
|
51
|
+
# use substitution
|
52
|
+
puts :show_my_age._ age: 36
|
53
|
+
|
54
|
+
# You can also use
|
55
|
+
puts 'show_my_age'.translate(age: 36)
|
56
|
+
```
|
57
|
+
|
58
|
+
### A note on Android
|
59
|
+
[As you can read here](https://github.com/GantMan/PackingPeanut#explain-this-android-context-thing-again), Android love `Context` stuff. In order to get your strings translated on Android, you have to initialize `MotionLocalize.context` (from you `Android::App::Application` or first activity).
|
60
|
+
|
61
|
+
## Todo
|
62
|
+
- Tests
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Make some specs pass
|
70
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
6. Create new Pull Request
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Released under the [MIT license](LICENSE).
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def translate(opts={})
|
4
|
+
context = MotionLocalize.context
|
5
|
+
raise ArgumentError.new 'MotionLocalize on android require that you init MotionLocalize.context' unless context
|
6
|
+
str = context.getString(self)
|
7
|
+
unless str
|
8
|
+
return self
|
9
|
+
end
|
10
|
+
|
11
|
+
str = str.dup
|
12
|
+
opts.each do |key, value|
|
13
|
+
puts "replace #{key} with #{value}"
|
14
|
+
str.gsub!("%{#{key}}", value.respond_to?(:to_s) ? value.to_s : value)
|
15
|
+
end
|
16
|
+
str
|
17
|
+
end
|
18
|
+
alias _ translate
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
def translate(opts={})
|
4
|
+
str = NSBundle.mainBundle.localizedStringForKey(self, value: nil, table: nil)
|
5
|
+
unless str
|
6
|
+
return self
|
7
|
+
end
|
8
|
+
|
9
|
+
str = str.dup
|
10
|
+
opts.each do |key, value|
|
11
|
+
puts "replace #{key} with #{value}"
|
12
|
+
str.gsub!("%{#{key}}", value.respond_to?(:to_s) ? value.to_s : value)
|
13
|
+
end
|
14
|
+
str
|
15
|
+
end
|
16
|
+
alias _ translate
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
unless defined?(Motion::Project::Config)
|
3
|
+
raise "MotionLocalize must be required within a RubyMotion project."
|
4
|
+
end
|
5
|
+
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
8
|
+
|
9
|
+
app.files << File.join(lib_dir_path, "MotionLocalize/motion_localize.rb")
|
10
|
+
app.files << File.join(lib_dir_path, "MotionLocalize/symbol.rb")
|
11
|
+
if App.template.to_s =~ /\bios|osx\b/
|
12
|
+
# remove localization from sugarcube
|
13
|
+
app.files.reject! {|file| /sugarcube-localized/ =~ file }
|
14
|
+
app.files << File.join(lib_dir_path, "MotionLocalize/cocoa/ns_string.rb")
|
15
|
+
elsif App.template.to_s =~ /\bandroid\b/
|
16
|
+
app.files << File.join(lib_dir_path, "MotionLocalize/android/string.rb")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'tasks/localize'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
desc "Convert translations to iOS or Android format"
|
2
|
+
task :localize do
|
3
|
+
cocoa = App.template.to_s =~ /\bios|osx\b/
|
4
|
+
android = App.template.to_s =~ /\bandroid\b/
|
5
|
+
if android
|
6
|
+
require File.dirname(__FILE__) + '/../MotionLocalize/android/yaml'
|
7
|
+
end
|
8
|
+
|
9
|
+
files = Dir.glob("config/locales/*.yml")
|
10
|
+
|
11
|
+
files.each do |file|
|
12
|
+
data = YAML.load(File.read(file))
|
13
|
+
locale = File.basename(file).sub(".yml", "")
|
14
|
+
|
15
|
+
if cocoa
|
16
|
+
FileUtils.mkdir_p("resources/#{locale}.lproj")
|
17
|
+
filename = "resources/#{locale}.lproj/Localizable.strings"
|
18
|
+
elsif android
|
19
|
+
FileUtils.mkdir_p("resources/values-#{locale}")
|
20
|
+
filename = "resources/values-#{locale}/strings.xml"
|
21
|
+
end
|
22
|
+
|
23
|
+
App.info "Writing", filename
|
24
|
+
File.open(filename, 'w') do |translation|
|
25
|
+
if android
|
26
|
+
translation.puts <<-EOF
|
27
|
+
<?xml version="1.0" encoding="utf-8"?>
|
28
|
+
<resources>
|
29
|
+
EOF
|
30
|
+
end
|
31
|
+
|
32
|
+
data.each do |key, value|
|
33
|
+
if cocoa
|
34
|
+
translation.puts "\"#{key}\" = \"#{value}\";"
|
35
|
+
elsif android
|
36
|
+
translation.puts <<-EOF
|
37
|
+
<string name="#{key}">#{value}</string>
|
38
|
+
EOF
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if android
|
43
|
+
translation.puts '</resources>'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :build do
|
50
|
+
task :simulator => :localize
|
51
|
+
task :device => :localize
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: MotionLocalize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Michotte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: motion-yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
description: Easy localization for RubyMotion.
|
42
|
+
email:
|
43
|
+
- bmichotte@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/MotionLocalize.rb
|
50
|
+
- lib/MotionLocalize/android/string.rb
|
51
|
+
- lib/MotionLocalize/android/yaml.rb
|
52
|
+
- lib/MotionLocalize/cocoa/ns_string.rb
|
53
|
+
- lib/MotionLocalize/motion_localize.rb
|
54
|
+
- lib/MotionLocalize/symbol.rb
|
55
|
+
- lib/tasks/localize.rb
|
56
|
+
homepage: https://github.com/bmichotte/MotionLocalize
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Localization for iOS and Android made easy.
|
80
|
+
test_files: []
|