ripl-i18n 0.1.0

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/.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless Object.const_defined?(:Gem)
3
+ require File.dirname(__FILE__) + "/lib/ripl/i18n/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ripl-i18n"
7
+ s.version = Ripl::I18n::VERSION
8
+ s.authors = ["Gabriel Horner"]
9
+ s.email = "gabriel.horner@gmail.com"
10
+ s.homepage = "http://github.com/cldwalker/ripl-i18n"
11
+ s.summary = "A ripl plugin que habla ta langue"
12
+ s.description = "A ripl plugin that translates ripl to your preferred language."
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.add_dependency 'ripl', '~> 0.4.0'
15
+ s.add_development_dependency 'bacon', '>= 1.1.0'
16
+ s.add_development_dependency 'bacon-bits'
17
+ s.rubyforge_project = 'tagaholic'
18
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
19
+ s.files += Dir.glob(['lib/ripl/i18n/locales/*.yml', 'test/fixtures/{,*}.yml'])
20
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
21
+ s.license = 'MIT'
22
+ end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Initial release!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2011 Gabriel Horner
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.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ == Description
2
+ A ripl plugin that translates ripl to your preferred language.
3
+
4
+ == Usage
5
+
6
+ Add to your ~/.riplrc:
7
+
8
+ require 'ripl/i18n'
9
+ # Use your language: :es maps to es.yml
10
+ Ripl.config[:i18n_locale] = :es
11
+
12
+ If you want to load and use your own locale:
13
+
14
+ Ripl::I18n.load 'path/to/my_lang.yml'
15
+ Ripl.config[:i18n_locale] = :my_lang
16
+
17
+ == Contribute Your Language
18
+
19
+ As I would like to make ripl available in as many languages as possible,
20
+ please do add your own! Here's all you have to do:
21
+
22
+ * Fork this project. It's dead-easy to do this with the {fork and edit
23
+ button}[https://github.com/blog/844-forking-with-the-edit-button].
24
+ * Create a .yml file under lib/ripl/i18n/locales/ for your language.
25
+ If you're not sure what locale to use for your language, {see
26
+ some examples}[https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale].
27
+ * Be sure to translate all the keys in lib/ripl/i18n/locales/en.yml.
28
+
29
+ == Inspiration
30
+ http://yugui.jp/articles/863
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'fileutils'
3
+
4
+ def gemspec
5
+ @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
6
+ end
7
+
8
+ desc "Build the gem"
9
+ task :gem=>:gemspec do
10
+ sh "gem build .gemspec"
11
+ FileUtils.mkdir_p 'pkg'
12
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
13
+ end
14
+
15
+ desc "Install the gem locally"
16
+ task :install => :gem do
17
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
18
+ end
19
+
20
+ desc "Generate the gemspec"
21
+ task :generate do
22
+ puts gemspec.to_ruby
23
+ end
24
+
25
+ desc "Validate the gemspec"
26
+ task :gemspec do
27
+ gemspec.validate
28
+ end
29
+
30
+ desc 'Run tests'
31
+ task :test do |t|
32
+ sh 'bacon -q -Ilib -I. test/*_test.rb'
33
+ end
34
+
35
+ task :default => :test
data/deps.rip ADDED
@@ -0,0 +1 @@
1
+ ripl ~>0.4.0
@@ -0,0 +1,14 @@
1
+ ---
2
+ -f: Unterdrücke Laden von ~/.irbrc
3
+ -F: Unterdrücke Laden von ~/.riplrc
4
+ -d: Setze $DEBUG auf wahr (wie `ruby -d')
5
+ -I: Pfad an den Anfang des $LOAD_PATH hinzufügen. Begrenze mehrfache Pfade mit ':'
6
+ -r: Lade Datei mittels "require" (wie `ruby -r')
7
+ -v: Gib Version aus
8
+ -h: Gib Hilfe aus
9
+ run_command: `%s' ist kein %s-Befehl.
10
+ start: Unbenutzte Argumente
11
+ load_rc: Fehler beim Laden von %s
12
+ parse_option: Ungültige Option
13
+ prompt: Fehler beim Erstellen des Prompts
14
+ print_result: Fehler beim Ergebnis ausgeben
@@ -0,0 +1,15 @@
1
+ # Keys and their words to translate into other languages
2
+ ---
3
+ -f: Suppress loading ~/.irbrc
4
+ -F: Suppress loading ~/.riplrc
5
+ -d: Set $DEBUG to true (same as `ruby -d')
6
+ -I: Add to front of $LOAD_PATH. Delimit multiple paths with ':'
7
+ -r: Require file (same as `ruby -r')
8
+ -v: Print version
9
+ -h: Print help
10
+ run_command: `%s' is not a %s command.
11
+ start: Unused arguments
12
+ load_rc: Error while loading %s
13
+ parse_option: invalid option
14
+ prompt: Error while creating prompt
15
+ print_result: Error while printing result
@@ -0,0 +1,14 @@
1
+ ---
2
+ -f: Para de cargar ~/.irbrc
3
+ -F: Para de cargar ~/.riplrc
4
+ -d: Configura $DEBUG a true (lo mismo que `ruby -d')
5
+ -I: Añade al frente de $LOAD_PATH. Delimita con ':'
6
+ -r: Require archivo (lo mismo que `ruby -r')
7
+ -v: Imprime version
8
+ -h: Imprime ayuda
9
+ run_command: `%s' no es un comando de %s.
10
+ start: argumentos no usado
11
+ load_rc: Ocurrió un error mientras cargando %s
12
+ parse_option: opción inválida
13
+ prompt: Ocurrió un error mientras creando prompt
14
+ print_result: Ocurrió un error impremiendo el resultado
@@ -0,0 +1,5 @@
1
+ module Ripl
2
+ module I18n
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/ripl/i18n.rb ADDED
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'ripl'
3
+ require 'yaml'
4
+ require 'ripl/i18n/version'
5
+
6
+ module Ripl::I18n
7
+ class<<self
8
+ attr_accessor :locales
9
+
10
+ def locale; Ripl.config[:i18n_locale]; end
11
+
12
+ def translate(str)
13
+ (locales[locale] ||= {})[str] || "Translation missing: #{locale}.#{str}"
14
+ end
15
+
16
+ def load_file(file)
17
+ YAML.load_file(file)
18
+ rescue
19
+ warn "Error while loading locale from #{file}:\n#{$!}"
20
+ end
21
+
22
+ def init
23
+ load Dir["#{File.dirname(__FILE__)}/i18n/locales/*.yml"]
24
+ internationalize
25
+ end
26
+
27
+ def load(*files)
28
+ files.flatten.each do |file|
29
+ lang = File.basename(file)[/^[a-zA-Z]+/]
30
+ next if lang.nil? || lang.empty?
31
+ locales[lang.to_sym] = load_file(file)
32
+ end
33
+ end
34
+
35
+ def internationalize
36
+ Ripl::Runner::OPTIONS.each { |opt, val| locales[:en][opt] = val[1] }
37
+ Ripl::Runner::OPTIONS.instance_eval %[
38
+ def [](v) [dup[v][0], Ripl::I18n.translate(v)] end
39
+ def values() map {|k,v| [v[0], Ripl::I18n.translate(k)] } end
40
+ ]
41
+ [Ripl::Runner::MESSAGES, Ripl::Shell::MESSAGES].each do |obj|
42
+ obj.each { |opt, val| locales[:en][opt] = val }
43
+ obj.instance_eval %[def [](v) Ripl::I18n.translate(v) end]
44
+ end
45
+ end
46
+ end
47
+ self.locales = {}
48
+ end
49
+
50
+ Ripl.config[:i18n_locale] ||= :en
51
+ Ripl::I18n.init
data/test/deps.rip ADDED
@@ -0,0 +1,2 @@
1
+ bacon >=1.1.0
2
+ bacon-bits >=0
File without changes
@@ -0,0 +1 @@
1
+ ''::'
@@ -0,0 +1 @@
1
+ -f: woah dudez
data/test/i18n_test.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'ripl/i18n'
2
+ require 'bacon'
3
+ require 'bacon/bits'
4
+
5
+ module Helpers
6
+ def capture_stderr(&block)
7
+ original_stderr = $stderr
8
+ $stderr = fake = StringIO.new
9
+ begin
10
+ yield
11
+ ensure
12
+ $stderr = original_stderr
13
+ end
14
+ fake.string
15
+ end
16
+ end
17
+
18
+ Bacon::Context.send :include, Helpers
19
+
20
+ describe Ripl::I18n do
21
+ before_all { Ripl::I18n.locales = {} }
22
+
23
+ describe ".init" do
24
+ describe "defines locales" do
25
+ before do
26
+ Ripl::I18n.locales = {}
27
+ Ripl::I18n.init
28
+ end
29
+
30
+ it "by language" do
31
+ Ripl::I18n.locales.keys.should.include? :en
32
+ Ripl::I18n.locales.keys.should.include? :es
33
+ end
34
+
35
+ it "with the correct number of translations" do
36
+ Ripl::I18n.locales.values.each {|e| e.size.should == 13 }
37
+ end
38
+ end
39
+
40
+ # already redefined when required
41
+ describe "redefines" do
42
+ before_all { Ripl.config[:i18n_locale] = :es }
43
+
44
+ it "Runner::OPTIONS#[]" do
45
+ Ripl::Runner::OPTIONS['-f'].should == ["-f", "Para de cargar ~/.irbrc"]
46
+ end
47
+
48
+ it "Runner::OPTIONS#values" do
49
+ Ripl::Runner::OPTIONS.values.sort_by {|a| a[0].downcase }[0][1].
50
+ should =~ /^Configura/
51
+ end
52
+
53
+ it "Runner::MESSAGES#[]" do
54
+ Ripl::Runner::MESSAGES['start'].should =~ /^argumentos/
55
+ end
56
+
57
+ it "Shell::MESSAGES#[]" do
58
+ Ripl::Shell::MESSAGES['prompt'].should =~ /^Ocurri/
59
+ end
60
+ after_all { Ripl.config[:i18n_locale] = :en }
61
+ end
62
+
63
+ describe ".translate" do
64
+ before_all { Ripl::I18n.init }
65
+ it "returns translation missing message for missing translation" do
66
+ Ripl::I18n.translate('blah').should == "Translation missing: en.blah"
67
+ end
68
+
69
+ it "handles locales that haven't been defined yet" do
70
+ Ripl.config[:i18n_locale] = :zzz
71
+ Ripl::I18n.translate('-f').should =~ /^Translation missing/
72
+ Ripl.config[:i18n_locale] = :en
73
+ end
74
+ end
75
+
76
+ describe ".load" do
77
+ def fixture(name)
78
+ File.dirname(__FILE__) +"/fixtures/#{name}.yml"
79
+ end
80
+
81
+ before { Ripl::I18n.locales = {} }
82
+
83
+ it "prints warning for locale file with invalid syntax" do
84
+ capture_stderr {
85
+ Ripl::I18n.load(fixture('invalid_syntax'))
86
+ }.should =~ /^Error while loading/
87
+ end
88
+
89
+ it "sets locale using basename of locale file" do
90
+ Ripl::I18n.load fixture('rb')
91
+ Ripl::I18n.locales[:rb].should == {'-f' => 'woah dudez' }
92
+ end
93
+
94
+ it "skips locale if invalid basename" do
95
+ Ripl::I18n.load fixture('')
96
+ Ripl::I18n.locales.should.be.empty
97
+ end
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripl-i18n
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Gabriel Horner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-07 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ripl
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: bacon
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.1.0
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bacon-bits
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: A ripl plugin that translates ripl to your preferred language.
50
+ email: gabriel.horner@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - README.rdoc
57
+ - LICENSE.txt
58
+ files:
59
+ - lib/ripl/i18n/version.rb
60
+ - lib/ripl/i18n.rb
61
+ - test/i18n_test.rb
62
+ - LICENSE.txt
63
+ - CHANGELOG.rdoc
64
+ - README.rdoc
65
+ - deps.rip
66
+ - test/deps.rip
67
+ - Rakefile
68
+ - .gemspec
69
+ - lib/ripl/i18n/locales/de.yml
70
+ - lib/ripl/i18n/locales/en.yml
71
+ - lib/ripl/i18n/locales/es.yml
72
+ - test/fixtures/.yml
73
+ - test/fixtures/invalid_syntax.yml
74
+ - test/fixtures/rb.yml
75
+ has_rdoc: true
76
+ homepage: http://github.com/cldwalker/ripl-i18n
77
+ licenses:
78
+ - MIT
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.6
96
+ requirements: []
97
+
98
+ rubyforge_project: tagaholic
99
+ rubygems_version: 1.6.1
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A ripl plugin que habla ta langue
103
+ test_files: []
104
+