motion-i18n 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .repl_history
2
+ build
3
+ resources/*.nib
4
+ resources/*.momd
5
+ resources/*.storyboardc
6
+ *.gem
7
+ .bundle
8
+ Gemfile.lock
9
+ pkg/*
10
+ .dat*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "motion-require"
4
+
5
+ # Specify your gem's dependencies in motion-support.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # MotionI18n
2
+
3
+ Rails-style translations for RubyMotion apps.
4
+
5
+ This gem allows you to specify your RubyMotion translations as `.yml` files. The translations are automatically converted to Cocoa's native format for translations.
6
+
7
+ # Installation
8
+
9
+ ```
10
+ gem install motion-i18n
11
+ ```
12
+
13
+ and in your `Rakefile`:
14
+
15
+ ```ruby
16
+ require 'motion-i18n'
17
+ ```
18
+
19
+ or using bundler:
20
+
21
+ ```ruby
22
+ gem "motion-i18n"
23
+ ```
24
+
25
+ # Usage
26
+
27
+ Put your translations in YAML files in `config/locales/`. For each locale there should be a file named as the locale with the extension `.yml`, e.g. `en.yml`, `de.yml` etc.
28
+
29
+ ## Translations
30
+
31
+ For a guide on how the translation files should look like, see <http://guides.rubyonrails.org/i18n.html#adding-translations>
32
+
33
+ To translate a string, use `I18n.translate` or the shortcut `I18n.t` like this:
34
+
35
+ ```ruby
36
+ I18n.t("main_screen.title")
37
+ ```
38
+
39
+ To substitute variables in the string, specify the substitutions in second a hash argument
40
+
41
+ ```ruby
42
+ I18n.t("maps.directions", :from => origin, :to => destination)
43
+ ```
44
+
45
+ ## Locale
46
+
47
+ You can get the current locale by calling
48
+
49
+ ```ruby
50
+ I18n.locale
51
+ ```
52
+
53
+ # Warning
54
+
55
+ For each locale `loc`, this gem overwrites the file `resources/loc.lproj/Localizable.strings` before building. Make sure you don't edit this file. Also, you should add these files to `.gitignore`:
56
+
57
+ ```
58
+ Localizable.strings
59
+ ```
60
+
61
+ # Forking
62
+
63
+ Feel free to fork and submit pull requests!
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project'
4
+ require "bundler/gem_tasks"
5
+ Bundler.setup
6
+ Bundler.require
7
+
8
+ require 'motion-i18n'
9
+
10
+ Motion::Project::App.setup do |app|
11
+ # Use `rake config' to see complete project settings.
12
+ app.name = 'MotionI18n'
13
+ end
@@ -0,0 +1,7 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
+ @window.rootViewController = UIViewController.alloc.init
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module I18n
2
+ class << self
3
+ def translate(key, substitutions = {})
4
+ String.new((NSBundle.mainBundle.localizedStringForKey(key, value:"", table:nil))).tap do |result|
5
+ substitutions.each do |key, value|
6
+ result.sub!("%{#{key}}", value.to_s)
7
+ end
8
+ end
9
+ end
10
+ alias t translate
11
+
12
+ def locale
13
+ NSLocale.preferredLanguages.first
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ require 'motion-require'
2
+ require 'tasks/translate'
3
+
4
+ Motion::Require.all(Dir.glob(File.expand_path('../motion-i18n/**/*.rb', __FILE__)))
@@ -0,0 +1,35 @@
1
+ def convert(file, namespace, value)
2
+ if value.is_a?(Hash)
3
+ value.each do |key, value|
4
+ convert(file, "#{namespace}.#{key}", value)
5
+ end
6
+ else
7
+ file.puts %{"#{namespace}" = "#{value.to_s}";}
8
+ end
9
+ end
10
+
11
+ task :translate do
12
+ require 'i18n'
13
+
14
+ files = Dir.glob("config/locales/*.yml")
15
+
16
+ I18n.load_path.clear
17
+ I18n.load_path << files
18
+
19
+ files.each do |locale_file|
20
+ locale = File.basename(locale_file).sub(".yml", "")
21
+
22
+ all_translations = I18n.backend.send(:lookup, locale.to_sym, "")
23
+ FileUtils.mkdir_p("resources/#{locale}.lproj")
24
+ File.open("resources/#{locale}.lproj/Localizable.strings", 'w') do |file|
25
+ all_translations.each do |key, value|
26
+ convert(file, key, value)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ namespace :build do
33
+ task :simulator => :translate
34
+ task :device => :translate
35
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = "motion-i18n"
4
+ s.version = "0.0.1"
5
+ s.authors = ["Thomas Kadauke"]
6
+ s.email = ["thomas.kadauke@googlemail.com"]
7
+ s.homepage = "https://github.com/tkadauke/motion-i18n"
8
+ s.summary = "Wrapper for translations in RubyMotion"
9
+ s.description = "Wrapper for translations in RubyMotion"
10
+
11
+ s.files = `git ls-files`.split($\)
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+ s.require_paths = ["lib"]
14
+
15
+ s.add_dependency 'motion-require'
16
+ s.add_dependency 'i18n'
17
+ s.add_development_dependency 'rake'
18
+ end
@@ -0,0 +1,2 @@
1
+ "test.string" = "Test string";
2
+ "test.substitutions" = "%{count} substitutions";
@@ -0,0 +1,25 @@
1
+ describe "I18n" do
2
+ describe "translate" do
3
+ it "should translate string" do
4
+ I18n.translate("test.string").should == "Test string"
5
+ end
6
+
7
+ it "should return key for untranslated string" do
8
+ I18n.translate("foo.bar").should == "foo.bar"
9
+ end
10
+
11
+ it "should plug in substitutions" do
12
+ I18n.translate("test.substitutions", :count => 5).should == "5 substitutions"
13
+ end
14
+
15
+ it "should have shortcut" do
16
+ I18n.t("test.string").should == I18n.translate("test.string")
17
+ end
18
+ end
19
+
20
+ describe "locale" do
21
+ it "should return the current locale" do
22
+ I18n.locale.should == "en"
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Kadauke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: motion-require
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: i18n
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: rake
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: Wrapper for translations in RubyMotion
63
+ email:
64
+ - thomas.kadauke@googlemail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - app/app_delegate.rb
74
+ - lib/motion-i18n.rb
75
+ - lib/motion-i18n/i18n.rb
76
+ - lib/tasks/translate.rb
77
+ - motion-i18n.gemspec
78
+ - resources/en.lproj/Localizable.strings
79
+ - spec/motion-i18n/i18n_spec.rb
80
+ homepage: https://github.com/tkadauke/motion-i18n
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: -1874604674427192652
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -1874604674427192652
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.25
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Wrapper for translations in RubyMotion
110
+ test_files:
111
+ - spec/motion-i18n/i18n_spec.rb