File: README.rdoc

package info (click to toggle)
ruby-i18n-inflector-rails 1.0.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 288 kB
  • ctags: 91
  • sloc: ruby: 472; makefile: 2
file content (200 lines) | stat: -rw-r--r-- 6,077 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
= Simple I18n Inflector for Rails

<b>i18n-inflector-rails version <tt>1.0</tt></b> (<b><tt>Rain</tt></b>)



* https://rubygems.org/gems/i18n-inflector-rails
* https://github.com/siefca/i18n-inflector-rails/tree
* mailto:pw@gnu.org

== Summary

This Rails plug-in contains bindings for the I18n Inflector module for Ruby's I18n.
It overwrites the <tt>translate()</tt> method from Rails in a way that it will
interpolate additional inflection tokens present in translations.
These tokens may appear in *patterns* which are contained within
<tt>@{</tt> and <tt>}</tt> symbols.

== Why?

It's intended to be used in a projects where tranlations are performed
by many people, yet there is a need to inflect sentences or words by
user's gender, person or other data.

To achieve similar functionality lambdas can be used but including
Proc objects in translations may be considered unsafe.

If you have a troop of happy translators that shouldn't have the
ability to execute any code yet you need some simple inflection
then this plug-in might help you.

== Synopsis

  translate('.welcome')

===== In a YAML file:

  en:
    welcome:  "Dear @{f:Lady|m:Sir|n:You|All}"
  
  en:
    i18n:
      inflections:
        gender:
          f:        "female"
          m:        "male"
          n:        "neuter"
          female:   @f
          male:     @m
          neuter:   @n
          man:      @male
          woman:    @female
          default:  n

===== In a controller:

  class ApplicationController < ActionController::Base
    
    inflection_method :gender
    
    # assuming that @gender is set somewhere
    def gender
      @gender || nil
    end
  
  end

  class UsersController < ApplicationController
    
    # t() will call method gender() from the current context
    # to get the inflection token
    def say_welcome
      t('welcome')
      # => "Dear Sir"
    end
  
  end
  
== Description

You can create your own kinds (gender, title, person, time, author, etc.)
of tokens to group them in a meaningful, semantical sets.

This plug-in adds {I18n::Inflector::Rails::ClassMethods#inflection_method inflection_method},
{I18n::Inflector::Rails::ClassMethods#no_inflection_method no_inflection_method}
and {I18n::Inflector::Rails::ClassMethods#no_inflection_method_for no_inflection_method_for} clauses
that can be used in controllers and views. Using that clauses makes it easy to register
methods that will be called to obtain certain inflection options.
It is also possible to set up an inflection method for a so called
strict kind commonly used in a so called named and complex patterns.

This plug-in uses i18n-inflector[https://rubygems.org/gems/i18n-inflector]
module which allows passing inflection options to the translate method.
You may find I18n Inflector's API and a default object very helpful since
they allow you to read inflection data in many different ways. You might,
for example, use it to generate forms containing lists of languages that are using
inflection, or to view all known inflection kinds or tokens assigned to them.

To access the Inflector object bound to default I18n backend use:
  I18n.inflector

== Note about YAML parsing

The previous example is not compatible with Psych parser, which is used
by Rails 3. There are two ways to solve that problem.

First is to change a YAML file and replace any value that has
special meaning with a symbol:

  en:
    i18n:
      inflections:
        gender:
          f:        "female"
          m:        "male"
          n:        "neuter"
          female:   :@f
          male:     :@m
          neuter:   :@n
          man:      :@male
          woman:    :@female
          default:  :n
  
Second way is to use other parser by adding to +config/boot.rb+:

  require 'yaml'
  YAML::ENGINE.yamler = 'syck'

== Requirements

* i18n-inflector[https://rubygems.org/gems/i18n-inflector]
* actionpack[https://rubygems.org/gems/actionpack]
* rake[https://rubygems.org/gems/rake]
* rubygems[http://docs.rubygems.org/]

== Download

==== Source code

* https://github.com/siefca/i18n-inflector-rails/tree
* <tt>git clone git://github.com/siefca/i18n-inflector-rails.git</tt>

==== Gem

* https://rubygems.org/gems/i18n-inflector-rails

== Installation

* <tt>gem install i18n-inflector-rails</tt>

== Specs

You can run RSpec examples both with

* <tt>rake spec</tt> or just <tt>rake</tt>
* run a test file directly, e.g. <tt>ruby -Ilib -Ispec spec/inflector_spec.rb</tt>

== More information

See {I18n::Inflector::Rails::ClassMethods} to learn how to use +inflection_method+ and +no_inflection_method+.

See {I18n::Inflector::Rails::InflectedTranslate} to learn about using the translation wrapper.

See {I18n::Inflector::InflectionOptions} to know more about switches that can be used to control the engine.

See the {whole documentation}[http://rubydoc.info/gems/i18n-inflector-rails/] for more information.

To know how the basics and to learn more about Inflector that is used by this plug-in
see {I18n Inflector documentation}[http://rubydoc.info/gems/i18n-inflector].

== Credits

* {Heise Media Polska}[http://www.heise-online.pl/] supports Free Software and has
  contributed to this library by paying for my food during the coding.

* {Ryan Bates}[https://github.com/dmilisic/] made this package Rails 4 compatible. Thanks!

== Donations

If you like my work you can send me some BitCoins:

* <tt>13wZbBjs6yQQuAb3zjfHubQSyer2cLAYzH</tt>

Or you can endorse my skills on LinkedIn:

* {pl.linkedin.com/in/pwilk}[http://www.linkedin.com/profile/view?id=4251568#profile-skills]

== License

Copyright (c) 2011-2013 by Paweł Wilk.

i18n-inflector-rails is copyrighted software owned by Paweł Wilk (pw@gnu.org).
You may redistribute and/or modify this software as long as you
comply with either the terms of the LGPL (see {file:LGPL-LICENSE}),
or Ruby's license (see {file:COPYING}).

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.