From 5b47d7bfcc241c6117d3ecf71c68bac90eac05fa 2006-07-29 19:53:34 From: Jean-Philippe Lang Date: 2006-07-29 19:53:34 Subject: [PATCH] git-svn-id: http://redmine.rubyforge.org/svn/trunk@13 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/redmine/vendor/plugins/localization/README b/redmine/vendor/plugins/localization/README deleted file mode 100644 index 0996906..0000000 --- a/redmine/vendor/plugins/localization/README +++ /dev/null @@ -1,85 +0,0 @@ -= Localization Plugin for Rails - -This plugin provides a simple, gettext-like method to -provide localizations. - -== Features - - * Any number of languages or locales - * Simple method to defines singluar/plural translations - * Can use lambdas to provide Ruby-code based dynamic translations - * Customizable for different instances of the application - -== Usage - -If the localization plugin is installed, it is used automatically. - -You need to create a /lang dir in your RAILS_ROOT. - -The recommended way to use it is to create files that are named -like the languages you define in them (but you can put everything in -one big file too.) - -For instance-customizable strings, add overrides in files you -put in /lang/custom. - -=== Simple example: - -Create a file /lang/translations.rb: - - Localization.define('de') do |l| - l.store 'yes', 'Ja' - l.store 'no', 'Nein' - end - - Localization.define('fr') do |l| - l.store 'yes', 'oui' - l.store 'no', 'non' - end - -In your controller or application.rb: - - Localization.lang = 'de' # or 'fr' - -In your view: - - <%=_ 'yes' %> - <%=_ 'no' %> - -Because the _ method is simply an extension to Object, you -can use it anywhere (models/controllers/views/libs). - -=== Extended example: - -Create a file /lang/default.rb with following contents: - - Localization.define do |l| - l.store '(time)', lambda { |t| t.strftime('%I:%M%p') } - end - -Create a file /lang/de_DE.rb with following contents: - - Localization.define('de_DE') do |l| - l.store '%d entries', ['Ein Eintrag', '%d Einträge'] - l.store '(time)', lambda { |t| t.strftime('%H:%M') } - end - -In your controller or application.rb: - - Localization.lang = 'de_DE' - -In your view: - - <%=_ '%d entries', 1 %> # singular variant is chosen - <%=_ '%d entries', 4 %> # plural variant is chosen - <%=_ '(time)', Time.now %> # call the block with a parameter - -== Translation file guesstimation - -You can generate a guesstimation of all strings needed to be -translated in your views by first adding the _('blah') syntax -everywhere and then calling: - - puts Localization.generate_l10n_file - -in the Rails console. \ No newline at end of file diff --git a/redmine/vendor/plugins/localization/init.rb b/redmine/vendor/plugins/localization/init.rb deleted file mode 100644 index 72ed7b9..0000000 --- a/redmine/vendor/plugins/localization/init.rb +++ /dev/null @@ -1,3 +0,0 @@ -require "#{directory}/lib/localization.rb" - -Localization.load \ No newline at end of file diff --git a/redmine/vendor/plugins/localization/lib/localization.rb b/redmine/vendor/plugins/localization/lib/localization.rb deleted file mode 100644 index d1756b1..0000000 --- a/redmine/vendor/plugins/localization/lib/localization.rb +++ /dev/null @@ -1,57 +0,0 @@ -# Original Localization plugin for Rails can be found at: -# http://mir.aculo.us/articles/2005/10/03/ruby-on-rails-i18n-revisited -# -# Slightly edited by Jean-Philippe Lang -# - added @@langs and modified self.define method to maintain an array of available -# langages with labels, eg. { 'en' => 'English, 'fr' => 'French } -# - modified self.generate_l10n_file method to retrieve already translated strings -# - -module Localization - mattr_accessor :lang, :langs - - @@l10s = { :default => {} } - @@lang = :default - @@langs = {} - - def self._(string_to_localize, *args) - translated = @@l10s[@@lang][string_to_localize] || string_to_localize - return translated.call(*args).to_s if translated.is_a? Proc - if translated.is_a? Array - translated = if translated.size == 3 - translated[args[0]==0 ? 0 : (args[0]>1 ? 2 : 1)] - else - translated[args[0]>1 ? 1 : 0] - end - end - sprintf translated, *args - end - - def self.define(lang = :default, name = :default) - @@l10s[lang] ||= {} - @@langs[lang] = [ name ] - yield @@l10s[lang] - end - - def self.load - Dir.glob("#{RAILS_ROOT}/lang/*.rb"){ |t| require t } - Dir.glob("#{RAILS_ROOT}/lang/custom/*.rb"){ |t| require t } - end - - # Generates a best-estimate l10n file from all views by - # collecting calls to _() -- note: use the generated file only - # as a start (this method is only guesstimating) - def self.generate_l10n_file(lang) - "Localization.define('en_US') do |l|\n" << - Dir.glob("#{RAILS_ROOT}/app/views/**/*.rhtml").collect do |f| - ["# #{f}"] << File.read(f).scan(/<%.*[^\w]_\s*[\(]+[\"\'](.*?)[\"\'][\)]+/) - end.uniq.flatten.collect do |g| - g.starts_with?('#') ? "\n #{g}" : " l.store '#{g}', '#{@@l10s[lang][g]}'" - end.uniq.join("\n") << "\nend" - end - -end - -class Object - def _(*args); Localization._(*args); end -end \ No newline at end of file