gbence-g3a_i18n 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ - v0.2.0: Changing API (localize -> translate), and license.
2
+ - v0.1.1: Githubbing README.
3
+ - v0.1.0: Initial release.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bence Golda <gbence@algernon.hu>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,14 @@
1
+ CHANGELOG
2
+ Rakefile
3
+ MIT-LICENSE
4
+ README.rdoc
5
+ g3a_i18n.gemspec
6
+ lib/g3a.rb
7
+ lib/g3a/i18n.rb
8
+ init.rb
9
+ locales/hu.yml
10
+ spec/g3a_i18n_spec.rb
11
+ spec/hu/float_spec.rb
12
+ spec/hu/integer_spec.rb
13
+ spec/spec_helper.rb
14
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = G3A::I18n
2
+
3
+ == Summary
4
+
5
+ This is an extension to the original Ruby/Rails I18n project, that should be
6
+ found in activesupport's vendor directory. G3A::I18n gives you the ability to
7
+ translate Integers and Floats through the well known I18n API, eg.:
8
+
9
+ require 'g3a/i18n'
10
+ I18n.locale = :hu
11
+ I18n.t 1234
12
+ # => "ezerkétszázharmincnégy"
13
+ I18n.t(1234.0 + 1/6.0)
14
+ # => "ezerkétszázharmincnégy és egy hatod"
15
+
16
+ == Prerequisites
17
+
18
+ You should install svenfuchs' i18n gem prior to this one.
19
+
20
+ gem install svenfuchs-i18n --source http://gems.github.com/
21
+
22
+ == Installation
23
+
24
+ gem install gbence-g3a_i18n --source http://gems.github.com/
25
+
26
+ == Licensing and contribution
27
+
28
+ G3A::I18n is released under the MIT-LICENSE license, see the included license
29
+ file for further information. Suggestions, feedback, pull requests, patches,
30
+ bug reports are mostly welcome to my github account or to
31
+ mailto:gbence@algernon.hu.
32
+
33
+ Some part of this project is forked of László Németh's localization project
34
+ (http://hunspell.sourceforge.net/Soros.html), as well as the cloned gemspec and
35
+ other misc files from Bálint Érdi's (http://github.com/balinterdi) various
36
+ projects.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'spec/rake/spectask'
4
+ require 'cucumber/rake/task'
5
+
6
+ desc 'Default: run specs'
7
+ task :default => 'spec'
8
+
9
+ desc 'Run all specs in spec directory'
10
+ Spec::Rake::SpecTask.new(:spec) do |t|
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ t.spec_opts = ['--color', '--format specdoc']
13
+ end
14
+
15
+ desc 'Generate documentation for G3A.'
16
+ Rake::RDocTask.new(:rdoc) do |t|
17
+ t.rdoc_dir = 'rdoc'
18
+ t.title = 'G3A'
19
+ t.options << '--line-numbers' << '--inline-source' << '--charset' << 'UTF-8'
20
+ t.rdoc_files.include('README.rdoc')
21
+ t.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ desc 'Cucumberate.'
25
+ Cucumber::Rake::Task.new do |t|
26
+ t.cucumber_opts = '--language en'
27
+ end
28
+
data/g3a_i18n.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'g3a_i18n'
5
+ s.version = '0.2.0'
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
7
+ s.authors = ["Bence Golda"]
8
+ s.email = 'gbence@algernon.hu'
9
+ s.date = '2009-06-18'
10
+ s.description = 'Number localization extensions to the original (Ruby/Rails) I18n project.'
11
+ s.executables = %w{ }
12
+ s.extra_rdoc_files = %w{ README.rdoc }
13
+ s.files = %w{ CHANGELOG Rakefile MIT-LICENSE README.rdoc g3a_i18n.gemspec lib/g3a.rb lib/g3a/i18n.rb init.rb locales/hu.yml spec/g3a_i18n_spec.rb spec/hu/float_spec.rb spec/hu/integer_spec.rb spec/spec_helper.rb Manifest }
14
+ s.has_rdoc = true
15
+ s.homepage = 'http://github.com/gbence/g3a_i18n'
16
+ s.rdoc_options = %w{ --line-numbers --inline-source --title G3A::I18n --main README.rdoc }
17
+ s.require_paths = %w{ lib }
18
+ s.rubyforge_project = 'g3a_i18n'
19
+ s.rubygems_version = '1.3.3'
20
+ s.summary = 'Number localization extensions to the original (Ruby/Rails) I18n project.'
21
+
22
+ s.add_dependency 'svenfuchs-i18n', '>= 0.1.3'
23
+
24
+ if s.respond_to? :specification_version then
25
+ # current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ # if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ # else
30
+ # end
31
+ else
32
+ end
33
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # this will make it possible to install missing_t as a plugin for a Rails
2
+ # project (from http://railscasts.com/episodes/135-making-a-gem)
3
+ require 'g3a/i18n'
data/lib/g3a.rb ADDED
@@ -0,0 +1,10 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+
3
+ G3A_LOADABLE_MODULES = [] unless defined?(G3A_LOADABLE_MODULES)
4
+ G3A_LOADABLE_MODULES.unshift(*(%w{ g3a/i18n }))
5
+
6
+ module G3A; end
7
+
8
+ while f = (loadable_modules ||= G3A_LOADABLE_MODULES).pop do
9
+ begin; require f; end #rescue LoadError; next; end
10
+ end
data/lib/g3a/i18n.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ gem 'svenfuchs-i18n', '>= 0.1.3'
3
+
4
+ require 'yaml'
5
+ require 'i18n'
6
+
7
+ module G3A
8
+ module I18n
9
+ end
10
+ end
11
+
12
+ module G3A::I18n::Backend
13
+ class ObjectHandler < ::I18n::Backend::Simple
14
+ def translate locale, object, format=:default
15
+ case object
16
+ when Float
17
+ source = object.to_s
18
+ ((translations[locale][:float] || [] rescue []) + (translations[locale][:integer] || [] rescue [])).each do |rule|
19
+ source.gsub!(Regexp.new(rule.keys.first), rule.values.first)
20
+ end
21
+ source
22
+ when Integer
23
+ source = object.to_s
24
+ (translations[locale][:integer] || [] rescue []).each do |rule|
25
+ source.gsub!(Regexp.new(rule.keys.first), rule.values.first)
26
+ end
27
+ source
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def localize locale, object, format=:default
34
+ case object
35
+ when Float
36
+ when Integer
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ I18n.backend = G3A::I18n::Backend::ObjectHandler.new
45
+ I18n.backend.load_translations(*Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'locales', '**', '*.yml')))
46
+
data/locales/hu.yml ADDED
@@ -0,0 +1,73 @@
1
+ # Hungarian integer number names, described by László Németh (http://hunspell.sourceforge.net/Soros.html).
2
+ # License: LGPL and BSD dual-license
3
+ #
4
+ # Integer modifications and floats by Bence Golda <gbence@algernon.hu>, (c) 2009, MIT-LICENSE.
5
+ #
6
+ # Rule order is important!
7
+ hu:
8
+ :integer:
9
+ - "[-−](\d\d*)": "mínusz \1"
10
+ - "^0$": "nulla"
11
+ - "(\d{1,3})0{21}": "\1trilliárd"
12
+ - "(\d{1,3})(\d{21})": "\1trilliárd-\2"
13
+ - "-000": "-"
14
+ - "(\d{1,3})0{18}": "\1trillió"
15
+ - "(\d{1,3})(\d{18})": "\1trillió-\2"
16
+ - "-000": "-"
17
+ - "(\d{1,3})0{15}": "\1billiárd"
18
+ - "(\d{1,3})(\d{15})": "\1billiárd-\2"
19
+ - "-000": "-"
20
+ - "(\d{1,3})0{12}": "\1billió"
21
+ - "(\d{1,3})(\d{12})": "\1billió-\2"
22
+ - "-000": "-"
23
+ - "(\d{1,3})0{9}": "\1milliárd"
24
+ - "(\d{1,3})(\d{9})": "\1milliárd-\2"
25
+ - "-000": "-"
26
+ - "(\d{1,3})0{6}": "\1millió"
27
+ - "(\d{1,3})(\d{6})": "\1millió-\2"
28
+ - "-000": "-"
29
+ - "(\d{1,3})000($| egész)": "\1ezer\2"
30
+ - "(\d{1,3})(\d{3})": "\1ezer-\2"
31
+ - "(-|^| )1ezer-": "\1ezer"
32
+ - "1(\d\d)": "száz\1"
33
+ - "0(\d\d)": "\1"
34
+ - "(\d)(\d\d)": "\1száz\2"
35
+ - "20": "húsz"
36
+ - "10": "tíz"
37
+ - "9(\d)": "kilencven\1"
38
+ - "8(\d)": "nyolcvan\1"
39
+ - "7(\d)": "hetven\1"
40
+ - "6(\d)": "hatvan\1"
41
+ - "5(\d)": "ötven\1"
42
+ - "4(\d)": "negyven\1"
43
+ - "3(\d)": "harminc\1"
44
+ - "2(\d)": "huszon\1"
45
+ - "1(\d)": "tizen\1"
46
+ - "0(\d)": "\1"
47
+ - "9": "kilenc"
48
+ - "8": "nyolc"
49
+ - "7": "hét"
50
+ - "6": "hat"
51
+ - "5": "öt"
52
+ - "4": "négy"
53
+ - "3": "három"
54
+ - "2$": "kettő"
55
+ - "2": "két"
56
+ - "1": "egy"
57
+ - "0": ""
58
+ :float:
59
+ - "\.0$": ""
60
+ - "\.5$": " és fél"
61
+ - "\.25$": " és egy negyed"
62
+ - "\.75$": " és három negyed"
63
+ - "\.3{9,}(3|4)$": " és egy harmad"
64
+ - "\.6{9,}(6|7)$": " és két harmad"
65
+ - "\.16{8,}(6|7)$": " és egy hatod"
66
+ - "\.83{8,}(3|4)$": " és öt hatod"
67
+ - "(\d+)\.(\d{1})$": "\1 egész \2 tized"
68
+ - "(\d+)\.(\d{2})$": "\1 egész \2 század"
69
+ - "(\d+)\.(\d{3})$": "\1 egész \2 ezred"
70
+ - "(\d+)\.(\d{4})$": "\1 egész \2 tízezred"
71
+ - "(\d+)\.(\d{5})$": "\1 egész \2 százezred"
72
+ - "(\d+)\.(\d{6})$": "\1 egész \2 milliomod"
73
+ - "egész 0+": "egész "
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "G3A::I18n::Backend::ObjectHandler" do
4
+ it "should be a descendant of I18n::Backend::Simple" do
5
+ G3A::I18n::Backend::ObjectHandler.superclass.should == I18n::Backend::Simple
6
+ end
7
+
8
+ describe "instance" do
9
+ it "should be an active I18n backend" do
10
+ I18n.backend.should be_kind_of(G3A::I18n::Backend::ObjectHandler)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ context "Hungarian" do
4
+
5
+ before(:each) do
6
+ I18n.locale = :hu
7
+ end
8
+
9
+ describe "Float" do
10
+ it "can be localized" do
11
+ lambda { I18n.l 0.1 }.should_not raise_error
12
+ lambda { I18n.localize 0.1 }.should_not raise_error
13
+ end
14
+
15
+ it "can be translated" do
16
+ lambda { I18n.t 0.1 }.should_not raise_error
17
+ lambda { I18n.translate 0.1 }.should_not raise_error
18
+ end
19
+
20
+ {
21
+ 0.0 => 'nulla',
22
+ 1.0 => 'egy',
23
+ 1.0+(1.0/6.0) => 'egy és egy hatod',
24
+ 1.25 => 'egy és egy negyed',
25
+ 1.0+(1.0/3.0) => 'egy és egy harmad',
26
+ 1.5 => 'egy és fél',
27
+ 1.0+(2.0/3.0) => 'egy és két harmad',
28
+ 1.75 => 'egy és három negyed',
29
+ 1.0+(5.0/6.0) => 'egy és öt hatod',
30
+ 2.0 => 'kettő',
31
+ 2.25 => 'két és egy negyed',
32
+ 2.5 => 'két és fél',
33
+ 2.75 => 'két és három negyed',
34
+ 2.666 => 'két egész hatszázhatvanhat ezred',
35
+ 2.666666 => 'két egész hatszázhatvanhatezer-hatszázhatvanhat milliomod',
36
+ 10.0 => 'tíz',
37
+ 10.1 => 'tíz egész egy tized',
38
+ 10.11 => 'tíz egész tizenegy század',
39
+ 10.101 => 'tíz egész százegy ezred',
40
+ 10.0001 => 'tíz egész egy tízezred',
41
+ 10.00001 => 'tíz egész egy százezred',
42
+ 10.100001 => 'tíz egész százezer-egy milliomod',
43
+ 1234.6666666666666 => 'ezerkétszázharmincnégy és két harmad',
44
+ 1234.1234 => 'ezerkétszázharmincnégy egész ezerkétszázharmincnégy tízezred'
45
+ #10.1234567 => 'tíz egész egy-kettő-három-négy-öt-hat-hét',
46
+ #-10.1234567 => 'mínusz tíz egész egy-kettő-három-négy-öt-hat-hét'
47
+ }.each do |number,translation|
48
+ instance_eval <<-EOC
49
+ describe #{number}.to_s do
50
+ it "should equal to '#{translation}'" do
51
+ I18n.translate(#{number}).should == "#{translation}"
52
+ end
53
+ end
54
+ EOC
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,68 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ context "Hungarian" do
4
+
5
+ before(:each) do
6
+ I18n.locale = :hu
7
+ end
8
+
9
+ describe "Integer" do
10
+ it "can be localized" do
11
+ lambda { I18n.l 1 }.should_not raise_error
12
+ lambda { I18n.localize 1 }.should_not raise_error
13
+ end
14
+
15
+ it "can be translated" do
16
+ lambda { I18n.t 1 }.should_not raise_error
17
+ lambda { I18n.translate 1 }.should_not raise_error
18
+ end
19
+
20
+ {
21
+ 0 => 'nulla',
22
+ 1 => 'egy',
23
+ 2 => 'kettő',
24
+ 10 => 'tíz',
25
+ 11 => 'tizenegy',
26
+ 12 => 'tizenkettő',
27
+ 20 => 'húsz',
28
+ 22 => 'huszonkettő',
29
+ 23 => 'huszonhárom',
30
+ 12 => 'tizenkettő',
31
+ 100 => 'száz',
32
+ 101 => 'százegy',
33
+ 110 => 'száztíz',
34
+ 123 => 'százhuszonhárom',
35
+ 201 => 'kétszázegy',
36
+ 1001 => 'ezeregy',
37
+ 1010 => 'ezertíz',
38
+ 1011 => 'ezertizenegy',
39
+ 1100 => 'ezerszáz',
40
+ 1234 => 'ezerkétszázharmincnégy',
41
+ 1999 => 'ezerkilencszázkilencvenkilenc',
42
+ 2000 => 'kétezer',
43
+ 2001 => 'kétezer-egy',
44
+ 22222 => 'huszonkétezer-kétszázhuszonkettő',
45
+ 100001 => 'százezer-egy',
46
+ 200000 => 'kétszázezer',
47
+ 2000000 => 'kétmillió',
48
+ 2200000 => 'kétmillió-kétszázezer',
49
+ 2200001 => 'kétmillió-kétszázezer-egy',
50
+ 2_000_000_001 => 'kétmilliárd-egy',
51
+ 2_000_000_000 => 'kétmilliárd',
52
+ 2_000_000_000_000 => 'kétbillió',
53
+ 2_000_200_000_000 => 'kétbillió-kétszázmillió',
54
+ 2_000_000_200_000 => 'kétbillió-kétszázezer',
55
+ 2_002_020_200_222 => 'kétbillió-kétmilliárd-húszmillió-kétszázezer-kétszázhuszonkettő',
56
+ 12_345_678_901_234_567_890 => 'tizenkéttrillió-háromszáznegyvenötbilliárd-hatszázhetvennyolcbillió-kilencszázegymilliárd-kétszázharmincnégymillió-ötszázhatvanhétezer-nyolcszázkilencven',
57
+ -12_345_678_901_234_567_890 => 'mínusz tizenkéttrillió-háromszáznegyvenötbilliárd-hatszázhetvennyolcbillió-kilencszázegymilliárd-kétszázharmincnégymillió-ötszázhatvanhétezer-nyolcszázkilencven'
58
+ }.each do |number,translation|
59
+ instance_eval <<-EOC
60
+ describe #{number}.to_s do
61
+ it "should equal to '#{translation}'" do
62
+ I18n.translate(#{number}).should == "#{translation}"
63
+ end
64
+ end
65
+ EOC
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'g3a')
2
+
3
+ module G3A::I18nHelper
4
+ end
5
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gbence-g3a_i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bence Golda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: svenfuchs-i18n
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.3
24
+ version:
25
+ description: Number localization extensions to the original (Ruby/Rails) I18n project.
26
+ email: gbence@algernon.hu
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - CHANGELOG
35
+ - Rakefile
36
+ - MIT-LICENSE
37
+ - README.rdoc
38
+ - g3a_i18n.gemspec
39
+ - lib/g3a.rb
40
+ - lib/g3a/i18n.rb
41
+ - init.rb
42
+ - locales/hu.yml
43
+ - spec/g3a_i18n_spec.rb
44
+ - spec/hu/float_spec.rb
45
+ - spec/hu/integer_spec.rb
46
+ - spec/spec_helper.rb
47
+ - Manifest
48
+ has_rdoc: true
49
+ homepage: http://github.com/gbence/g3a_i18n
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --line-numbers
53
+ - --inline-source
54
+ - --title
55
+ - G3A::I18n
56
+ - --main
57
+ - README.rdoc
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "1.2"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: g3a_i18n
75
+ rubygems_version: 1.2.0
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Number localization extensions to the original (Ruby/Rails) I18n project.
79
+ test_files: []
80
+