rich_pluralization 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ pkg/*
data/CHANGELOG ADDED
@@ -0,0 +1,14 @@
1
+ = Rich-pluralization CHANGELOG
2
+
3
+ == Version 1.0.2 (July 22, 2010)
4
+
5
+ * Specify the locales with relative paths
6
+ * Fixed error during gem initialization
7
+
8
+ == Version 1.0.1 (July 21, 2010)
9
+
10
+ * Added String inflection methods
11
+
12
+ == Version 1.0.0 (July 20, 2010)
13
+
14
+ * Initial release (extracted Rich-pluralization from E9s)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Paul Engel
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/README.textile ADDED
@@ -0,0 +1,203 @@
1
+
2
+ h1. Rich-pluralization
3
+
4
+ Enrichments (e9s) module for localized pluralization
5
+
6
+ h2. Introduction
7
+
8
+ Rich-pluralization is a module of E9s ("http://github.com/archan937/e9s":http://github.com/archan937/e9s) which provides localized pluralization in combination with i18n. Doing this enables you to only translate words in singular form as the module pluralizes the translation for you.
9
+
10
+ h3. Pluralization
11
+
12
+ As as example, in the Dutch locale you can do the following:
13
+
14
+ <pre>
15
+ >> "Appendix".pl
16
+ => "Appendices"
17
+ </pre>
18
+
19
+ Dutch pluralization rules are provided along with Rich-pluralization and has a 86% test coverage out of 54977 words which are provided by "INL (Instituut voor Nederlandse Lexicologie)":http://www.inl.nl. Unfortunately we can't distribute the complete list of nouns due to the closed nature of the database.
20
+
21
+ h3. Inflections
22
+
23
+ Rich-pluralization preserves the casing in the pluralized result:
24
+
25
+ <pre>
26
+ >> "huis".pl
27
+ => "huizen"
28
+ >> "Huis".pl
29
+ => "Huizen"
30
+ >> "HUIS".pl
31
+ => "HUIZEN"
32
+ </pre>
33
+
34
+ *Note*: @I18n.locale@ is @:nl@
35
+
36
+ h2. Installation
37
+
38
+ h3. Using Rich-pluralization as gem
39
+
40
+ Install the Rich-pluralization gem:
41
+
42
+ <pre>
43
+ sudo gem install rich_pluralization
44
+ </pre>
45
+
46
+ Add rich_pluralization in @environment.rb@ as a gem dependency:
47
+
48
+ <pre>
49
+ config.gem "rich_pluralization"
50
+ </pre>
51
+
52
+ h3. Using Rich-pluralization as plugin
53
+
54
+ Install the Rich-pluralization plugin:
55
+
56
+ <pre>
57
+ ./script/plugin install git://github.com/archan937/rich_pluralization.git
58
+ </pre>
59
+
60
+ Install i18n if you haven't already:
61
+
62
+ <pre>
63
+ sudo gem install i18n
64
+ </pre>
65
+
66
+ h3. Testing Rich-pluralization out-of-the-box
67
+
68
+ Set the default locale to @:nl@ in @environment.rb@:
69
+
70
+ <pre>
71
+ config.i18n.default_locale = :nl
72
+ </pre>
73
+
74
+ Run the Rails console:
75
+
76
+ <pre>
77
+ ./script/console
78
+ </pre>
79
+
80
+ Start pluralizing in Dutch:
81
+
82
+ <pre>
83
+ >> "Academicus".pl
84
+ => "Academici"
85
+ </pre>
86
+
87
+ h2. Usage
88
+
89
+ Just call the @pl@ method on string or symbols to pluralize.
90
+
91
+ *Note*: @I18n.locale@ is @:nl@
92
+
93
+ <pre>
94
+ >> "brief".pl
95
+ => "brieven"
96
+ >> "gebruiker".pl
97
+ => "gebruikers"
98
+ >> :museum.pl
99
+ => "musea"
100
+ >> "afspraak".pl
101
+ => "afspraken"
102
+ </pre>
103
+
104
+ h3. String methods
105
+
106
+ Rich-pluralization has enriched the String class with several inflection methods such as @upcase_first@, @cp_case@, @upcase_first!@ and @pluralize!@. Please visit "http://github.com/archan937/rich_pluralization/blob/master/lib/rich/pluralization/core/string/inflections.rb":http://github.com/archan937/rich_pluralization/blob/master/lib/rich/pluralization/core/string/inflections.rb to see all the methods.
107
+
108
+ h3. Adding pluralization rules / inflections
109
+
110
+ Rich-pluralization inflections resembles the inflections of @ActiveSupport::Inflector@. Unfortunately, specifying inflections within @config/initializers/inflections.rb@ influences your Rails application and thus causes great problems.
111
+
112
+ To specify pluralization rules for different locales. You have to use regular expressions and put them in @config/locales/language.yml@.
113
+
114
+ *Note*: specified in @config/locales/nl.yml@
115
+
116
+ <pre>
117
+ ---
118
+ nl:
119
+
120
+ e9s:
121
+ singular:
122
+ - rule: en$
123
+ replacement: ""
124
+
125
+ plural:
126
+ - rule: ee$
127
+ replacement: eeën
128
+
129
+ - rule: heid$
130
+ replacement: heden
131
+
132
+ - rule: (c|m|n|t)us$
133
+ replacement: \1i
134
+
135
+ - rule: | abc, acme, acne, (a|ë|i|o|u|y)$
136
+ replacement: \1's
137
+ exceptions: (ai|eau|ei|li|lieu|ooi|ou|shampoo|spray|vlo)$
138
+
139
+ - rule: (blad|kind)$
140
+ replacement: \1eren
141
+ exceptions: (aanrecht|advertentie)blad
142
+
143
+ - rule: (e|em|el|er|erd|aar|aard|um|eur|foon|oor|ier|en|ie|eau|show|festival|é)$
144
+ replacement: \1s
145
+
146
+ - rule: | (a|e|o|u)\1([^aeiou])$
147
+ replacement: \1\2en
148
+
149
+ - rule: | (aï|alia)(s),
150
+ ([^aeiou][aeiou])([^aeiou])$
151
+ replacement: \1\2\2en
152
+ exceptions: dal, pad, slot, vat, weg,
153
+ (blad|dag|dak|engel|gat|weg)$
154
+
155
+ - rule: f$
156
+ replacement: ven
157
+
158
+ - rule: s$
159
+ replacement: zen
160
+
161
+ - rule: $
162
+ replacement: en
163
+
164
+ irregular:
165
+ gelid: gelederen
166
+
167
+ uncountable:
168
+ - geld
169
+ - informatie
170
+ - rijst
171
+ </pre>
172
+
173
+ For a complete example, please open "http://github.com/archan937/rich_pluralization/blob/master/locales/nl.yml":http://github.com/archan937/rich_pluralization/blob/master/locales/nl.yml which contains Dutch inflections.
174
+
175
+ *Note*: The Dutch pluralization are tested on 54977 words provided by "INL (Instituut voor Nederlandse Lexicologie)":http://www.inl.nl. The test coverage is 86% (46366 words passed).
176
+
177
+ h2. Contact me
178
+
179
+ For support, remarks and requests please mail me at "paul.engel@holder.nl":mailto:paul.engel@holder.nl.
180
+
181
+ h2. Credit
182
+
183
+ This Rails gem / plugin depends on:
184
+
185
+ i18n<br>
186
+ "http://github.com/svenfuchs/i18n":http://github.com/svenfuchs/i18n
187
+
188
+ h2. ToDo's
189
+
190
+ * Complete the Dutch inflections
191
+ * Most String inflection methods are also defined in rich_i18n (keep it DRY)
192
+
193
+ h2. License
194
+
195
+ Copyright (c) 2010 Paul Engel, released under the MIT license
196
+
197
+ "http://holder.nl":http://holder.nl - "http://codehero.es":http://codehero.es - "http://gettopup.com":http://gettopup.com - "http://twitter.com/archan937":http://twitter.com/archan937 - "paul.engel@holder.nl":mailto:paul.engel@holder.nl
198
+
199
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
200
+
201
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
202
+
203
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require "rake"
2
+ require "rake/testtask"
3
+ require "rake/rdoctask"
4
+
5
+ begin
6
+ require "jeweler"
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "rich_pluralization"
9
+ gemspec.summary = "Enrichments (e9s) module for localized pluralization"
10
+ gemspec.description = "Rich-pluralization is a module of E9s (http://github.com/archan937/e9s) which provides localized pluralization in combination with i18n. Doing this enables you to only translate words in singular form as the module pluralizes the translation for you."
11
+ gemspec.email = "paul.engel@holder.nl"
12
+ gemspec.homepage = "http://github.com/archan937/rich_pluralization"
13
+ gemspec.author = "Paul Engel"
14
+
15
+ gemspec.add_dependency "i18n"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ desc "Default: run unit tests."
23
+ task :default => :test
24
+
25
+ desc "Test the rich_pluralization plugin."
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << "lib"
28
+ t.libs << "test"
29
+ t.pattern = "test/**/*_test.rb"
30
+ t.verbose = true
31
+ end
32
+
33
+ desc "Generate documentation for the rich_pluralization plugin."
34
+ Rake::RDocTask.new(:rdoc) do |rdoc|
35
+ rdoc.rdoc_dir = "rdoc"
36
+ rdoc.title = "Rich-pluralization"
37
+ rdoc.options << "--line-numbers" << "--inline-source"
38
+ rdoc.rdoc_files.include "README"
39
+ rdoc.rdoc_files.include "MIT-LICENSE"
40
+ rdoc.rdoc_files.include "lib/**/*.rb"
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "rails", "init")
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,4 @@
1
+
2
+ Dir[File.join(File.dirname(__FILE__), "core", "*.rb")].each do |file|
3
+ require file
4
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require "rich/pluralization/core/string/inflections"
3
+
4
+ class String
5
+ include Rich::Pluralization::Core::String::Inflections
6
+ end
@@ -0,0 +1,38 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Core
5
+ module String
6
+ module Inflections
7
+
8
+ # -- start FIXME: these methods are also defined in rich_i18n
9
+
10
+ def upcase_first
11
+ empty? ?
12
+ self :
13
+ self[0].chr.capitalize + self[1, size]
14
+ end
15
+
16
+ def cp_case(s)
17
+ send((:downcase unless s.dup.downcase!) || (:upcase unless s.dup.upcase!) || (:upcase_first unless s.dup.upcase_first!) || :to_s)
18
+ end
19
+
20
+ def upcase_first!
21
+ self == (result = upcase_first) ? nil : replace(result)
22
+ end
23
+
24
+ def cp_case!(s)
25
+ self == (result = cp_case(s)) ? nil : replace(result)
26
+ end
27
+
28
+ # -- end
29
+
30
+ def pl(count = nil)
31
+ Rich::Pluralization::Inflector.pluralize self, count
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require "rich/pluralization/core/symbol/inflections"
3
+
4
+ class Symbol
5
+ include Rich::Pluralization::Core::Symbol::Inflections
6
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Core
5
+ module Symbol
6
+ module Inflections
7
+
8
+ def pl(count = nil)
9
+ to_s.pl count
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Engine
5
+ extend self
6
+
7
+ def init(test_class = nil)
8
+ if test_class
9
+ test_locale = test_class.name.match(/(Rich\:\:Pluralization\:\:Test\:\:Locales\:\:)(\w+)/).captures[1].downcase.to_sym
10
+
11
+ I18n.load_path = [File.join(File.dirname(__FILE__), "..", "..", "..", "locales", "#{test_locale}.yml")]
12
+ else
13
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), "..", "..", "..", "locales", "*.yml")]
14
+ end
15
+
16
+ I18n.backend.reload!
17
+ Rich::Pluralization::Inflector.inflections.reset_attrs if test_class
18
+
19
+ initial_locale = I18n.locale
20
+
21
+ I18n.backend.available_locales.each do |locale|
22
+ I18n.locale = locale
23
+
24
+ Rich::Pluralization::Inflector.inflections locale do |inflections|
25
+ (I18n.t! "e9s" rescue []).each do |type, entries|
26
+ entries.each do |inflection|
27
+ inflections.send *[type, inflection].flatten
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ I18n.locale = initial_locale
34
+
35
+ test_locale
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ Rich::Pluralization::Engine.init
@@ -0,0 +1,58 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Inflector
5
+ extend self
6
+
7
+ def inflections(locale = nil)
8
+ Inflections.instance.locale = locale
9
+ if block_given?
10
+ yield Inflections.instance
11
+ else
12
+ Inflections.instance
13
+ end
14
+ end
15
+
16
+ def singularize(word)
17
+ inflect :singulars, word
18
+ end
19
+
20
+ def pluralize(word, count = nil)
21
+ count == 1 ? singularize(word) : inflect(:plurals, word)
22
+ end
23
+
24
+ private
25
+
26
+ [:singulars, :plurals, :irregulars, :uncountables].each do |type|
27
+ define_method type do
28
+ (Inflections.instance.send(type)[I18n.locale] || (type == :uncountables ? [] : {}))
29
+ end
30
+ end
31
+
32
+ def inflect(type, word)
33
+ return word if uncountable?(word) or irregular_counterpart?(type, word)
34
+
35
+ if irregular = irregulars[word.downcase]
36
+ return irregular.cp_case(word)
37
+ end
38
+
39
+ send(type).each do |inflection|
40
+ if result = inflection.inflect!(word)
41
+ return result.cp_case(word)
42
+ end
43
+ end
44
+
45
+ word
46
+ end
47
+
48
+ def uncountable?(word)
49
+ uncountables.include?(word.downcase)
50
+ end
51
+
52
+ def irregular_counterpart?(type, word)
53
+ irregulars.send({:singulars => :keys, :plurals => :values}[type]).include?(word.downcase)
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,136 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Inflector
5
+
6
+ class Inflections
7
+ include Singleton
8
+
9
+ attr_reader :singulars, :plurals, :irregulars, :uncountables
10
+ attr_writer :locale
11
+
12
+ def initialize
13
+ set_attrs
14
+ end
15
+
16
+ def set_attrs
17
+ %w(singulars plurals irregulars uncountables).each do |x|
18
+ instance_variable_set :"@#{x}", {}
19
+ end
20
+ @locale = I18n.default_locale
21
+ end
22
+ alias :reset_attrs :set_attrs
23
+
24
+ def singular(*args)
25
+ add_inflection :singulars, *args
26
+ end
27
+
28
+ def plural(*args)
29
+ add_inflection :plurals , *args
30
+ end
31
+
32
+ def irregular(*args)
33
+ locale, s, pl = extract_args(*args)
34
+ (@irregulars[locale] ||= {})[s.to_s] = pl
35
+ end
36
+
37
+ def uncountable(*args)
38
+ locale, words = extract_args(*args)
39
+ (@uncountables[locale] ||= []).concat [words].flatten
40
+ end
41
+
42
+ def dump
43
+ puts "SINGULARS : #{@singulars .inspect}"
44
+ puts "PLURAL : #{@plurals .inspect}"
45
+ puts "IRREGULARS : #{@irregulars .inspect}"
46
+ puts "UNCOUNTABLES: #{@uncountables.inspect}"
47
+ puts "LOCALE : #{@locale .inspect}"
48
+ end
49
+
50
+ private
51
+
52
+ def add_inflection(type, *args)
53
+ locale, values = extract_args(*args)
54
+ inflections = instance_variable_get(:"@#{type}")
55
+ inflection = Inflection.build values
56
+
57
+ (inflections[locale] ||= []).push inflection
58
+ end
59
+
60
+ def extract_args(*args)
61
+ locale = begin
62
+ if args.last.is_a?(Symbol)
63
+ args.pop
64
+ elsif args.last.is_a?(Hash)
65
+ args.delete(:locale)
66
+ end
67
+ end
68
+
69
+ args.unshift [locale, @locale].detect{|x| x.is_a?(Symbol)} || I18n.default_locale
70
+ end
71
+
72
+ Inflection = Struct.new(:rule, :replacement, :exceptions) do
73
+
74
+ def self.build(*args)
75
+ self.new *(args.first.is_a?(Hash) ? args.first.values_at(*%w(rule replacement exceptions)) : args)
76
+ end
77
+
78
+ def rule
79
+ self[:rule].downcase
80
+ end
81
+
82
+ def exceptions
83
+ (self[:exceptions] || "").downcase.split(",")
84
+ end
85
+
86
+ def exception?(word)
87
+ exceptions.any?{|e| match?(word, e)}
88
+ end
89
+
90
+ def match?(word, pattern)
91
+ w, p = word.downcase, parse_pattern(pattern)
92
+ p.is_a?(Regexp) ? !!w.match(p) : (w == p)
93
+ end
94
+
95
+ def inflect(word)
96
+ if exception?(word)
97
+ word
98
+ else
99
+ rule.split(",").collect do |x|
100
+ word.dup.gsub! parse_pattern(x, true), self[:replacement]
101
+ end.detect{|x| !x.nil?} || word
102
+ end
103
+ end
104
+
105
+ def inflect!(word)
106
+ (result = inflect(word)) == word ? nil : result
107
+ end
108
+
109
+ def inspect
110
+ to_hash.inspect
111
+ end
112
+
113
+ def to_hash
114
+ Hash[*members.zip(values).flatten]
115
+ end
116
+
117
+ private
118
+
119
+ def parse_pattern(s, force_regexp = false)
120
+ s.strip!
121
+ if force_regexp and not regexp?(s)
122
+ s = "^(#{s.strip})$"
123
+ end
124
+ regexp?(s) ? Regexp.new(s, Regexp::IGNORECASE) : s
125
+ end
126
+
127
+ def regexp?(s)
128
+ !!s.match(/[\^\$\(\)]/)
129
+ end
130
+
131
+ end
132
+ end
133
+
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require "rich/pluralization/core"
3
+ require "rich/pluralization/engine"
data/locales/nl.yml ADDED
@@ -0,0 +1,148 @@
1
+ ---
2
+ nl:
3
+
4
+ e9s:
5
+ singular:
6
+ - rule: en$
7
+ replacement: ""
8
+
9
+ plural:
10
+ - rule: cees$
11
+ replacement: cesen
12
+
13
+ - rule: chys$
14
+ replacement: chen
15
+
16
+ - rule: (c|m|n|t)us$
17
+ replacement: \1i
18
+ exceptions: | abortus, anus
19
+
20
+ - rule: (c|d|e|i|t|tr|v)um$
21
+ replacement: \1a
22
+ exceptions: (anthu|aqua)rium
23
+
24
+ - rule: ee$
25
+ replacement: eeën
26
+ exceptions: abonnee
27
+
28
+ - rule: eum$
29
+ replacement: ea
30
+
31
+ - rule: heid$
32
+ replacement: heden
33
+
34
+ - rule: dix$
35
+ replacement: dices
36
+
37
+ - rule: lid$
38
+ replacement: leden
39
+
40
+ - rule: (nuens)is$
41
+ replacement: \1es
42
+
43
+ - rule: stad$
44
+ replacement: steden
45
+
46
+ - rule: | abc, acme, acne, (a|ë|i|o|u|y)$
47
+ replacement: \1's
48
+ exceptions: (ai|eau|ei|li|lieu|ooi|ou|shampoo|spray|vlo)$
49
+
50
+ - rule: (blad|kind)$
51
+ replacement: \1eren
52
+ exceptions: (aanrecht|advertentie)blad
53
+
54
+ - rule: (ige)$
55
+ replacement: \1n
56
+
57
+ - rule: (allerg|bat|scop|fantas|fib|log|mal|metr|nest|nom|or|path)ie$
58
+ replacement: \1ieën
59
+ exceptions: approbatie
60
+
61
+ - rule: (alka|o)(l)ie?$
62
+ replacement: \1\2iën
63
+
64
+ - rule: (schip)$
65
+ replacement: schepen
66
+
67
+ - rule: (abort|act|acquisit|advis|amat|inspect)(eur)$
68
+ replacement: \1\2s
69
+
70
+ - rule: | (gevoel)$
71
+ replacement: \1ens
72
+
73
+ - rule: | (accent|agent)([-\s])(\w+)
74
+ replacement: \1s\2\3s
75
+
76
+ - rule: advocaat-(\w+)
77
+ replacement: advocaten-\1
78
+
79
+ - rule: (bike|borstel|distel|kabel|prikkel|winkel)$
80
+ replacement: \1s
81
+
82
+ - rule: | abraham, account, act, addict, adoptiefzoon, ah, ai, air, airstrip, alligator, amant, ampersand, analysator, animator, anklet, antiquair, arbeidspool,
83
+ (aar|aard|age|ah|bag|beignet|bike|chef|chon|club|e|é|eau|eër|el|em|en|eon|er|erd|festival|filet|film)$,
84
+ (foon|ie|ier|iër|kon|lation|lieu|lotion|marshal|nal|oir|oor|ose|ou|our|ount|pon|poo|prop|rak|rant|rn|sar|sion|sit|show|sor|spray)$,
85
+ (sun|tank|tant|test|um|view)$
86
+ replacement: \1s
87
+ exceptions: | a-attest, aar, aardster, aarlenaar, acceptant, adoptant, afgifte, albe, alge, allofoon, amandel, amarant, ante, antifoon, antipode, aquarel, arelaar,
88
+ ((aan|ge|ver|voor).*de|afe|ate|bel|bier|cel|contractant|denkende|deur|dier|dienaar|dode|eem|een|eel|eer|einde)$,
89
+ (ene|engel|gezwel|gier|iel|iem|isme|ïsme|jaar|ke|kel|krant|lem|lier|maatregel|migrant)$,
90
+ (model|officier|oïde|oor|oen|oer|eose|penaar|rivale|schel|schijnsel|sien|spier|ste|stel|stem|taar|tenaar|tier|tride|uaar|vaar|valide|verwante|vrage|zijde)$
91
+
92
+ - rule: (a|e|o|u)\1f$
93
+ replacement: \1ven
94
+ exceptions: (graaf|soof)$
95
+
96
+ - rule: (a|e|o|u)\1s$
97
+ replacement: \1zen
98
+
99
+ - rule: (ver|cijn)s$
100
+ replacement: \1zen
101
+
102
+ - rule: | (a|e|o|u)\1([^aeiou])$
103
+ replacement: \1\2en
104
+
105
+ - rule: | (aï|alia)(s),
106
+ ([^aeiou][aeiou])([^aeioux])$,
107
+ ^([aeiou])([^aeioux])$
108
+ replacement: \1\2\2en
109
+ exceptions: alcohol, amandel, apostel, dal, pad, slot, vat,
110
+ (blad|dag|dak|engel|gat|god|hertog|ij|kel|oorlog|proton|regel|schijnsel|schot|slag|tor|weg)$
111
+
112
+ - rule: (de|ene)$
113
+ replacement: \1n
114
+
115
+ - rule: f$
116
+ replacement: ven
117
+ exceptions: morf$
118
+
119
+ - rule: | ([aeiou]|aar|eur|ij)s$
120
+ replacement: \1zen
121
+ exceptions: (kaars|kruis)$
122
+
123
+ - rule: (lo)$
124
+ replacement: \1oien
125
+
126
+ - rule: (wei|zij)$
127
+ replacement: \1den
128
+
129
+ - rule: (e)$
130
+ replacement: \1n
131
+
132
+ - rule: $
133
+ replacement: en
134
+
135
+ irregular:
136
+ "accountant-administratieconsulent": "accountants-administratieconsulenten"
137
+ "agens" : "agentia"
138
+ "akkerman" : "akkerlieden"
139
+ "album amicorum" : "alba amicorum"
140
+ "ambachtsman" : "ambachtslieden"
141
+ "anchorman" : "anchormen"
142
+ "anchorwoman" : "anchorwomen"
143
+
144
+ uncountable:
145
+ - geld
146
+ - informatie
147
+ - rijst
148
+ - afrokapsel # according to WNT
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "rich_pluralization"
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rich_pluralization}
8
+ s.version = "1.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Engel"]
12
+ s.date = %q{2010-07-22}
13
+ s.description = %q{Rich-pluralization is a module of E9s (http://github.com/archan937/e9s) which provides localized pluralization in combination with i18n. Doing this enables you to only translate words in singular form as the module pluralizes the translation for you.}
14
+ s.email = %q{paul.engel@holder.nl}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "CHANGELOG",
21
+ "MIT-LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "init.rb",
26
+ "install.rb",
27
+ "lib/rich/pluralization/core.rb",
28
+ "lib/rich/pluralization/core/string.rb",
29
+ "lib/rich/pluralization/core/string/inflections.rb",
30
+ "lib/rich/pluralization/core/symbol.rb",
31
+ "lib/rich/pluralization/core/symbol/inflections.rb",
32
+ "lib/rich/pluralization/engine.rb",
33
+ "lib/rich/pluralization/inflector.rb",
34
+ "lib/rich/pluralization/inflector/inflections.rb",
35
+ "lib/rich_pluralization.rb",
36
+ "locales/nl.yml",
37
+ "rails/init.rb",
38
+ "rich_pluralization.gemspec",
39
+ "tasks/rich_pluralization_tasks.rake",
40
+ "test/core/string/inflections_test.rb",
41
+ "test/engine_test.rb",
42
+ "test/locales/nl/inflections_test.rb",
43
+ "test/setup.rb",
44
+ "test/test_helper.rb",
45
+ "uninstall.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/archan937/rich_pluralization}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.7}
51
+ s.summary = %q{Enrichments (e9s) module for localized pluralization}
52
+ s.test_files = [
53
+ "test/core/string/inflections_test.rb",
54
+ "test/engine_test.rb",
55
+ "test/locales/nl/inflections_test.rb",
56
+ "test/setup.rb",
57
+ "test/test_helper.rb"
58
+ ]
59
+
60
+ if s.respond_to? :specification_version then
61
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<i18n>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<i18n>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,11 @@
1
+
2
+ namespace :rich_pluralization do
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.verbose = false
6
+ t.test_files = FileList.new("vendor/plugins/rich_pluralization/test/**/*.rb") do |list|
7
+ # list.exclude "foo.rb"
8
+ end
9
+ end
10
+ Rake::Task["rich_pluralization:test"].comment = "Run the rich_pluralization plugin tests"
11
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "test_helper.rb"))
2
+
3
+ module Rich
4
+ module Pluralization
5
+ module Test
6
+ module Core
7
+ module String
8
+
9
+ class InflectionsTest < ActiveSupport::TestCase
10
+ setup do
11
+ include Setup
12
+ I18n.locale = ::Rich::Pluralization::Engine.init(Locales::NL)
13
+ end
14
+
15
+ # test "pl" do
16
+ # assert true
17
+ # end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ module Rich
4
+ module Pluralization
5
+ module Test
6
+
7
+ class EngineTest < ActiveSupport::TestCase
8
+ setup do
9
+ include Setup
10
+ I18n.locale = ::Rich::Pluralization::Engine.init(Locales::NL)
11
+ end
12
+
13
+ # test "something" do
14
+ # assert true
15
+ # end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "test_helper.rb"))
2
+ require "csv"
3
+
4
+ module Rich
5
+ module Pluralization
6
+ module Test
7
+ module Locales
8
+ module NL
9
+
10
+ class InflectionsTest < ActiveSupport::TestCase
11
+ setup do
12
+ include Setup
13
+ I18n.locale = ::Rich::Pluralization::Engine.init(self)
14
+ end
15
+
16
+ test "dutch_pluralizations" do
17
+ assert_equal "vinnen" , "vin".pl
18
+ assert_equal "tassen" , "tas".pl
19
+ assert_equal "telefoons" , "telefoon".pl
20
+ assert_equal "vragen" , "vraag".pl
21
+ assert_equal "huizen" , "huis".pl
22
+ assert_equal "brieven" , "brief".pl
23
+ assert_equal "broeken" , "broek".pl
24
+ assert_equal "tekens" , "teken".pl
25
+ assert_equal "begrafenissen" , "begrafenis".pl
26
+ assert_equal "diners" , "diner".pl
27
+ assert_equal "jubilea" , "jubileum".pl
28
+ assert_equal "festivals" , "festival".pl
29
+ assert_equal "vazen" , "vaas".pl
30
+ # assert_equal "vragen & antwoorden", "vraag & antwoord".pl
31
+ end
32
+
33
+ test "wnt_list" do
34
+ if File.exist?(filename = File.join(File.dirname(__FILE__), "words.csv"))
35
+
36
+ CSV.open(filename, "r", ",") do |word|
37
+ assert_equal word[1], word[0].pl unless word[1].match(/NULL/)
38
+ end
39
+
40
+ # passed, counted = 0, 0
41
+ #
42
+ # CSV.open(File.join(File.dirname(__FILE__), "words.csv"), "r", ",") do |word|
43
+ # unless word[1].match(/NULL/)
44
+ # counted = counted + 1
45
+ # passed = passed + 1 if word[1] == word[0].pl
46
+ # end
47
+ # end
48
+ #
49
+ # puts "Dutch word pluralization test results:"
50
+ # puts "Passed #{passed} of #{counted}"
51
+
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
data/test/setup.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ module Rich
3
+ module Pluralization
4
+ module Test
5
+ module Setup
6
+
7
+ def self.included(base)
8
+ require "rich/pluralization"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ require "rubygems"
2
+ require "active_support"
3
+ require "active_support/test_case"
4
+
5
+ require File.join(File.dirname(__FILE__), "setup.rb")
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rich_pluralization
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 2
9
+ version: 1.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Paul Engel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-22 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: i18n
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Rich-pluralization is a module of E9s (http://github.com/archan937/e9s) which provides localized pluralization in combination with i18n. Doing this enables you to only translate words in singular form as the module pluralizes the translation for you.
34
+ email: paul.engel@holder.nl
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.textile
41
+ files:
42
+ - .gitignore
43
+ - CHANGELOG
44
+ - MIT-LICENSE
45
+ - README.textile
46
+ - Rakefile
47
+ - VERSION
48
+ - init.rb
49
+ - install.rb
50
+ - lib/rich/pluralization/core.rb
51
+ - lib/rich/pluralization/core/string.rb
52
+ - lib/rich/pluralization/core/string/inflections.rb
53
+ - lib/rich/pluralization/core/symbol.rb
54
+ - lib/rich/pluralization/core/symbol/inflections.rb
55
+ - lib/rich/pluralization/engine.rb
56
+ - lib/rich/pluralization/inflector.rb
57
+ - lib/rich/pluralization/inflector/inflections.rb
58
+ - lib/rich_pluralization.rb
59
+ - locales/nl.yml
60
+ - rails/init.rb
61
+ - rich_pluralization.gemspec
62
+ - tasks/rich_pluralization_tasks.rake
63
+ - test/core/string/inflections_test.rb
64
+ - test/engine_test.rb
65
+ - test/locales/nl/inflections_test.rb
66
+ - test/setup.rb
67
+ - test/test_helper.rb
68
+ - uninstall.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/archan937/rich_pluralization
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Enrichments (e9s) module for localized pluralization
101
+ test_files:
102
+ - test/core/string/inflections_test.rb
103
+ - test/engine_test.rb
104
+ - test/locales/nl/inflections_test.rb
105
+ - test/setup.rb
106
+ - test/test_helper.rb