[activescaffoldlocalize commit] r86 - in trunk: . lang lib lib/helpers

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 20, 2007, 12:11:57 AM12/20/07
to activescaffold...@googlegroups.com
Author: edwin.moss
Date: Wed Dec 19 21:11:07 2007
New Revision: 86

Added:
trunk/lib/helpers/
trunk/lib/helpers/list_column_helpers.rb
Modified:
trunk/environment.rb
trunk/lang/en-us.rb
trunk/lang/fr-ca.rb
trunk/lib/localization.rb

Log:
Date and Time localization.

Modified: trunk/environment.rb
==============================================================================
--- trunk/environment.rb (original)
+++ trunk/environment.rb Wed Dec 19 21:11:07 2007
@@ -1,6 +1,7 @@
require 'localization'

require "#{File.dirname __FILE__}/lib/extensions/active_record"
+require "#{File.dirname __FILE__}/lib/helpers/list_column_helpers"

##
## Preload lang files

Modified: trunk/lang/en-us.rb
==============================================================================
--- trunk/lang/en-us.rb (original)
+++ trunk/lang/en-us.rb Wed Dec 19 21:11:07 2007
@@ -47,21 +47,6 @@
lang['Update %s'] ||= 'Update %s'
lang['Updated %s'] ||= 'Updated %s'

- # DHTML Calendar plugin strings
- lang['mm/dd/yyyy'] ||= "mm/dd/yyyy or use calendar"
- lang['Click to Show Calendar'] ||= 'Click to Show Calendar
-or try these Shortcuts:
-today (tod)
-tomorrow (tom)
-yesterday
-6 (6th or 6th October)
-3rd of Feb
-12 feb
-mon
-next mon
-last mon
-4/26'
-
# AS error messages
lang['Version inconsistency - this record has been modified since
you started editing it.'] ||= 'Version inconsistency - this record has
been modified since you started editing it.'

@@ -80,4 +65,82 @@
lang["is not a number"] ||= "is not a number"
lang['%d error prohibited this %s from being saved'] ||= {1 => '%s
error prohibited this %s from being saved', 2 => '%s errors prohibited
this %s from being saved'}
lang['There were problems with the following fields:'] ||= 'There
were problems with the following fields:'
+
+ # Dates
+ lang[:date_helper] = {
+ :calendar_help => "yyyy-mm-dd or use calendar",
+ :calendar_tool_tip => 'Click to Show Calendar
+ or try these Shortcuts:
+ today (tod)
+ tomorrow (tom)
+ yesterday
+ 6 (6th or 6th October)
+ 3rd of Feb
+ 12 feb
+ mon
+ next mon
+ last mon
+ 4/26',
+ # don't translate, just re-order
+ :date_helper_date_formats => {
+ :default => "%Y-%m-%d",
+ :short => "%b %e",
+ :long => "%B %e, %Y"
+ },
+ # don't translate, just re-order
+ :date_helper_time_formats => {
+ :default => "%a, %d %b %Y %H:%M:%S %z",
+ :short => "%d %b %H:%M",
+ :long => "%B %d, %Y %H:%M"
+ },
+ # added at the end of date if your date system doesn't use a 24
hours system
+ :date_helper_am => 'am',
+ :date_helper_pm => 'pm',
+ :date_helper_month_names => ['', '',
+ 'January',
+ 'February',
+ 'March',
+ 'April',
+ 'May',
+ 'June',
+ 'July',
+ 'August',
+ 'September',
+ 'October',
+ 'November',
+ 'December'],
+
+ :date_helper_abbr_month_names => ['', '',
+ 'Jan',
+ 'Feb',
+ 'Mar',
+ 'Apr',
+ 'May',
+ 'Jun',
+ 'Jul',
+ 'Aug',
+ 'Sep',
+ 'Oct',
+ 'Nov',
+ 'Dec'],
+
+ :date_helper_day_names => [
+ 'Sunday',
+ 'Monday',
+ 'Tuesday',
+ 'Wednesday',
+ 'Thursday',
+ 'Friday',
+ 'Saturday'],
+
+ :date_helper_abbr_day_names => [
+ 'Sun',
+ 'Mon',
+ 'Tue',
+ 'Wed',
+ 'Thu',
+ 'Fri',
+ 'Sat']
+ }
+
end

Modified: trunk/lang/fr-ca.rb
==============================================================================
--- trunk/lang/fr-ca.rb (original)
+++ trunk/lang/fr-ca.rb Wed Dec 19 21:11:07 2007
@@ -47,10 +47,6 @@
lang['Update %s'] ||= 'Mettre à jour %s'
lang['Updated %s'] ||= '%s mis à jour'

- # DHTML Calendar plugin strings
- lang['mm/dd/yyyy'] ||= "mm/dd/yyyy or use calendar"
- lang['Click to Show Calendar'] ||= 'Click pour Show Calendar'
-
# AS error messages
lang['Version inconsistency - this record has been modified since
you started editing it.'] ||= 'Version inconsistency - this record has
been modified since you started editing it.'

@@ -69,4 +65,71 @@
lang["is not a number"] ||= "n'est pas un nombre"
lang['%d error prohibited this %s from being saved'] ||= {1 => '%d a
empêché ce %s d\'être sauvegardé', 2 => "%d a interdit ce
participant d'être économisé"}
lang['There were problems with the following fields:'] ||= 'Des
problèmes sont survenus pour les champs suivants :'
+
+ # Dates
+ lang[:date_helper] = {
+ :calendar_help => "jj-mm-aaaa or use calendar",
+ :calendar_tool_tip => 'Click to Show Calendar',
+ # don't translate, just re-order
+ :date_helper_date_formats => {
+ :default => "%d-%m-%Y",
+ :short => "%b %e",
+ :long => "%B %e, %Y"
+ },
+ # don't translate, just re-order
+ :date_helper_time_formats => {
+ :default => "%a, %d %b %Y %H:%M:%S %z",
+ :short => "%d %b %H:%M",
+ :long => "%B %d, %Y %H:%M"
+ },
+ # added at the end of date if your date system doesn't use a 24
hours system
+ :date_helper_am => 'am',
+ :date_helper_pm => 'pm',
+ :date_helper_month_names => ['', '',
+ 'Janvier',
+ 'Février',
+ 'Mars',
+ 'Avril',
+ 'Mai',
+ 'Juin',
+ 'Juillet',
+ 'Août',
+ 'Septembre',
+ 'Octobre',
+ 'Novembre',
+ 'Décembre'],
+
+ :date_helper_abbr_month_names => ['', '',
+ 'Jan',
+ 'Fev',
+ 'Mar',
+ 'Avr',
+ 'Mai',
+ 'Jui',
+ 'Jul',
+ 'Aoû',
+ 'Sep',
+ 'Oct',
+ 'Nov',
+ 'Déc'],
+
+ :date_helper_day_names => [
+ 'Dimanche',
+ 'Lundi',
+ 'Mardi',
+ 'Mercredi',
+ 'Jeudi',
+ 'Vendredi',
+ 'Samedi'],
+
+ :date_helper_abbr_day_names => [
+ 'Dim',
+ 'Lun',
+ 'Mar',
+ 'Mer',
+ 'Jeu',
+ 'Ven',
+ 'Sam'],
+ }
+
end

Added: trunk/lib/helpers/list_column_helpers.rb
==============================================================================
--- (empty file)
+++ trunk/lib/helpers/list_column_helpers.rb Wed Dec 19 21:11:07 2007
@@ -0,0 +1,15 @@
+module ActiveScaffold
+ module Helpers
+ # Helpers that assist with the rendering of a List Column
+ module ListColumns
+ def format_time(time)
+ time.localize
+ end
+
+ def format_date(date)
+ date.localize
+ end
+
+ end
+ end
+end

Modified: trunk/lib/localization.rb
==============================================================================
--- trunk/lib/localization.rb (original)
+++ trunk/lib/localization.rb Wed Dec 19 21:11:07 2007
@@ -48,6 +48,10 @@
end
end
end
+
+ def self.lookup(key)
+ @@l10s[self.lang][key] if @@l10s[self.lang]
+ end

def self.define(lang = 'en-us')
lang = standardize_name(lang)
@@ -83,3 +87,65 @@
ActiveScaffold::Localization._(*args)
end
end
+
+#TODO 2007-12-19 (EJM) Level=0 - Need to test this before...
+# class Array
+# alias :orig_to_sentence :to_sentence
+# def to_sentence(options = {})
+# # unabashedly stolen from Globalite
+# options.reverse_merge!({ :connector
=> :array_connector.l, :skip_last_comma =>
Boolean(:array_skip_last_comma.l) })
+# orig_to_sentence(options)
+# end
+# end
+
+class Time
+ # Acts the same as #strftime, but returns a localized version of the
+ # formatted date/time string.
+ def localize(format='default')
+ # unabashedly stolen from Globalite which unabashedly stole this
snippet from Globalize which unabashedly stole this snippet from
Tadayoshi Funaba's Date class
+ o = ''
+ format =
ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_time_formats][format.to_s.downcase.to_sym]
if ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_time_formats][format.to_s.downcase.to_sym]
+ format.scan(/%[EO]?.|./o) do |c|
+ cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
+ case cc
+ when '%A'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_day_names][wday]
+ when '%a'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_abbr_day_names][wday]
+ when '%B'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_month_names][mon]
+ when '%b'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_abbr_month_names][mon]
+ #when '%c'; o
<< :date_helper_time_formats.l[:default] ? :date_helper_date_formats.l[:default] : strftime('%Y-%m-%d')
+ when '%p'; o << if hour < 12 then
ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_am] else
ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_pm] end
+ else; o << c
+ end
+ end
+ strftime(o)
+ end
+ alias :l :localize
+end
+
+class Date
+ # Acts the same as #strftime, but returns a localized version of the
formatted date string.
+
+ def self.un_localize(value)
+ Date.strptime(value, ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_date_formats][:default])
+ end
+
+ def localize(format='default')
+ # unabashedly stolen from Globalite which unabashedly stole this
snippet from Globalize which unabashedly stole this snippet from
Tadayoshi Funaba's Date class
+ o = ''
+ format =
ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_date_formats][format.to_s.downcase.to_sym]
if ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_date_formats][format.to_s.downcase.to_sym]
+ format.scan(/%[EO]?.|./o) do |c|
+ cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
+ case cc
+ when '%A'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_day_names][wday]
+ when '%a'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_abbr_day_names][wday]
+ when '%B'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_month_names][mon]
+ when '%b'; o << ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_abbr_month_names][mon]
+ #when '%c'; o
<< :date_helper_time_formats.l[:default] ? :date_helper_date_formats.l[:default] : strftime('%Y-%m-%d')
+ when '%p'; o << if hour < 12
then :ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_am]
else ActiveScaffold::Localization.lookup(:date_helper)[:date_helper_pm] end
+ else; o << c
+ end
+ end
+ strftime(o)
+ end
+ alias :l :localize
+end
\ No newline at end of file

Reply all
Reply to author
Forward
0 new messages