diff --git a/gloc-1.2.0/vendor/plugins/gloc-1.1.0/CHANGELOG b/gloc-1.2.0/vendor/plugins/gloc-1.1.0/CHANGELOG deleted file mode 100644 index 6392d7cbe..000000000 --- a/gloc-1.2.0/vendor/plugins/gloc-1.1.0/CHANGELOG +++ /dev/null @@ -1,19 +0,0 @@ -== Version 1.1 (28 May 2006) - -* The charset for each and/or all languages can now be easily configured. -* Added a ActionController filter that auto-detects the client language. -* The rake task "sort" now merges lines that match 100%, and warns if duplicate keys are found. -* Rule support. Create flexible rules to handle issues such as pluralization. -* Massive speed and stability improvements to development mode. -* Added Russian strings. (Thanks to Evgeny Lineytsev) -* Complete RDoc documentation. -* Improved helpers. -* GLoc now configurable via get_config and set_config -* Added an option to tell GLoc to output various verbose information. -* More useful functions such as set_language_if_valid, similar_language -* GLoc's entire internal state can now be backed up and restored. - - -== Version 1.0 (17 April 2006) - -* Initial public release. diff --git a/gloc-1.2.0/vendor/plugins/gloc-1.1.0/doc/classes/ActionController/Filters/ClassMethods.html b/gloc-1.2.0/vendor/plugins/gloc-1.1.0/doc/classes/ActionController/Filters/ClassMethods.html deleted file mode 100644 index fba33b5b5..000000000 --- a/gloc-1.2.0/vendor/plugins/gloc-1.1.0/doc/classes/ActionController/Filters/ClassMethods.html +++ /dev/null @@ -1,230 +0,0 @@ - - - - -
-| Module | -ActionController::Filters::ClassMethods | -
| In: | -
-
- lib/gloc-rails.rb
-
- - |
-
-This filter attempts to auto-detect the clients desired language. It first -checks the params, then a cookie and then the HTTP_ACCEPT_LANGUAGE request -header. If a language is found to match or be similar to a currently valid -language, then it sets the current_language of the controller. -
-- class ExampleController < ApplicationController - set_language :en - autodetect_language_filter :except => 'monkey', :on_no_lang => :lang_not_autodetected_callback - autodetect_language_filter :only => 'monkey', :check_cookie => 'monkey_lang', :check_accept_header => false - ... - def lang_not_autodetected_callback - redirect_to somewhere - end - end --
-The args for this filter are exactly the same the arguments of -before_filter with the following exceptions: -
--You override the default names of the param or cookie by calling GLoc.set_config :default_param_name -=> ‘new_param_name‘ and GLoc.set_config :default_cookie_name -=> ‘new_cookie_name‘. -
- -- # File lib/gloc-rails.rb, line 43 -43: def autodetect_language_filter(*args) -44: options= args.last.is_a?(Hash) ? args.last : {} -45: x= 'Proc.new { |c| l= nil;' -46: # :check_params -47: unless (v= options.delete(:check_params)) == false -48: name= v ? ":#{v}" : 'GLoc.get_config(:default_param_name)' -49: x << "l ||= GLoc.similar_language(c.params[#{name}]);" -50: end -51: # :check_cookie -52: unless (v= options.delete(:check_cookie)) == false -53: name= v ? ":#{v}" : 'GLoc.get_config(:default_cookie_name)' -54: x << "l ||= GLoc.similar_language(c.send(:cookies)[#{name}]);" -55: end -56: # :check_accept_header -57: unless options.delete(:check_accept_header) == false -58: x << %< -59: unless l -60: a= c.request.env['HTTP_ACCEPT_LANGUAGE'].split(/,|;/) rescue nil -61: a.each {|x| l ||= GLoc.similar_language(x)} if a -62: end; > -63: end -64: # Set language -65: x << 'ret= true;' -66: x << 'if l; c.set_language(l); c.headers[\'Content-Language\']= l.to_s; ' -67: if options.has_key?(:on_set_lang) -68: x << "ret= c.#{options.delete(:on_set_lang)}(l);" -69: end -70: if options.has_key?(:on_no_lang) -71: x << "else; ret= c.#{options.delete(:on_no_lang)};" -72: end -73: x << 'end; ret }' -74: -75: # Create filter -76: block= eval x -77: before_filter(*args, &block) -78: end --
| Class | -ActionMailer::Base | -
| In: | -
-
- lib/gloc-rails.rb
-
- - |
-
| Parent: | -- Object - | -
-In addition to including GLoc, -render_message is also overridden so that mail templates contain -the current language at the end of the file. Eg. deliver_hello -will render hello_en.rhtml. -
- -| render_message | --> | -render_message_without_gloc | -
| Class | -ActionView::Base | -
| In: | -
-
- lib/gloc-rails.rb
-
- - |
-
| Parent: | -- Object - | -
-initialize is overridden so that new instances of this class -inherit the current language of the controller. -
- -| initialize | --> | -initialize_without_gloc | -
- # File lib/gloc-rails.rb, line 109 -109: def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil) -110: initialize_without_gloc(base_path, assigns_for_first_render, controller) -111: set_language controller.current_language unless controller.nil? -112: end --
| Module | -ActionView::Helpers::DateHelper | -
| In: | -
-
- lib/gloc-rails-text.rb
-
- - |
-
| LOCALIZED_HELPERS | -= | -true | -
| LOCALIZED_MONTHNAMES | -= | -{} | -
| LOCALIZED_ABBR_MONTHNAMES | -= | -{} | -
-This method uses current_language to return a localized string. -
- -- # File lib/gloc-rails-text.rb, line 16 -16: def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false) -17: from_time = from_time.to_time if from_time.respond_to?(:to_time) -18: to_time = to_time.to_time if to_time.respond_to?(:to_time) -19: distance_in_minutes = (((to_time - from_time).abs)/60).round -20: distance_in_seconds = ((to_time - from_time).abs).round -21: -22: case distance_in_minutes -23: when 0..1 -24: return (distance_in_minutes==0) ? l(:actionview_datehelper_time_in_words_minute_less_than) : l(:actionview_datehelper_time_in_words_minute_single) unless include_seconds -25: case distance_in_seconds -26: when 0..5 then lwr(:actionview_datehelper_time_in_words_second_less_than, 5) -27: when 6..10 then lwr(:actionview_datehelper_time_in_words_second_less_than, 10) -28: when 11..20 then lwr(:actionview_datehelper_time_in_words_second_less_than, 20) -29: when 21..40 then l(:actionview_datehelper_time_in_words_minute_half) -30: when 41..59 then l(:actionview_datehelper_time_in_words_minute_less_than) -31: else l(:actionview_datehelper_time_in_words_minute) -32: end -33: -34: when 2..45 then lwr(:actionview_datehelper_time_in_words_minute, distance_in_minutes) -35: when 46..90 then l(:actionview_datehelper_time_in_words_hour_about_single) -36: when 90..1440 then lwr(:actionview_datehelper_time_in_words_hour_about, (distance_in_minutes.to_f / 60.0).round) -37: when 1441..2880 then lwr(:actionview_datehelper_time_in_words_day, 1) -38: else lwr(:actionview_datehelper_time_in_words_day, (distance_in_minutes / 1440).round) -39: end -40: end --
-This method has been modified so that a localized string can be appended to -the day numbers. -
- -- # File lib/gloc-rails-text.rb, line 43 -43: def select_day(date, options = {}) -44: day_options = [] -45: prefix = l :actionview_datehelper_select_day_prefix -46: -47: 1.upto(31) do |day| -48: day_options << ((date && (date.kind_of?(Fixnum) ? date : date.day) == day) ? -49: %(<option value="#{day}" selected="selected">#{day}#{prefix}</option>\n) : -50: %(<option value="#{day}">#{day}#{prefix}</option>\n) -51: ) -52: end -53: -54: select_html(options[:field_name] || 'day', day_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) -55: end --
-This method has been modified so that -
-- # File lib/gloc-rails-text.rb, line 61 -61: def select_month(date, options = {}) -62: unless LOCALIZED_MONTHNAMES.has_key?(current_language) -63: LOCALIZED_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names).split(',') -64: LOCALIZED_ABBR_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names_abbr).split(',') -65: end -66: -67: month_options = [] -68: month_names = options[:use_short_month] ? LOCALIZED_ABBR_MONTHNAMES[current_language] : LOCALIZED_MONTHNAMES[current_language] -69: -70: if options.has_key?(:min_date) && options.has_key?(:max_date) -71: if options[:min_date].year == options[:max_date].year -72: start_month, end_month = options[:min_date].month, options[:max_date].month -73: end -74: end -75: start_month = (options[:start_month] || 1) unless start_month -76: end_month = (options[:end_month] || 12) unless end_month -77: prefix = l :actionview_datehelper_select_month_prefix -78: -79: start_month.upto(end_month) do |month_number| -80: month_name = if options[:use_month_numbers] -81: "#{month_number}#{prefix}" -82: elsif options[:add_month_numbers] -83: month_number.to_s + ' - ' + month_names[month_number] -84: else -85: month_names[month_number] -86: end -87: -88: month_options << ((date && (date.kind_of?(Fixnum) ? date : date.month) == month_number) ? -89: %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) : -90: %(<option value="#{month_number}">#{month_name}</option>\n) -91: ) -92: end -93: -94: select_html(options[:field_name] || 'month', month_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) -95: end --
-This method has been modified so that -
-- # File lib/gloc-rails-text.rb, line 100 -100: def select_year(date, options = {}) -101: year_options = [] -102: y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year -103: -104: start_year = options.has_key?(:min_date) ? options[:min_date].year : (options[:start_year] || y-5) -105: end_year = options.has_key?(:max_date) ? options[:max_date].year : (options[:end_year] || y+5) -106: step_val = start_year < end_year ? 1 : -1 -107: prefix = l :actionview_datehelper_select_year_prefix -108: -109: start_year.step(end_year, step_val) do |year| -110: year_options << ((date && (date.kind_of?(Fixnum) ? date : date.year) == year) ? -111: %(<option value="#{year}" selected="selected">#{year}#{prefix}</option>\n) : -112: %(<option value="#{year}">#{year}#{prefix}</option>\n) -113: ) -114: end -115: -116: select_html(options[:field_name] || 'year', year_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) -117: end --
| Class | -ActionView::Helpers::InstanceTag | -
| In: | -
-
- lib/gloc-rails-text.rb
-
- - - lib/gloc-rails.rb - - - |
-
| Parent: | -- Object - | -
-The private method add_options is overridden so that "Please -select" is localized. -
- -| Class | -ActiveRecord::Errors | -
| In: | -
-
- lib/gloc-rails.rb
-
- - |
-
| Parent: | -- Object - | -
| add | --> | -add_without_gloc | -
-The GLoc version of this method provides two -extra features -
-- # File lib/gloc-rails.rb, line 141 -141: def add(attribute, msg= @@default_error_messages[:invalid]) -142: if msg.is_a?(Array) -143: args= msg.clone -144: msg= args.shift -145: args= nil if args.empty? -146: end -147: msg= ltry(msg) -148: msg= msg % args unless args.nil? -149: add_without_gloc(attribute, msg) -150: end --
| Module | -ActiveRecord::Validations::ClassMethods | -
| In: | -
-
- lib/gloc-rails.rb
-
- - |
-
-The default Rails version of this function creates an error message and -then passes it to ActiveRecord.Errors. The GLoc version of this method, sends an array to -ActiveRecord.Errors that will be turned into a -string by ActiveRecord.Errors which in turn -allows for the message of this validation function to be a GLoc string key. -
- -- # File lib/gloc-rails.rb, line 164 -164: def validates_length_of(*attrs) -165: # Merge given options with defaults. -166: options = { -167: :too_long => ActiveRecord::Errors.default_error_messages[:too_long], -168: :too_short => ActiveRecord::Errors.default_error_messages[:too_short], -169: :wrong_length => ActiveRecord::Errors.default_error_messages[:wrong_length] -170: }.merge(DEFAULT_VALIDATION_OPTIONS) -171: options.update(attrs.pop.symbolize_keys) if attrs.last.is_a?(Hash) -172: -173: # Ensure that one and only one range option is specified. -174: range_options = ALL_RANGE_OPTIONS & options.keys -175: case range_options.size -176: when 0 -177: raise ArgumentError, 'Range unspecified. Specify the :within, :maximum, :minimum, or :is option.' -178: when 1 -179: # Valid number of options; do nothing. -180: else -181: raise ArgumentError, 'Too many range options specified. Choose only one.' -182: end -183: -184: # Get range option and value. -185: option = range_options.first -186: option_value = options[range_options.first] -187: -188: case option -189: when :within, :in -190: raise ArgumentError, ":#{option} must be a Range" unless option_value.is_a?(Range) -191: -192: too_short = [options[:too_short] , option_value.begin] -193: too_long = [options[:too_long] , option_value.end ] -194: -195: validates_each(attrs, options) do |record, attr, value| -196: if value.nil? or value.split(//).size < option_value.begin -197: record.errors.add(attr, too_short) -198: elsif value.split(//).size > option_value.end -199: record.errors.add(attr, too_long) -200: end -201: end -202: when :is, :minimum, :maximum -203: raise ArgumentError, ":#{option} must be a nonnegative Integer" unless option_value.is_a?(Integer) and option_value >= 0 -204: -205: # Declare different validations per option. -206: validity_checks = { :is => "==", :minimum => ">=", :maximum => "<=" } -207: message_options = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long } -208: -209: message = [(options[:message] || options[message_options[option]]) , option_value] -210: -211: validates_each(attrs, options) do |record, attr, value| -212: if value.kind_of?(String) -213: record.errors.add(attr, message) unless !value.nil? and value.split(//).size.method(validity_checks[option])[option_value] -214: else -215: record.errors.add(attr, message) unless !value.nil? and value.size.method(validity_checks[option])[option_value] -216: end -217: end -218: end -219: end --
| Module | -GLoc | -
| In: | -
-
- lib/gloc-helpers.rb
-
- - - lib/gloc-internal.rb - - - - lib/gloc-version.rb - - - - lib/gloc.rb - - - |
-
-Copyright © 2005-2006 David Barri -
- -| LOCALIZED_STRINGS | -= | -{} | -
| RULES | -= | -{} | -
| LOWERCASE_LANGUAGES | -= | -{} | -
| UTF_8 | -= | -'utf-8' | -
| SHIFT_JIS | -= | -'sjis' | -
| EUC_JP | -= | -'euc-jp' | -
| clear_strings | --> | -_clear_strings | -
-Adds a collection of localized strings to the in-memory string store. -
- -- # File lib/gloc.rb, line 113 -113: def add_localized_strings(lang, symbol_hash, override=true, strings_charset=nil) -114: _verbose_msg {"Adding #{symbol_hash.size} #{lang} strings."} -115: _add_localized_strings(lang, symbol_hash, override, strings_charset) -116: _verbose_msg :stats -117: end --
-Creates a backup of the internal state of GLoc (ie. -strings, langs, rules, config) and optionally clears everything. -
- -- # File lib/gloc.rb, line 121 -121: def backup_state(clear=false) -122: s= _get_internal_state_vars.map{|o| o.clone} -123: _get_internal_state_vars.each{|o| o.clear} if clear -124: s -125: end --
-Removes all localized strings from memory, either of a certain language (or -languages), or entirely. -
- -- # File lib/gloc.rb, line 129 -129: def clear_strings(*languages) -130: if languages.empty? -131: _verbose_msg {"Clearing all strings"} -132: LOCALIZED_STRINGS.clear -133: LOWERCASE_LANGUAGES.clear -134: else -135: languages.each {|l| -136: _verbose_msg {"Clearing :#{l} strings"} -137: l= l.to_sym -138: LOCALIZED_STRINGS.delete l -139: LOWERCASE_LANGUAGES.each_pair {|k,v| LOWERCASE_LANGUAGES.delete k if v == l} -140: } -141: end -142: end --
-Removes all localized strings from memory, except for those of certain -specified languages. -
- -- # File lib/gloc.rb, line 146 -146: def clear_strings_except(*languages) -147: clear= (LOCALIZED_STRINGS.keys - languages) -148: _clear_strings(*clear) unless clear.empty? -149: end --
-Returns the default language -
- -- # File lib/gloc.rb, line 108 -108: def current_language -109: GLoc::CONFIG[:default_language] -110: end --
-Returns the charset used to store localized strings in memory. -
- -- # File lib/gloc.rb, line 152 -152: def get_charset(lang) -153: CONFIG[:internal_charset_per_lang][lang] || CONFIG[:internal_charset] -154: end --
-Loads localized strings from all yml files in the specifed directory. -
- -- # File lib/gloc.rb, line 167 -167: def load_localized_strings(dir=nil, override=true) -168: _charset_required -169: _get_lang_file_list(dir).each {|filename| -170: -171: # Load file -172: raw_hash = YAML::load(File.read(filename)) -173: raw_hash={} unless raw_hash.kind_of?(Hash) -174: filename =~ /([^\/\\]+)\.ya?ml$/ -175: lang = $1.to_sym -176: file_charset = raw_hash['file_charset'] || UTF_8 -177: -178: # Convert string keys to symbols -179: dest_charset= get_charset(lang) -180: _verbose_msg {"Reading file #{filename} [charset: #{file_charset} --> #{dest_charset}]"} -181: symbol_hash = {} -182: Iconv.open(dest_charset, file_charset) do |i| -183: raw_hash.each {|key, value| -184: symbol_hash[key.to_sym] = i.iconv(value) -185: } -186: end -187: -188: # Add strings to repos -189: _add_localized_strings(lang, symbol_hash, override) -190: } -191: _verbose_msg :stats -192: end --
-Restores a backup of GLoc’s internal state -that was made with backup_state. -
- -- # File lib/gloc.rb, line 195 -195: def restore_state(state) -196: _get_internal_state_vars.each do |o| -197: o.clear -198: o.send o.respond_to?(:merge!) ? :merge! : :concat, state.shift -199: end -200: end --
-Sets the charset used to internally store localized strings. You can set -the charset to use for a specific language or languages, or if none are -specified the charset for ALL localized strings will be set. -
- -- # File lib/gloc.rb, line 205 -205: def set_charset(new_charset, *langs) -206: CONFIG[:internal_charset_per_lang] ||= {} -207: -208: # Convert symbol shortcuts -209: if new_charset.is_a?(Symbol) -210: new_charset= case new_charset -211: when :utf8, :utf_8 then UTF_8 -212: when :sjis, :shift_jis, :shiftjis then SHIFT_JIS -213: when :eucjp, :euc_jp then EUC_JP -214: else new_charset.to_s -215: end -216: end -217: -218: # Convert existing strings -219: (langs.empty? ? LOCALIZED_STRINGS.keys : langs).each do |lang| -220: cur_charset= get_charset(lang) -221: if cur_charset && new_charset != cur_charset -222: _verbose_msg {"Converting :#{lang} strings from #{cur_charset} to #{new_charset}"} -223: Iconv.open(new_charset, cur_charset) do |i| -224: bundle= LOCALIZED_STRINGS[lang] -225: bundle.each_pair {|k,v| bundle[k]= i.iconv(v)} -226: end -227: end -228: end -229: -230: # Set new charset value -231: if langs.empty? -232: _verbose_msg {"Setting GLoc charset for all languages to #{new_charset}"} -233: CONFIG[:internal_charset]= new_charset -234: CONFIG[:internal_charset_per_lang].clear -235: else -236: langs.each do |lang| -237: _verbose_msg {"Setting GLoc charset for :#{lang} strings to #{new_charset}"} -238: CONFIG[:internal_charset_per_lang][lang]= new_charset -239: end -240: end -241: end --
-Sets the $KCODE global variable according to a specified charset, or else -the current default charset for the default language. -
- -- # File lib/gloc.rb, line 250 -250: def set_kcode(charset=nil) -251: _charset_required -252: charset ||= get_charset(current_language) -253: $KCODE= case charset -254: when UTF_8 then 'u' -255: when SHIFT_JIS then 's' -256: when EUC_JP then 'e' -257: else 'n' -258: end -259: _verbose_msg {"$KCODE set to #{$KCODE}"} -260: end --
-Tries to find a valid language that is similar to the argument passed. Eg. -:en, :en_au, :EN_US are all similar languages. Returns nil if no -similar languages are found. -
- -- # File lib/gloc.rb, line 265 -265: def similar_language(lang) -266: return nil if lang.nil? -267: return lang.to_sym if valid_language?(lang) -268: # Check lowercase without dashes -269: lang= lang.to_s.downcase.gsub('-','_') -270: return LOWERCASE_LANGUAGES[lang] if LOWERCASE_LANGUAGES.has_key?(lang) -271: # Check without dialect -272: if lang.to_s =~ /^([a-z]+?)[^a-z].*/ -273: lang= $1 -274: return LOWERCASE_LANGUAGES[lang] if LOWERCASE_LANGUAGES.has_key?(lang) -275: end -276: # Check other dialects -277: lang= "#{lang}_" -278: LOWERCASE_LANGUAGES.keys.each {|k| return LOWERCASE_LANGUAGES[k] if k.starts_with?(lang)} -279: # Nothing found -280: nil -281: end --
-Returns true if there are any localized strings for a specified -language. Note that although set_langauge nil is perfectly valid, -nil is not a valid language. -
- -- # File lib/gloc.rb, line 290 -290: def valid_language?(language) -291: LOCALIZED_STRINGS.has_key? language.to_sym rescue false -292: end --
-Returns an array of (currently) valid languages (ie. languages for which -localized data exists). -
- -- # File lib/gloc.rb, line 284 -284: def valid_languages -285: LOCALIZED_STRINGS.keys -286: end --
| Module | -GLoc::ClassMethods | -
| In: | -
-
- lib/gloc.rb
-
- - |
-
-All classes/modules that include GLoc will also -gain these class methods. Notice that the GLoc::InstanceMethods module is also -included. -
- -| Module | -GLoc::Helpers | -
| In: | -
-
- lib/gloc-helpers.rb
-
- - |
-
-These helper methods will be included in the InstanceMethods module. -
- -- # File lib/gloc-helpers.rb, line 12 -12: def l_YesNo(value) l(value ? :general_text_Yes : :general_text_No) end --
- # File lib/gloc-helpers.rb, line 6 -6: def l_age(age) lwr :general_fmt_age, age end --
- # File lib/gloc-helpers.rb, line 7 -7: def l_date(date) l_strftime date, :general_fmt_date end --
- # File lib/gloc-helpers.rb, line 8 -8: def l_datetime(date) l_strftime date, :general_fmt_datetime end --
- # File lib/gloc-helpers.rb, line 9 -9: def l_datetime_short(date) l_strftime date, :general_fmt_datetime_short end --
- # File lib/gloc-helpers.rb, line 15 -15: def l_lang_name(lang, display_lang=nil) -16: ll display_lang || current_language, "general_lang_#{lang}" -17: end --
- # File lib/gloc-helpers.rb, line 10 -10: def l_strftime(date,fmt) date.strftime l(fmt) end --
- # File lib/gloc-helpers.rb, line 11 -11: def l_time(time) l_strftime time, :general_fmt_time end --
| Module | -GLoc::InstanceMethods | -
| In: | -
-
- lib/gloc.rb
-
- - |
-
-Returns a localized string. -
- -- # File lib/gloc.rb, line 18 -18: def l(symbol, *arguments) -19: return GLoc._l(symbol,current_language,*arguments) -20: end --
-Returns true if a localized string with the specified key exists. -
- -- # File lib/gloc.rb, line 48 -48: def l_has_string?(symbol) -49: return GLoc._l_has_string?(symbol,current_language) -50: end --
-Returns a localized string in a specified language. This does not effect -current_language. -
- -- # File lib/gloc.rb, line 24 -24: def ll(lang, symbol, *arguments) -25: return GLoc._l(symbol,lang.to_sym,*arguments) -26: end --
-Returns a localized string if the argument is a Symbol, else just returns -the argument. -
- -- # File lib/gloc.rb, line 29 -29: def ltry(possible_key) -30: possible_key.is_a?(Symbol) ? l(possible_key) : possible_key -31: end --
-Uses a rule to return a localized string. A rule is a function -that uses specified arguments to return a localization key prefix. The -prefix is appended to the localization key originally specified, to create -a new key which is then used to lookup a localized string. -
- -- # File lib/gloc.rb, line 43 -43: def lwr_(rule, symbol, *arguments) -44: GLoc._l("#{symbol}#{GLoc::_l_rule(rule,current_language).call(*arguments)}",current_language,*arguments) -45: end --
-Sets the current language for this instance/class. Setting the language of -a class effects all instances unless the instance has its own language -defined. -
- -- # File lib/gloc.rb, line 54 -54: def set_language(language) -55: @gloc_language= language.nil? ? nil : language.to_sym -56: end --
-Sets the current language if the language passed is a valid language. If -the language was valid, this method returns true else it will -return false. Note that nil is not a valid language. See -set_language(language) for more -info. -
- -- # File lib/gloc.rb, line 62 -62: def set_language_if_valid(language) -63: if GLoc.valid_language?(language) -64: set_language(language) -65: true -66: else -67: false -68: end -69: end --
| Path: | -CHANGELOG - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
| Path: | -README - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-I originally started designing this on weekends and after work in 2005. We -started to become very interested in Rails at work and I wanted to get some -experience with ruby with before we started using it full-time. I -didn’t have very many ideas for anything interesting to create so, -because we write a lot of multilingual webapps at my company, I decided to -write a localization library. That way if my little hobby project developed -into something decent, I could at least put it to good use. And here we are -in 2006, my little hobby project has come a long way and become quite a -useful piece of software. Not only do I use it in production sites I write -at work, but I also prefer it to other existing alternatives. Therefore I -have decided to make it publicly available, and I hope that other -developers will find it useful too. -
--GLoc is a localization library. It -doesn’t aim to do everything l10n-related that you can imagine, but -what it does, it does very well. It was originally designed as a Rails -plugin, but can also be used for plain ruby projects. Here are a list of -its main features: -
--If you’re wondering about the name "GLoc", I’m sure you’re not -alone. This project was originally just called "Localization" -which was a bit too common, so when I decided to release it I decided to -call it "Golly’s Localization Library" instead (Golly is my -nickname), and that was long and boring so I then abbreviated that to -"GLoc". What a fun story!! -
--This also includes a few helpers for common situations such as displaying -localized date, time, "yes" or "no", etc. -
--At the moment, unless you manually remove the require -‘gloc-rails-text’ line from init.rb, this plugin overrides -certain Rails functions to provide multilingual versions. This -automatically localizes functions such as select_date(), -distance_of_time_in_words() and more… The strings can be found in -lang/*.yml. NOTE: This is not complete. Timezones and countries are not -currently localized. -
--Windows users will need to first install iconv. wiki.rubyonrails.com/rails/pages/iconv -
-- GLoc.set_config :default_language => :ja - GLoc.clear_strings_except :en, :ja - GLoc.set_kcode - GLoc.load_localized_strings --
-There is more functionality provided by this plugin, that is not -demonstrated above. Please read the API summary for details. -
--The following methods are added as both class methods and instance methods -to modules/classes that include GLoc. -They are also available as class methods of GLoc. -
-- current_language # Returns the current language - l(symbol, *arguments) # Returns a localized string - ll(lang, symbol, *arguments) # Returns a localized string in a specific language - ltry(possible_key) # Returns a localized string if passed a Symbol, else returns the same argument passed - lwr(symbol, *arguments) # Uses the default rule to return a localized string. - lwr_(rule, symbol, *arguments) # Uses a specified rule to return a localized string. - l_has_string?(symbol) # Checks if a localized string exists - set_language(language) # Sets the language for the current class or class instance - set_language_if_valid(lang) # Sets the current language if the language passed is a valid language --
-The GLoc module also defines the -following class methods: -
-- add_localized_strings(lang, symbol_hash, override=true) # Adds a hash of localized strings - backup_state(clear=false) # Creates a backup of GLoc's internal state and optionally clears everything too - clear_strings(*languages) # Removes localized strings from memory - clear_strings_except(*languages) # Removes localized strings from memory except for those of certain specified languages - get_charset(lang) # Returns the charset used to store localized strings in memory - get_config(key) # Returns a GLoc configuration value (see below) - load_localized_strings(dir=nil, override=true) # Loads localized strings from all YML files in a given directory - restore_state(state) # Restores a backup of GLoc's internal state - set_charset(new_charset, *langs) # Sets the charset used to internally store localized strings - set_config(hash) # Sets GLoc configuration values (see below) - set_kcode(charset=nil) # Sets the $KCODE global variable - similar_language(language) # Tries to find a valid language that is similar to the argument passed - valid_languages # Returns an array of (currently) valid languages (ie. languages for which localized data exists) - valid_language?(language) # Checks whether any localized strings are in memory for a given language --
-GLoc uses the following configuration -items. They can be accessed via get_config and -set_config. -
-- :default_cookie_name - :default_language - :default_param_name - :raise_string_not_found_errors - :verbose --
-The GLoc module is automatically -included in the following classes: -
-- ActionController::Base - ActionMailer::Base - ActionView::Base - ActionView::Helpers::InstanceTag - ActiveRecord::Base - ActiveRecord::Errors - ApplicationHelper - Test::Unit::TestCase --
-The GLoc module also defines the -following controller filters: -
-- autodetect_language_filter --
-GLoc also makes the following change to -Rails: -
-- Eg. validates_xxxxxx_of :name, :message => ['Your name must be at least %d characters.', MIN_LEN] - Eg. validates_xxxxxx_of :name, :message => [:user_error_validation_name_too_short, MIN_LEN] --
-This plugin also adds the following rake tasks: -
-- * gloc:sort - Sorts the keys in the lang ymls (also accepts a DIR argument) --
-The language can be set at three levels: -
-- 1. The default # GLoc.get_config :default_language - 2. Class level # class A; set_language :de; end - 3. Instance level # b= B.new; b.set_language :zh --
-Instance level has the highest priority and the default has the lowest. -
--Because GLoc is included at class level -too, it becomes easy to associate languages with contexts. For example: -
-
- class Student
- set_language :en
- def say_hello
- puts "We say #{l :hello} but our teachers say #{Teacher.l :hello}"
- end
- end
-
--There are often situations when depending on the value of one or more -variables, the surrounding text changes. The most common case of this is -pluralization. Rather than hardcode these rules, they are completely -definable by the user so that the user can eaasily accomodate for more -complicated grammatical rules such as those found in Russian and Polish (or -so I hear). To define a rule, simply include a string in the string bundle -whose key begins with "gloc_rule" and then write ruby -code as the value. The ruby code will be converted to a Proc when the -string bundle is first read, and should return a prefix that will be -appended to the string key at runtime to point to a new string. Make sense? -Probably not… Please look at the following example and I am sure it -will all make sense. -
--Simple example (string bundle / en.yml) -
-- _gloc_rule_default: ' |n| n==1 ? "_single" : "_plural" ' - man_count_plural: There are %d men. - man_count_single: There is 1 man. --
-Simple example (code) -
-- lwr(:man_count, 1) # => There is 1 man. - lwr(:man_count, 8) # => There are 8 men. --
-To use rules other than the default simply call lwr_ instead of lwr, and -specify the rule. -
--Example 2 (string bundle / en.yml) -
-- _gloc_rule_default: ' |n| n==1 ? "_single" : "_plural" ' - _gloc_rule_custom: ' |n| return "_none" if n==0; return "_heaps" if n>100; n==1 ? "_single" : "_plural" ' - man_count_none: There are no men. - man_count_heaps: There are heaps of men!! - man_count_plural: There are %d men. - man_count_single: There is 1 man. --
-Example 2 (code) -
-- lwr_(:custom, :man_count, 0) # => There are no men. - lwr_(:custom, :man_count, 1) # => There is 1 man. - lwr_(:custom, :man_count, 8) # => There are 8 men. - lwr_(:custom, :man_count, 150) # => There are heaps of men!! --
-GLoc includes the following helpers: -
-- l_age(age) # Returns a localized version of an age. eg "3 years old" - l_date(date) # Returns a date in a localized format - l_datetime(date) # Returns a date+time in a localized format - l_datetime_short(date) # Returns a date+time in a localized short format. - l_lang_name(l,dl=nil) # Returns the name of a language (you must supply your own strings) - l_strftime(date,fmt) # Formats a date/time in a localized format. - l_time(date) # Returns a time in a localized format - l_YesNo(value) # Returns localized string of "Yes" or "No" depending on the arg - l_yesno(value) # Returns localized string of "yes" or "no" depending on the arg --
-Not all of Rails is covered but the following functions are: -
-- distance_of_time_in_words - select_day - select_month - select_year - add_options --
-Simply put this in your init_engine.rb -
-- GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang') --
-That way your engines strings will be loaded when the engine is started. -Just simply make sure that you load your application strings after you -start your engines to safely override any engine strings. -
--By default GLoc loads all of its default -strings at startup. For example, calling set_charset -‘iso-2022-jp’ will cause this error because Russian -strings are loaded by default, and the Russian strings use characters that -cannot be expressed in the ISO-2022-JP charset. Before calling -set_charset you should call clear_strings_except to -remove strings from any languages that you will not be using. -Alternatively, you can simply specify the language(s) as follows, -set_charset ‘iso-2022-jp’, :ja. -
--Disable it as follows: -
-- GLoc.set_config :raise_string_not_found_errors => false -- -
| Path: | -lib/gloc-helpers.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -| Path: | -lib/gloc-internal.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -| Path: | -lib/gloc-rails-text.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -| Path: | -lib/gloc-rails.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -| Path: | -lib/gloc-ruby.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -| Path: | -lib/gloc-version.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
| Path: | -lib/gloc.rb - | -
| Last Update: | -Sun May 28 15:19:38 E. Australia Standard Time 2006 | -
-Copyright © 2005-2006 David Barri -
- -