~david4dev/libplugin-loader-ruby/trunk

« back to all changes in this revision

Viewing changes to lib/plugin/loader.rb

  • Committer: david4dev at gmail
  • Date: 2010-09-29 16:40:25 UTC
  • Revision ID: david4dev@gmail.com-20100929164025-pijeemqawpwfwk02
Implemented translations for plugins using ruby gettext (experimental)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#Depends: libjson-ruby
24
24
require 'json'
 
25
#Depends: libgettext-ruby
 
26
require 'gettext'
25
27
 
26
28
module Plugin
27
29
 
153
155
                        end
154
156
                        @plugins[type].keys
155
157
                end
156
 
                
 
158
                #Returns true if the plugin is translatable (in the metadata file "translatable" : true),
 
159
                #false otherwise
 
160
                def translatable? name, type
 
161
                        etc(name, type)['translatable'] || false
 
162
                end
 
163
                #Returns the translation text domain of the plugin.
 
164
                #(specified by the "textdomain" key in the metadata file)
 
165
                def textdomain name, type
 
166
                        etc(name, type)['textdomain'] || false
 
167
                end
 
168
                #Translates a string for a particular plugin.
 
169
                def translate name, type, str
 
170
                        begin
 
171
                                translator_class = Class.new do
 
172
                                        include GetText
 
173
                                        bindtextdomain textdomain(name, type)
 
174
                                        def translate str
 
175
                                                _(str)
 
176
                                        end
 
177
                                end
 
178
                                translator_class.new.translate(str)
 
179
                        rescue Exception=>e
 
180
                                str
 
181
                        end
 
182
                end
157
183
                #A more descriptive name (eg. file-compressor => Compress File)
158
184
                #Imagine: what would be written on a button that excecutes the plugin.
159
185
                def long_name name, type
160
 
                        etc(name, type)['long_name'] || ''
 
186
                        translate( name, type,
 
187
                                etc(name, type)['long_name'] || ''
 
188
                        )
161
189
                end
162
190
                #A short description of what the plugin does.
163
191
                #(eg. file-compressor => Compresses the file so that it takes up less disk space)
164
192
                #Imagine: a tooltip for a button that excecutes the plugin.
165
193
                def summary name, type
166
 
                        etc(name, type)['summary'] || ''
 
194
                        translate( name, type,
 
195
                                etc(name, type)['summary'] || ''
 
196
                        )
167
197
                end
168
198
                #A more detailed description.
169
199
                #(eg. file-compressor => Compresses the file using gzip so that it takes up less
170
200
                #disk space. Options are available to use bzip2 or lzma instead for a higher
171
201
                #compression ratio.)
172
202
                def description name, type
173
 
                        etc(name, type)['description'] || ''
 
203
                        translate( name, type,
 
204
                                etc(name, type)['description'] || ''
 
205
                        )
174
206
                end
175
207
                #A list of the people who created the plugin.
176
208
                def authors name, type
184
216
                def homepage name, type
185
217
                        etc(name, type)['homepage'] || ''
186
218
                end
187
 
 
188
 
                #Hopefully, in the future, plugins can have translatable
189
 
                #long_name/summary/description etc. (how???).
190
 
                #This will return a true or false value that describes whether
191
 
                #or not the plugin can be translated. Currently returns false regardless.
192
 
                def translatable? name, type
193
 
                        false
194
 
                end
195
219
        end
196
220
 
197
221
end