motiro 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +280 -0
- data/README +28 -0
- data/README.en +175 -0
- data/README.pt-br +175 -0
- data/Rakefile +10 -0
- data/app/controllers/account_controller.rb +62 -0
- data/app/controllers/application.rb +72 -0
- data/app/controllers/edition_controller.rb +13 -0
- data/app/controllers/javascript_controller.rb +21 -0
- data/app/controllers/report_controller.rb +79 -0
- data/app/controllers/root_controller.rb +7 -0
- data/app/controllers/wiki_controller.rb +102 -0
- data/app/core/cache_reporter.rb +53 -0
- data/app/core/cache_reporter_fetcher.rb +33 -0
- data/app/core/chief_editor.rb +69 -0
- data/app/core/reporter.rb +105 -0
- data/app/core/reporter_driver.rb +36 -0
- data/app/core/reporter_fetcher.rb +39 -0
- data/app/core/settings.rb +43 -0
- data/app/core/version.rb +1 -0
- data/app/core/wiki_page_not_found.rb +33 -0
- data/app/core/wiki_reporter.rb +83 -0
- data/app/helpers/account_helper.rb +2 -0
- data/app/helpers/application_helper.rb +68 -0
- data/app/helpers/default_page_provider.rb +28 -0
- data/app/helpers/report_helper.rb +2 -0
- data/app/helpers/root_helper.rb +2 -0
- data/app/helpers/wiki_helper.rb +3 -0
- data/app/models/change.rb +96 -0
- data/app/models/diff_table_builder.rb +285 -0
- data/app/models/event.rb +18 -0
- data/app/models/headline.rb +109 -0
- data/app/models/page.rb +114 -0
- data/app/models/page_sweeper.rb +26 -0
- data/app/models/user.rb +85 -0
- data/app/ports/chdir_runner.rb +36 -0
- data/app/ports/reporter_loader.rb +9 -0
- data/app/ports/runner.rb +64 -0
- data/app/reporters/darcs_connection.rb +54 -0
- data/app/reporters/darcs_reporter.rb +104 -0
- data/app/reporters/darcs_settings.rb +9 -0
- data/app/reporters/darcs_temp_repo.rb +40 -0
- data/app/reporters/events_reporter.rb +28 -0
- data/app/reporters/features_reporter.rb +24 -0
- data/app/reporters/subversion_reporter.rb +203 -0
- data/app/reporters/svn_connection.rb +62 -0
- data/app/reporters/svn_settings.rb +40 -0
- data/app/views/account/_authorization.rhtml +54 -0
- data/app/views/account/_availability.rhtml +5 -0
- data/app/views/account/availability.rhtml +1 -0
- data/app/views/account/login.rhtml +22 -0
- data/app/views/account/logout.rhtml +10 -0
- data/app/views/javascript/motiro.rjs +132 -0
- data/app/views/javascript/niftycube.rjs +300 -0
- data/app/views/layouts/_bottom.rhtml +5 -0
- data/app/views/layouts/_header.rhtml +7 -0
- data/app/views/layouts/_top.rhtml +25 -0
- data/app/views/layouts/application.rhtml +3 -0
- data/app/views/layouts/scaffold.rhtml +13 -0
- data/app/views/layouts/wiki_edit.rhtml +26 -0
- data/app/views/report/list.rhtml +32 -0
- data/app/views/report/older.rhtml +26 -0
- data/app/views/report/rss.rxml +29 -0
- data/app/views/report/show.rhtml +20 -0
- data/app/views/root/index.rhtml +33 -0
- data/app/views/wiki/_editbar.rhtml +26 -0
- data/app/views/wiki/_properties_edit.rhtml +5 -0
- data/app/views/wiki/_properties_show.rhtml +5 -0
- data/app/views/wiki/edit.rhtml +56 -0
- data/app/views/wiki/properties_edit.rhtml +1 -0
- data/app/views/wiki/show.rhtml +9 -0
- data/bin/motiro +44 -0
- data/config/boot.rb +19 -0
- data/config/database.yml +14 -0
- data/config/environment.rb +64 -0
- data/config/environments/development.rb +20 -0
- data/config/environments/production.rb +19 -0
- data/config/environments/test.rb +19 -0
- data/config/motiro.yml +43 -0
- data/config/routes.rb +79 -0
- data/db/migrate/005_globalize_migration.rb +11363 -0
- data/db/migrate/006_remove_headline_title.rb +14 -0
- data/db/migrate/007_stretch_rid.rb +11 -0
- data/db/migrate/008_add_page_editors.rb +12 -0
- data/db/migrate/009_add_page_original_author.rb +12 -0
- data/db/migrate/010_remove_empty_string_defaults_from_pages.rb +17 -0
- data/db/migrate/011_add_title_and_kind_to_pages.rb +13 -0
- data/db/migrate/012_page_modification_info.rb +13 -0
- data/db/migrate/013_nullify_initial_page_attributes.rb +21 -0
- data/db/migrate/014_events_are_wiki_pages.rb +13 -0
- data/db/migrate/015_migrate_previous_event_data.rb +23 -0
- data/db/migrate/1_initial_structure.rb +36 -0
- data/db/migrate/2_add_authentication.rb +12 -0
- data/db/migrate/3_drop_articles.rb +26 -0
- data/db/migrate/4_add_page_editing.rb +14 -0
- data/db/motirodb.sqlite.initial +0 -0
- data/db/schema_version +1 -0
- data/db/translation/pt-BR.rb +76 -0
- data/doc/README_FOR_APP +2 -0
- data/installer/rails_installer_defaults.yml +5 -0
- data/lib/import_translations.rb +154 -0
- data/lib/login_system.rb +89 -0
- data/lib/relative_time.rb +48 -0
- data/lib/string_extensions.rb +10 -0
- data/lib/stub_hash.rb +22 -0
- data/lib/tasks/packaging.rake +93 -0
- data/lib/tasks/testing.rake +32 -0
- data/lib/tick_daemon.rb +41 -0
- data/lib/translator.rb +67 -0
- data/lib/wiki_renderer.rb +42 -0
- data/lib/wiki_url_generator.rb +29 -0
- data/log/.keepdir +0 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/favicon.ico +0 -0
- data/public/images/calendar.png +0 -0
- data/public/images/rss.png +0 -0
- data/public/javascripts/controls.js +750 -0
- data/public/javascripts/dragdrop.js +584 -0
- data/public/javascripts/effects.js +854 -0
- data/public/javascripts/prototype.js +1785 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/motiro.css +269 -0
- data/public/stylesheets/niftyCorners.css +35 -0
- data/public/stylesheets/scaffold.css +74 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/process/spinner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/script/ticker +29 -0
- data/test/acceptance/account_test.rb +186 -0
- data/test/acceptance/darcs_test.rb +62 -0
- data/test/acceptance/events_test.rb +47 -0
- data/test/acceptance/main_page_test.rb +92 -0
- data/test/acceptance/subversion_test.rb +319 -0
- data/test/acceptance/ts_all_suites.rb +27 -0
- data/test/acceptance/wiki_test.rb +202 -0
- data/test/contract/darcs_test.rb +51 -0
- data/test/contract/remote_darcs_test.rb +61 -0
- data/test/contract/svn_test.rb +53 -0
- data/test/fixtures/changes.yml +25 -0
- data/test/fixtures/headlines.yml +45 -0
- data/test/fixtures/pages.yml +98 -0
- data/test/fixtures/users.yml +31 -0
- data/test/functional/account_controller_test.rb +96 -0
- data/test/functional/report_controller_test.rb +113 -0
- data/test/functional/report_features_test.rb +38 -0
- data/test/functional/report_subversion_test.rb +79 -0
- data/test/functional/root_controller_test.rb +127 -0
- data/test/functional/wiki_controller_test.rb +280 -0
- data/test/lib/acceptance_test_case.rb +43 -0
- data/test/lib/configuration.rb +53 -0
- data/test/lib/darcs_excerpts.rb +181 -0
- data/test/lib/darcs_repo.rb +77 -0
- data/test/lib/live_mode_test.rb +51 -0
- data/test/lib/local_svn.rb +157 -0
- data/test/lib/netutils.rb +42 -0
- data/test/lib/platform_thread.rb +62 -0
- data/test/lib/repoutils.rb +23 -0
- data/test/lib/selenium_extensions.rb +32 -0
- data/test/lib/stubio.rb +37 -0
- data/test/lib/svn_excerpts.rb +288 -0
- data/test/lib/test_configuration.rb +14 -0
- data/test/lib/webserver.rb +71 -0
- data/test/meta/configuration_test.rb +72 -0
- data/test/meta/darcs_repo_test.rb +118 -0
- data/test/meta/local_svn_test.rb +125 -0
- data/test/meta/platform_thread_test.rb +46 -0
- data/test/meta/stubio_test.rb +44 -0
- data/test/mocks/headline.rb +34 -0
- data/test/mocks/svn_reporter.rb +29 -0
- data/test/stubs/svn_settings.rb +19 -0
- data/test/stubs/url_generator.rb +24 -0
- data/test/test_helper.rb +36 -0
- data/test/unit/cache_reporter_fetcher_test.rb +46 -0
- data/test/unit/cache_reporter_test.rb +97 -0
- data/test/unit/caching_test.rb +78 -0
- data/test/unit/change_test.rb +152 -0
- data/test/unit/chdir_runner_test.rb +77 -0
- data/test/unit/chief_editor_test.rb +234 -0
- data/test/unit/darcs_connection_test.rb +109 -0
- data/test/unit/darcs_reporter_test.rb +146 -0
- data/test/unit/darcs_settings_test.rb +37 -0
- data/test/unit/darcs_temp_repo_test.rb +51 -0
- data/test/unit/default_page_provider_test.rb +46 -0
- data/test/unit/diff_table_builder_test.rb +602 -0
- data/test/unit/headline_test.rb +259 -0
- data/test/unit/page_test.rb +145 -0
- data/test/unit/relative_time_test.rb +56 -0
- data/test/unit/reporter_driver_test.rb +85 -0
- data/test/unit/reporter_fetcher_test.rb +31 -0
- data/test/unit/reporter_test.rb +81 -0
- data/test/unit/runner_test.rb +93 -0
- data/test/unit/settings_test.rb +55 -0
- data/test/unit/string_extensions_test.rb +10 -0
- data/test/unit/svn_connection_test.rb +183 -0
- data/test/unit/svn_reporter_interaction_test.rb +38 -0
- data/test/unit/svn_reporter_test.rb +286 -0
- data/test/unit/svn_settings_test.rb +86 -0
- data/test/unit/translator_test.rb +96 -0
- data/test/unit/user_test.rb +125 -0
- data/test/unit/wiki_renderer_test.rb +87 -0
- data/test/unit/wiki_reporter_test.rb +94 -0
- data/test/unit/wiki_url_generator_test.rb +31 -0
- data/vendor/motiro-installer.rb +159 -0
- data/vendor/plugins/globalize/LICENSE +9 -0
- data/vendor/plugins/globalize/README +49 -0
- data/vendor/plugins/globalize/data/country_data.csv +240 -0
- data/vendor/plugins/globalize/data/language_data.csv +188 -0
- data/vendor/plugins/globalize/data/translation_data.csv +3421 -0
- data/vendor/plugins/globalize/generators/globalize/USAGE +10 -0
- data/vendor/plugins/globalize/generators/globalize/globalize_generator.rb +42 -0
- data/vendor/plugins/globalize/generators/globalize/templates/migration.rb.gz +0 -0
- data/vendor/plugins/globalize/generators/globalize/templates/tiny_migration.rb.gz +0 -0
- data/vendor/plugins/globalize/init.rb +30 -0
- data/vendor/plugins/globalize/lib/globalize/localization/core_ext.rb +170 -0
- data/vendor/plugins/globalize/lib/globalize/localization/core_ext_hooks.rb +33 -0
- data/vendor/plugins/globalize/lib/globalize/localization/db_translate.rb +494 -0
- data/vendor/plugins/globalize/lib/globalize/localization/db_view_translator.rb +152 -0
- data/vendor/plugins/globalize/lib/globalize/localization/locale.rb +173 -0
- data/vendor/plugins/globalize/lib/globalize/localization/rfc_3066.rb +40 -0
- data/vendor/plugins/globalize/lib/globalize/models/country.rb +24 -0
- data/vendor/plugins/globalize/lib/globalize/models/currency.rb +188 -0
- data/vendor/plugins/globalize/lib/globalize/models/language.rb +84 -0
- data/vendor/plugins/globalize/lib/globalize/models/model_translation.rb +4 -0
- data/vendor/plugins/globalize/lib/globalize/models/translation.rb +9 -0
- data/vendor/plugins/globalize/lib/globalize/models/view_translation.rb +14 -0
- data/vendor/plugins/globalize/lib/globalize/rails/action_mailer.rb +125 -0
- data/vendor/plugins/globalize/lib/globalize/rails/action_view.rb +79 -0
- data/vendor/plugins/globalize/lib/globalize/rails/active_record.rb +129 -0
- data/vendor/plugins/globalize/lib/globalize/rails/active_record_helper.rb +33 -0
- data/vendor/plugins/globalize/populators/pop_dates.rb +81 -0
- data/vendor/plugins/globalize/populators/pop_migration.rb +18 -0
- data/vendor/plugins/globalize/populators/pop_pluralization.rb +26 -0
- data/vendor/plugins/globalize/populators/pop_seps.rb +32 -0
- data/vendor/plugins/globalize/tasks/data.rake +130 -0
- data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.en-US.plain.text.rhtml +1 -0
- data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.en.plain.text.rhtml +1 -0
- data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.he.plain.text.rhtml +1 -0
- data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.plain.text.rhtml +1 -0
- data/vendor/plugins/globalize/test/action_mailer_test.rb +54 -0
- data/vendor/plugins/globalize/test/config/database.yml.default +16 -0
- data/vendor/plugins/globalize/test/config/database.yml.example +22 -0
- data/vendor/plugins/globalize/test/core_ext_test.rb +61 -0
- data/vendor/plugins/globalize/test/currency_test.rb +141 -0
- data/vendor/plugins/globalize/test/date_helper_test.rb +634 -0
- data/vendor/plugins/globalize/test/db/schema.rb +90 -0
- data/vendor/plugins/globalize/test/db_translation_test.rb +374 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_categories.yml +7 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_categories_products.yml +7 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_countries.yml +41 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_languages.yml +64 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_manufacturers.yml +5 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_products.yml +29 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_simples.yml +5 -0
- data/vendor/plugins/globalize/test/fixtures/globalize_translations.yml +354 -0
- data/vendor/plugins/globalize/test/locale_test.rb +27 -0
- data/vendor/plugins/globalize/test/mime_responds_test.rb +358 -0
- data/vendor/plugins/globalize/test/model_test.rb +17 -0
- data/vendor/plugins/globalize/test/standard_data_test_helper.rb +33 -0
- data/vendor/plugins/globalize/test/test_helper.rb +19 -0
- data/vendor/plugins/globalize/test/test_standard_data.rb +54 -0
- data/vendor/plugins/globalize/test/validation_test.rb +29 -0
- data/vendor/plugins/globalize/test/view_picking_test.rb +49 -0
- data/vendor/plugins/globalize/test/view_translation_test.rb +237 -0
- data/vendor/plugins/globalize/test/views/layouts/standard.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/all_types_with_layout.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/all_types_with_layout.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rxml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rxml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rxml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rxml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rxml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rjs +1 -0
- data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rxml +1 -0
- data/vendor/plugins/globalize/test/views/test.he-IL.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/test.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/test2.he.rhtml +1 -0
- data/vendor/plugins/globalize/test/views/test2.rhtml +1 -0
- data/vendor/plugins/test_xml/MIT-LICENSE +20 -0
- data/vendor/plugins/test_xml/README +20 -0
- data/vendor/plugins/test_xml/Rakefile +22 -0
- data/vendor/plugins/test_xml/init.rb +7 -0
- data/vendor/plugins/test_xml/lib/xml_assertions.rb +22 -0
- data/vendor/plugins/test_xml/test/test_xml_test.rb +40 -0
- metadata +505 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a new migration that creates and populates the "globalize" db tables.
|
3
|
+
All tables are prefixed with "globalize_", so they won't conflict with
|
4
|
+
other application tables. Run 'rake migrate' afterwards to synch the db.
|
5
|
+
|
6
|
+
Example:
|
7
|
+
./script/generate globalize
|
8
|
+
|
9
|
+
This will create:
|
10
|
+
db/migrate/xxx_globalize.rb
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class GlobalizeGenerator < MigrationGenerator
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
arg = runtime_args.first
|
7
|
+
@tiny = arg && arg.downcase == 'tiny'
|
8
|
+
super([ "globalize_migration" ] + runtime_args, runtime_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def banner
|
12
|
+
"Usage: script/generate globalize [tiny]\n" +
|
13
|
+
' Specify "tiny" to generate a compact version of the data files (major languages only).'
|
14
|
+
end
|
15
|
+
|
16
|
+
def inflate_schema
|
17
|
+
deflated_name = @tiny ? 'tiny_migration.rb.gz' : 'migration.rb.gz'
|
18
|
+
inflated_path = source_path('migration.rb')
|
19
|
+
deflated_path = source_path(deflated_name)
|
20
|
+
|
21
|
+
return if File.exist?(inflated_path) && !File.exist?(deflated_path)
|
22
|
+
return if !File.exist?(deflated_path)
|
23
|
+
|
24
|
+
File.open(inflated_path, 'w') do |f|
|
25
|
+
Zlib::GzipReader.open(deflated_path) do |gzip|
|
26
|
+
gzip.each do |line|
|
27
|
+
line.chomp!
|
28
|
+
f.puts line
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def manifest
|
35
|
+
record do |m|
|
36
|
+
m.directory 'db/migrate'
|
37
|
+
m.inflate_schema
|
38
|
+
m.migration_template 'migration.rb', 'db/migrate'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'jcode'
|
2
|
+
$KCODE = 'u' # Always use UTF-8 internally!
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'singleton'
|
6
|
+
|
7
|
+
root_path = directory # this is set in the initializer that calls init.rb
|
8
|
+
ml_lib_path = "#{root_path}/lib/globalize"
|
9
|
+
|
10
|
+
# Load globalize libs
|
11
|
+
require "globalize/localization/db_view_translator"
|
12
|
+
require "globalize/localization/rfc_3066"
|
13
|
+
require "globalize/localization/locale"
|
14
|
+
require "globalize/localization/db_translate"
|
15
|
+
require "globalize/localization/core_ext"
|
16
|
+
require "globalize/localization/core_ext_hooks"
|
17
|
+
|
18
|
+
# Load plugin models
|
19
|
+
require "globalize/models/translation"
|
20
|
+
require "globalize/models/model_translation"
|
21
|
+
require "globalize/models/view_translation"
|
22
|
+
require "globalize/models/language"
|
23
|
+
require "globalize/models/country"
|
24
|
+
require "globalize/models/currency"
|
25
|
+
|
26
|
+
# Load overriden Rails modules
|
27
|
+
require "globalize/rails/active_record"
|
28
|
+
require "globalize/rails/action_view"
|
29
|
+
require "globalize/rails/action_mailer"
|
30
|
+
require "globalize/rails/active_record_helper"
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# This module supplies a bunch of localization-related core extensions to ruby
|
2
|
+
# built-in and standard classes.
|
3
|
+
|
4
|
+
module Globalize # :nodoc:
|
5
|
+
module CoreExtensions # :nodoc:
|
6
|
+
|
7
|
+
module String
|
8
|
+
|
9
|
+
# Indicates direction of text (usually +ltr+ [left-to-right] or
|
10
|
+
# +rtl+ [right-to-left].
|
11
|
+
attr_accessor :direction
|
12
|
+
|
13
|
+
# Translates the string into the active language. If there is a
|
14
|
+
# quantity involved, it can be set with the +arg+ parameter. In this case
|
15
|
+
# string should contain the code <tt>%d</tt>, which will be substituted with
|
16
|
+
# the supplied number.
|
17
|
+
#
|
18
|
+
# To substitute a +string+, give it as the +arg+ parameter. It will be
|
19
|
+
# substituted for <tt>%s</dd>.
|
20
|
+
#
|
21
|
+
# If there is no translation available, +default+ will be returned, or
|
22
|
+
# if it's not supplied, the original string will be returned.
|
23
|
+
def translate(default = nil, arg = nil)
|
24
|
+
Locale.translate(self, default, arg)
|
25
|
+
end
|
26
|
+
alias :t :translate
|
27
|
+
|
28
|
+
# Translates the string into the active language. This is equivalent
|
29
|
+
# to translate(arg).
|
30
|
+
#
|
31
|
+
# Example: <tt>"There are %d items in your cart" / 1 -> "There is one item in your cart"</tt>
|
32
|
+
def /(arg)
|
33
|
+
translate(nil, arg)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module Symbol
|
39
|
+
# Translates the symbol into the active language. Underscores are
|
40
|
+
# converted to spaces.
|
41
|
+
#
|
42
|
+
# If there is no translation available, +default+ will be returned, or
|
43
|
+
# if it's not supplied, the original string will be returned.
|
44
|
+
def translate(default = nil)
|
45
|
+
Locale.translate(self, default)
|
46
|
+
end
|
47
|
+
alias :t :translate
|
48
|
+
end
|
49
|
+
|
50
|
+
module Object
|
51
|
+
# Translates the supplied string into the active language. If there is a
|
52
|
+
# quantity involved, it can be set with the +arg+ parameter. In this case
|
53
|
+
# string should contain the code <tt>%d</tt>, which will be substituted with
|
54
|
+
# the supplied number.
|
55
|
+
#
|
56
|
+
# If there is no translation available, +default+ will be returned, or
|
57
|
+
# if it's not supplied, the original string will be returned.
|
58
|
+
#
|
59
|
+
# <em>Note: This method is deprectated and is supplied for backward
|
60
|
+
# compatibility with other translation packages, notable gettext.</em>
|
61
|
+
def _(str, default = nil, arg = nil)
|
62
|
+
Locale.translate(str, default, arg)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Integer
|
67
|
+
# Returns the integer in String form, according to the rules of the
|
68
|
+
# currently active locale.
|
69
|
+
def localize( base = 10 )
|
70
|
+
str = self.to_s( base )
|
71
|
+
if (base == 10)
|
72
|
+
if Locale.active?
|
73
|
+
delimiter = Locale.active.thousands_sep
|
74
|
+
number_grouping_scheme = Locale.active.number_grouping_scheme
|
75
|
+
end
|
76
|
+
delimiter ||= ','
|
77
|
+
number_grouping_scheme ||= :western
|
78
|
+
number_grouping_scheme == :indian ?
|
79
|
+
str.gsub(/(\d)(?=((\d\d\d)(?!\d))|((\d\d)+(\d\d\d)(?!\d)))/) { |match|
|
80
|
+
match + delimiter } :
|
81
|
+
str.gsub(/(\d)(?=(\d\d\d)+(?!\d))/) { |match| match + delimiter }
|
82
|
+
else
|
83
|
+
str
|
84
|
+
end
|
85
|
+
end
|
86
|
+
alias :loc :localize
|
87
|
+
end
|
88
|
+
|
89
|
+
module Float
|
90
|
+
# Returns the integer in String form, according to the rules of the
|
91
|
+
# currently active locale.
|
92
|
+
#
|
93
|
+
# Example: <tt>123456.localize -> 123.456</tt> (German locale)
|
94
|
+
def localize
|
95
|
+
str = self.to_s
|
96
|
+
if str =~ /^[\d\.]+$/
|
97
|
+
if Locale.active?
|
98
|
+
active_locale = Locale.active
|
99
|
+
delimiter = active_locale.thousands_sep
|
100
|
+
decimal = active_locale.decimal_sep
|
101
|
+
number_grouping_scheme = active_locale.number_grouping_scheme
|
102
|
+
end
|
103
|
+
delimiter ||= ','
|
104
|
+
decimal ||= '.'
|
105
|
+
number_grouping_scheme ||= :western
|
106
|
+
|
107
|
+
int, frac = str.split('.')
|
108
|
+
number_grouping_scheme == :indian ?
|
109
|
+
int.gsub!(/(\d)(?=((\d\d\d)(?!\d))|((\d\d)+(\d\d\d)(?!\d)))/) { |match|
|
110
|
+
match + delimiter} :
|
111
|
+
int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/) { |match| match + delimiter }
|
112
|
+
int + decimal + frac
|
113
|
+
else
|
114
|
+
str
|
115
|
+
end
|
116
|
+
end
|
117
|
+
alias :loc :localize
|
118
|
+
end
|
119
|
+
|
120
|
+
module Time
|
121
|
+
# Acts the same as #strftime, but returns a localized version of the
|
122
|
+
# formatted date/time string.
|
123
|
+
def localize(format)
|
124
|
+
# unabashedly stole this snippet from Tadayoshi Funaba's Date class
|
125
|
+
o = ''
|
126
|
+
format.scan(/%[EO]?.|./o) do |c|
|
127
|
+
cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
|
128
|
+
case cc
|
129
|
+
when '%A'; o << "#{::Date::DAYNAMES[wday]} [weekday]".t(::Date::DAYNAMES[wday])
|
130
|
+
when '%a'; o << "#{::Date::ABBR_DAYNAMES[wday]} [abbreviated weekday]".t(::Date::ABBR_DAYNAMES[wday])
|
131
|
+
when '%B'; o << "#{::Date::MONTHNAMES[mon]} [month]".t(::Date::MONTHNAMES[mon])
|
132
|
+
when '%b'; o << "#{::Date::ABBR_MONTHNAMES[mon]} [abbreviated month]".t(::Date::ABBR_MONTHNAMES[mon])
|
133
|
+
when '%c'; o << ((Locale.active? && !Locale.active.date_format.nil?) ?
|
134
|
+
localize(Locale.active.date_format) : strftime('%Y-%m-%d'))
|
135
|
+
when '%p'; o << if hour < 12 then 'AM [Ante Meridiem]'.t("AM") else 'PM [Post Meridiem]'.t("PM") end
|
136
|
+
else; o << c
|
137
|
+
end
|
138
|
+
end
|
139
|
+
strftime(o)
|
140
|
+
end
|
141
|
+
alias :loc :localize
|
142
|
+
end
|
143
|
+
|
144
|
+
module Date
|
145
|
+
# Acts the same as #strftime, but returns a localized version of the
|
146
|
+
# formatted date/time string.
|
147
|
+
def localize(format)
|
148
|
+
# unabashedly stole this snippet from Tadayoshi Funaba's Date class
|
149
|
+
o = ''
|
150
|
+
format.scan(/%[EO]?.|./o) do |c|
|
151
|
+
cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
|
152
|
+
case cc
|
153
|
+
when '%A'; o << "#{::Date::DAYNAMES[wday]} [weekday]".t(::Date::DAYNAMES[wday])
|
154
|
+
when '%a'; o << "#{::Date::ABBR_DAYNAMES[wday]} [abbreviated weekday]".t(::Date::ABBR_DAYNAMES[wday])
|
155
|
+
when '%B'; o << "#{::Date::MONTHNAMES[mon]} [month]".t(::Date::MONTHNAMES[mon])
|
156
|
+
when '%b'; o << "#{::Date::ABBR_MONTHNAMES[mon]} [abbreviated month]".t(::Date::ABBR_MONTHNAMES[mon])
|
157
|
+
when '%c'; o << ((Locale.active? && !Locale.active.date_format.nil?) ?
|
158
|
+
localize(Locale.active.date_format) : strftime('%Y-%m-%d'))
|
159
|
+
when '%p'; o << if hour < 12 then 'AM [Ante Meridiem]'.t("am") else 'PM [Post Meridiem]'.t("am") end
|
160
|
+
when '%P'; o << if hour < 12 then 'AM [Ante Meridiem]'.t("AM") else 'PM [Post Meridiem]'.t("PM") end
|
161
|
+
else; o << c
|
162
|
+
end
|
163
|
+
end
|
164
|
+
strftime(o)
|
165
|
+
end
|
166
|
+
alias :loc :localize
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Hook up core extenstions (need to define them as main level, hence
|
2
|
+
# the :: prefix)
|
3
|
+
class ::String # :nodoc:
|
4
|
+
include Globalize::CoreExtensions::String
|
5
|
+
end
|
6
|
+
|
7
|
+
class ::Symbol # :nodoc:
|
8
|
+
include Globalize::CoreExtensions::Symbol
|
9
|
+
end
|
10
|
+
|
11
|
+
class ::Object # :nodoc:
|
12
|
+
include Globalize::CoreExtensions::Object
|
13
|
+
end
|
14
|
+
|
15
|
+
class ::Fixnum # :nodoc:
|
16
|
+
include Globalize::CoreExtensions::Integer
|
17
|
+
end
|
18
|
+
|
19
|
+
class ::Bignum # :nodoc:
|
20
|
+
include Globalize::CoreExtensions::Integer
|
21
|
+
end
|
22
|
+
|
23
|
+
class ::Float # :nodoc:
|
24
|
+
include Globalize::CoreExtensions::Float
|
25
|
+
end
|
26
|
+
|
27
|
+
class ::Time # :nodoc:
|
28
|
+
include Globalize::CoreExtensions::Time
|
29
|
+
end
|
30
|
+
|
31
|
+
class ::Date # :nodoc:
|
32
|
+
include Globalize::CoreExtensions::Date
|
33
|
+
end
|