zena 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -0
- data/README.rdoc +1 -1
- data/app/controllers/columns_controller.rb +3 -31
- data/app/controllers/comments_controller.rb +8 -3
- data/app/controllers/data_entries_controller.rb +1 -1
- data/app/controllers/documents_controller.rb +2 -2
- data/app/controllers/nodes_controller.rb +29 -12
- data/app/controllers/relations_controller.rb +2 -2
- data/app/controllers/sites_controller.rb +1 -1
- data/app/controllers/user_sessions_controller.rb +6 -3
- data/app/controllers/users_controller.rb +18 -16
- data/app/controllers/versions_controller.rb +20 -18
- data/app/controllers/virtual_classes_controller.rb +103 -17
- data/app/helpers/users_helper.rb +1 -1
- data/app/models/column.rb +19 -50
- data/app/models/comment.rb +2 -1
- data/app/models/node.rb +45 -22
- data/app/models/relation.rb +13 -0
- data/app/models/relation_proxy.rb +3 -2
- data/app/models/role.rb +213 -4
- data/app/models/site.rb +18 -11
- data/app/models/template.rb +37 -35
- data/app/models/version.rb +1 -1
- data/app/models/virtual_class.rb +154 -86
- data/app/views/columns/_li.html.erb +1 -1
- data/app/views/columns/index.html.erb +1 -9
- data/app/views/comments/index.rhtml +10 -8
- data/app/views/documents/_crop.rhtml +5 -6
- data/app/views/documents/crop_form.rjs +3 -2
- data/app/views/groups/index.rhtml +1 -1
- data/app/views/iformats/index.rhtml +1 -1
- data/app/views/nodes/_import_results.rhtml +1 -1
- data/app/views/nodes/_parent.rhtml +1 -2
- data/app/views/nodes/update.rjs +3 -4
- data/app/views/relations/index.erb +1 -1
- data/app/views/sites/index.erb +1 -1
- data/app/views/templates/drive_tabs/_drive.rhtml +0 -2
- data/app/views/templates/edit_tabs/_image.rhtml +1 -1
- data/app/views/templates/edit_tabs/_title.rhtml +0 -6
- data/app/views/users/index.rhtml +1 -1
- data/app/views/users/preferences.html.erb +2 -2
- data/app/views/versions/backup.rjs +1 -1
- data/app/views/versions/custom_tab.rhtml +9 -4
- data/app/views/versions/destroy.rjs +2 -2
- data/app/views/versions/update.rjs +2 -9
- data/app/views/virtual_classes/_form.erb +3 -2
- data/app/views/virtual_classes/import_prepare.html.erb +13 -0
- data/app/views/virtual_classes/index.erb +28 -8
- data/app/views/zafu/default/Node-+adminLayout.zafu +1 -13
- data/app/views/zafu/default/Node-+login.zafu +1 -0
- data/app/views/zafu/default/Node-+notFound.zafu +1 -1
- data/app/views/zafu/default/Node-+popupLayout.zafu +1 -2
- data/app/views/zafu/default/Node-+search.zafu +1 -1
- data/app/views/zafu/default/Node-admin.zafu +205 -0
- data/app/views/zafu/default/Node.zafu +11 -11
- data/bricks/captcha/lib/bricks/captcha.rb +3 -2
- data/bricks/mongrel/zena/init.rb +2 -1
- data/bricks/pdf/README +5 -5
- data/bricks/pdf/lib/bricks/pdf/engine/prince.rb +2 -2
- data/bricks/pdf/lib/bricks/pdf/engine/xhtml2pdf.rb +2 -2
- data/bricks/pdf/lib/bricks/pdf/install.rb +5 -5
- data/bricks/pdf/lib/bricks/pdf.rb +11 -11
- data/bricks/pdf/test/engines/test_prince.rb +4 -4
- data/bricks/pdf/test/engines/test_xhtml2pdf.rb +4 -4
- data/bricks/pdf/test/shoulda_macros/shoulda_pdf.rb +2 -2
- data/bricks/pdf/zena/init.rb +2 -2
- data/bricks/pdf/zena/tasks.rb +2 -2
- data/bricks/sphinx/lib/bricks/sphinx.rb +6 -2
- data/bricks/sphinx/zena/{sphinx.yml → sphinx.yml.erb} +2 -2
- data/bricks/sphinx/zena/tasks.rb +28 -2
- data/bricks/tags/lib/bricks/tags.rb +16 -1
- data/bricks/tags/zena/test/unit/tags_test.rb +15 -0
- data/bricks/tags/zena/test/zafu/tags.yml +5 -1
- data/bricks/worker/lib/bricks/worker.rb +39 -0
- data/bricks/worker/zena/deploy.rb +0 -2
- data/bricks/worker/zena/init.rb +1 -0
- data/bricks/worker/zena/test/sites/zena/delayed_jobs.yml +16 -0
- data/bricks/worker/zena/test/zafu/worker.yml +8 -0
- data/bricks/zena/zena/migrate/01_base.rb +36 -60
- data/bricks/zena/zena/migrate/02_zerox1_schema.rb +388 -0
- data/bricks/zena/zena/migrate/03_zerox1_data.rb +380 -0
- data/bricks/zena/zena/migrate/20110315161158_add_reverse_scope_to_roles.rb +9 -0
- data/config/database_example.yml +1 -1
- data/config/environment.rb +1 -1
- data/config/gems.yml +17 -14
- data/db/init/base/skins/default/Node-+index.zafu +8 -1
- data/db/init/base/skins/default/Node-+login.zafu +1 -0
- data/db/init/base/skins/default/Node-+popupLayout.zafu +1 -2
- data/db/init/base/skins/default/Node-+search.zafu +2 -2
- data/db/init/base/skins/default/Node.zafu +9 -9
- data/db/init/base/skins/default/{favicon.png → img/favicon.png} +0 -0
- data/db/init/base/skins/default/{style.css → img/style.css} +0 -0
- data/db/init/base/skins/default/img/translations.yml +11 -0
- data/db/init/base/skins/default/notes.zafu +7 -9
- data/doc/zafu_changes.yml +12 -0
- data/lib/bricks/loader.rb +38 -15
- data/lib/tasks/zena.rake +74 -24
- data/lib/zena/acts/enrollable.rb +4 -1
- data/lib/zena/acts/secure.rb +2 -48
- data/lib/zena/acts/serializable.rb +13 -1
- data/lib/zena/app.rb +9 -0
- data/lib/zena/code_syntax.rb +154 -151
- data/lib/zena/console.rb +141 -0
- data/lib/zena/controller/test_case.rb +1 -1
- data/lib/zena/db_helper/abstract_db.rb +17 -5
- data/lib/zena/db_helper/mysql.rb +14 -12
- data/lib/zena/db_helper/postgresql.rb +1 -2
- data/lib/zena/db_helper/sqlite3.rb +6 -6
- data/lib/zena/deploy/awstats.conf.rhtml +1 -1
- data/lib/zena/deploy/httpd.rhtml +6 -1
- data/lib/zena/deploy/vhost.rhtml +9 -1
- data/lib/zena/deploy.rb +12 -7
- data/lib/zena/foxy_parser.rb +3 -1
- data/lib/zena/info.rb +1 -1
- data/lib/zena/parser/zafu_tags.rb +1 -0
- data/lib/zena/parser/zazen_rules.rb +1 -1
- data/lib/zena/remote/node.rb +15 -3
- data/lib/zena/remote/serializable_array.rb +19 -0
- data/lib/zena/remote.rb +1 -0
- data/lib/zena/routes.rb +7 -2
- data/lib/zena/site_worker.rb +11 -1
- data/lib/zena/unit/test_case.rb +68 -0
- data/lib/zena/use/action.rb +6 -2
- data/lib/zena/use/ajax.rb +127 -53
- data/lib/zena/use/ancestry.rb +11 -8
- data/lib/zena/use/calendar.rb +265 -129
- data/lib/zena/use/conditional.rb +1 -1
- data/lib/zena/use/context.rb +5 -5
- data/lib/zena/use/dates.rb +172 -60
- data/lib/zena/use/display.rb +70 -39
- data/lib/zena/use/error_rendering.rb +1 -3
- data/lib/zena/use/field_index.rb +4 -1
- data/lib/zena/use/forms.rb +94 -72
- data/lib/zena/use/fulltext.rb +16 -24
- data/lib/zena/use/html_tags.rb +20 -12
- data/lib/zena/use/i18n.rb +37 -37
- data/lib/zena/use/image_builder.rb +8 -1
- data/lib/zena/use/ml_index.rb +16 -16
- data/lib/zena/use/prop_eval.rb +10 -5
- data/lib/zena/use/query_builder.rb +55 -23
- data/lib/zena/use/query_node.rb +51 -25
- data/lib/zena/use/refactor.rb +2 -28
- data/lib/zena/use/relations.rb +1 -1
- data/lib/zena/use/rendering.rb +29 -0
- data/lib/zena/use/scope_index.rb +75 -14
- data/lib/zena/use/search.rb +5 -10
- data/lib/zena/use/test_helper.rb +2 -2
- data/lib/zena/use/urls.rb +125 -104
- data/lib/zena/use/workflow.rb +2 -1
- data/lib/zena/use/zafu_attributes.rb +2 -2
- data/lib/zena/use/zafu_safe_definitions.rb +20 -0
- data/lib/zena/use/zafu_templates.rb +20 -6
- data/lib/zena/use/zazen.rb +31 -20
- data/lib/zena/view/test_case.rb +5 -0
- data/lib/zena/zafu_compiler.rb +24 -2
- data/lib/zena.rb +12 -6
- data/locale/de/LC_MESSAGES/zena.mo +0 -0
- data/locale/de/zena.po +1345 -1164
- data/locale/en/LC_MESSAGES/zena.mo +0 -0
- data/locale/en/zena.po +1275 -1129
- data/locale/fr/LC_MESSAGES/zena.mo +0 -0
- data/locale/fr/zena.mo +0 -0
- data/locale/fr/zena.po +1617 -1441
- data/locale/log.txt +9 -0
- data/locale/zena.pot +957 -748
- data/public/javascripts/prototype.js +1 -1
- data/public/javascripts/zena.js +99 -44
- data/public/stylesheets/admin.css +6 -4
- data/public/stylesheets/backend.css +71 -0
- data/public/stylesheets/calendar.css +24 -25
- data/public/stylesheets/code.css +11 -6
- data/public/stylesheets/comment.css +2 -1
- data/public/stylesheets/popup.css +7 -8
- data/test/custom_queries/complex.host.yml +15 -1
- data/test/fixtures/files/Node-test.zafu +29 -28
- data/test/fixtures/files/translations_de.yml +12 -1
- data/test/fixtures/files/translations_fr.yml +12 -1
- data/test/functional/comments_controller_test.rb +9 -0
- data/test/functional/iformats_controller_test.rb +1 -1
- data/test/functional/nodes_controller_test.rb +124 -35
- data/test/functional/users_controller_test.rb +132 -3
- data/test/functional/virtual_classes_controller_test.rb +75 -4
- data/test/integration/navigation_test.rb +51 -9
- data/test/integration/query_node/basic.yml +19 -7
- data/test/integration/query_node/complex.yml +1 -1
- data/test/integration/query_node/dates.yml +27 -1
- data/test/integration/query_node/filters.yml +1 -1
- data/test/integration/query_node/relations.yml +13 -4
- data/test/integration/query_node_test.rb +4 -0
- data/test/integration/xml_api_test.rb +6 -1
- data/test/integration/zafu_compiler/action.yml +3 -3
- data/test/integration/zafu_compiler/ajax.yml +103 -22
- data/test/integration/zafu_compiler/basic.yml +0 -52
- data/test/integration/zafu_compiler/calendar.yml +44 -20
- data/test/integration/zafu_compiler/comments.yml +53 -0
- data/test/integration/zafu_compiler/complex.yml +11 -11
- data/test/integration/zafu_compiler/complex_ok.yml +16 -3
- data/test/integration/zafu_compiler/conditional.yml +15 -5
- data/test/integration/zafu_compiler/context.yml +9 -0
- data/test/integration/zafu_compiler/dates.yml +43 -15
- data/test/integration/zafu_compiler/display.yml +60 -6
- data/test/integration/zafu_compiler/errors.yml +6 -2
- data/test/integration/zafu_compiler/forms.yml +45 -6
- data/test/integration/zafu_compiler/i18n.yml +8 -1
- data/test/integration/zafu_compiler/meta.yml +38 -0
- data/test/integration/zafu_compiler/query.yml +43 -4
- data/test/integration/zafu_compiler/relations.yml +26 -33
- data/test/integration/zafu_compiler/rubyless.yml +10 -0
- data/test/integration/zafu_compiler/safe_definitions.yml +21 -1
- data/test/integration/zafu_compiler/urls.yml +75 -5
- data/test/integration/zafu_compiler/version.yml +2 -2
- data/test/integration/zafu_compiler/zafu_attributes.yml +5 -1
- data/test/integration/zafu_compiler/zazen.yml +14 -6
- data/test/integration/zafu_compiler_test.rb +5 -1
- data/test/sites/complex/columns.yml +5 -0
- data/test/sites/complex/roles.yml +4 -0
- data/test/sites/zena/nodes.yml +13 -2
- data/test/sites/zena/roles.yml +13 -5
- data/test/sites/zena/versions.yml +27 -9
- data/test/unit/column_test.rb +51 -5
- data/test/unit/iformat_test.rb +2 -2
- data/test/unit/node_test.rb +29 -17
- data/test/unit/note_test.rb +1 -1
- data/test/unit/relation_proxy_test.rb +4 -5
- data/test/unit/relation_test.rb +16 -0
- data/test/unit/remote_test.rb +2 -2
- data/test/unit/role_test.rb +292 -4
- data/test/unit/site_test.rb +12 -0
- data/test/unit/template_test.rb +1 -1
- data/test/unit/text_document_test.rb +1 -1
- data/test/unit/virtual_class_test.rb +200 -83
- data/test/unit/zena/acts/enrollable_test.rb +26 -31
- data/test/unit/zena/use/calendar_test.rb +90 -37
- data/test/unit/zena/use/field_index_test.rb +28 -0
- data/test/unit/zena/use/html_tags_test.rb +7 -3
- data/test/unit/zena/use/ml_index_test.rb +2 -16
- data/test/unit/zena/use/nested_attributes_alias_view_test.rb +2 -2
- data/test/unit/zena/use/prop_eval_test.rb +50 -8
- data/test/unit/zena/use/query_node_test.rb +11 -0
- data/test/unit/zena/use/rendering_test.rb +72 -0
- data/test/unit/zena/use/scope_index_test.rb +37 -2
- data/test/unit/zena/use/urls_test.rb +10 -0
- data/test/unit/zena/use/zazen_test.rb +3 -3
- data/vendor/plugins/gettext_i18n_rails/Gemfile +11 -0
- data/vendor/plugins/gettext_i18n_rails/Gemfile.lock +92 -0
- data/vendor/plugins/gettext_i18n_rails/Rakefile +12 -17
- data/vendor/plugins/gettext_i18n_rails/Readme.md +215 -0
- data/vendor/plugins/gettext_i18n_rails/VERSION +1 -1
- data/vendor/plugins/gettext_i18n_rails/gettext_i18n_rails.gemspec +38 -34
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/active_record.rb +1 -1
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/backend.rb +30 -14
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/haml_parser.rb +1 -1
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/html_safe_translations.rb +29 -0
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/i18n_hacks.rb +29 -1
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/model_attributes_finder.rb +7 -1
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/railtie.rb +10 -0
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/ruby_gettext_extractor.rb +6 -2
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/string_interpolate_fix.rb +20 -0
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/tasks.rb +120 -0
- data/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails.rb +10 -3
- data/vendor/plugins/gettext_i18n_rails/lib/tasks/gettext_rails_i18n.rake +1 -74
- data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb +51 -20
- data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb +12 -7
- data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb +32 -0
- data/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb +38 -1
- data/vendor/plugins/gettext_i18n_rails/spec/rails2/Gemfile +11 -0
- data/vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb +1 -8
- data/zena.gemspec +2241 -2217
- metadata +123 -83
- data/.gitignore +0 -36
- data/app/views/nodes/_dates.rhtml +0 -13
- data/db/init/base/skins/default/Node-+adminLayout.zafu +0 -46
- data/db/init/base/skins/default/Node-tree.zafu +0 -19
- data/vendor/plugins/gettext_i18n_rails/README.markdown +0 -143
@@ -1,58 +1,62 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gettext_i18n_rails}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-29}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.markdown"
|
16
|
-
]
|
17
14
|
s.files = [
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
15
|
+
"Gemfile",
|
16
|
+
"Gemfile.lock",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"gettext_i18n_rails.gemspec",
|
21
|
+
"init.rb",
|
22
|
+
"lib/gettext_i18n_rails.rb",
|
23
|
+
"lib/gettext_i18n_rails/action_controller.rb",
|
24
|
+
"lib/gettext_i18n_rails/active_record.rb",
|
25
|
+
"lib/gettext_i18n_rails/backend.rb",
|
26
|
+
"lib/gettext_i18n_rails/haml_parser.rb",
|
27
|
+
"lib/gettext_i18n_rails/html_safe_translations.rb",
|
28
|
+
"lib/gettext_i18n_rails/i18n_hacks.rb",
|
29
|
+
"lib/gettext_i18n_rails/model_attributes_finder.rb",
|
30
|
+
"lib/gettext_i18n_rails/railtie.rb",
|
31
|
+
"lib/gettext_i18n_rails/ruby_gettext_extractor.rb",
|
32
|
+
"lib/gettext_i18n_rails/string_interpolate_fix.rb",
|
33
|
+
"lib/gettext_i18n_rails/tasks.rb",
|
34
|
+
"lib/tasks/gettext_rails_i18n.rake",
|
35
|
+
"spec/gettext_i18n_rails/action_controller_spec.rb",
|
36
|
+
"spec/gettext_i18n_rails/active_record_spec.rb",
|
37
|
+
"spec/gettext_i18n_rails/backend_spec.rb",
|
38
|
+
"spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
|
39
|
+
"spec/gettext_i18n_rails_spec.rb",
|
40
|
+
"spec/rails2/Gemfile",
|
41
|
+
"spec/spec_helper.rb"
|
37
42
|
]
|
38
43
|
s.homepage = %q{http://github.com/grosser/gettext_i18n_rails}
|
39
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
40
44
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.
|
45
|
+
s.rubygems_version = %q{1.4.2}
|
42
46
|
s.summary = %q{Simple FastGettext Rails integration.}
|
43
47
|
s.test_files = [
|
44
|
-
"spec/
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
"spec/gettext_i18n_rails/action_controller_spec.rb",
|
49
|
+
"spec/gettext_i18n_rails/active_record_spec.rb",
|
50
|
+
"spec/gettext_i18n_rails/backend_spec.rb",
|
51
|
+
"spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
|
52
|
+
"spec/gettext_i18n_rails_spec.rb",
|
53
|
+
"spec/spec_helper.rb"
|
49
54
|
]
|
50
55
|
|
51
56
|
if s.respond_to? :specification_version then
|
52
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
57
|
s.specification_version = 3
|
54
58
|
|
55
|
-
if Gem::Version.new(Gem::
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
60
|
s.add_runtime_dependency(%q<fast_gettext>, [">= 0"])
|
57
61
|
else
|
58
62
|
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
@@ -14,21 +14,10 @@ module GettextI18nRails
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def translate(locale, key, options)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
_(flat_key)
|
17
|
+
if gettext_key = gettext_key(key, options)
|
18
|
+
translation = FastGettext._(gettext_key)
|
19
|
+
interpolate(translation, options)
|
21
20
|
else
|
22
|
-
if self.class.translate_defaults
|
23
|
-
[*options[:default]].each do |default|
|
24
|
-
#try the more specific key first e.g. 'activerecord.errors.my custom message'
|
25
|
-
flat_key = flatten_key default, options
|
26
|
-
return FastGettext._(flat_key) if FastGettext.key_exist?(flat_key)
|
27
|
-
|
28
|
-
#try the short key thereafter e.g. 'my custom message'
|
29
|
-
return FastGettext._(default) if FastGettext.key_exist?(default)
|
30
|
-
end
|
31
|
-
end
|
32
21
|
backend.translate locale, key, options
|
33
22
|
end
|
34
23
|
end
|
@@ -39,6 +28,33 @@ module GettextI18nRails
|
|
39
28
|
|
40
29
|
protected
|
41
30
|
|
31
|
+
def gettext_key(key, options)
|
32
|
+
flat_key = flatten_key key, options
|
33
|
+
if FastGettext.key_exist?(flat_key)
|
34
|
+
flat_key
|
35
|
+
elsif self.class.translate_defaults
|
36
|
+
[*options[:default]].each do |default|
|
37
|
+
#try the scoped(more specific) key first e.g. 'activerecord.errors.my custom message'
|
38
|
+
flat_key = flatten_key default, options
|
39
|
+
return flat_key if FastGettext.key_exist?(flat_key)
|
40
|
+
|
41
|
+
#try the short key thereafter e.g. 'my custom message'
|
42
|
+
return default if FastGettext.key_exist?(default)
|
43
|
+
end
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def interpolate(string, values)
|
49
|
+
reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+
|
50
|
+
I18n::RESERVED_KEYS
|
51
|
+
else
|
52
|
+
I18n::Backend::Base::RESERVED_KEYS
|
53
|
+
end
|
54
|
+
|
55
|
+
string % values.except(*reserved_keys)
|
56
|
+
end
|
57
|
+
|
42
58
|
def flatten_key key, options
|
43
59
|
scope = [*(options[:scope] || [])]
|
44
60
|
scope.empty? ? key.to_s : "#{scope*'.'}.#{key}"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module GettextI18nRails
|
2
|
+
mattr_accessor :translations_are_html_safe
|
3
|
+
|
4
|
+
module HtmlSafeTranslations
|
5
|
+
# also make available on class methods
|
6
|
+
def self.included(base)
|
7
|
+
base.extend self
|
8
|
+
end
|
9
|
+
|
10
|
+
def _(*args)
|
11
|
+
html_safe_if_wanted super
|
12
|
+
end
|
13
|
+
|
14
|
+
def n_(*args)
|
15
|
+
html_safe_if_wanted super
|
16
|
+
end
|
17
|
+
|
18
|
+
def s_(*args)
|
19
|
+
html_safe_if_wanted super
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def html_safe_if_wanted(text)
|
25
|
+
return text unless GettextI18nRails.translations_are_html_safe
|
26
|
+
text.to_s.html_safe
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,10 +1,38 @@
|
|
1
1
|
module I18n
|
2
2
|
module_function
|
3
|
-
|
3
|
+
|
4
4
|
def locale=(new_locale)
|
5
5
|
FastGettext.locale = new_locale
|
6
6
|
end
|
7
|
+
|
7
8
|
def locale
|
8
9
|
FastGettext.locale.to_sym
|
9
10
|
end
|
11
|
+
|
12
|
+
# since Rails 2.3.8 a config object is used instead of just .locale
|
13
|
+
if defined? Config
|
14
|
+
class Config
|
15
|
+
def locale
|
16
|
+
FastGettext.locale.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def locale=(new_locale)
|
20
|
+
FastGettext.locale=(new_locale)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# backport I18n.with_locale if it does not exist
|
26
|
+
unless respond_to?(:with_locale)
|
27
|
+
# Executes block with given I18n.locale set.
|
28
|
+
def with_locale(tmp_locale = nil)
|
29
|
+
if tmp_locale
|
30
|
+
current_locale = self.locale
|
31
|
+
self.locale = tmp_locale
|
32
|
+
end
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
self.locale = current_locale if tmp_locale
|
36
|
+
end
|
37
|
+
end
|
10
38
|
end
|
@@ -6,7 +6,12 @@ module GettextI18nRails
|
|
6
6
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
7
7
|
ModelAttributesFinder.new.find(options).each do |table_name,column_names|
|
8
8
|
#model name
|
9
|
-
|
9
|
+
begin
|
10
|
+
model = table_name.singularize.camelcase.constantize
|
11
|
+
rescue NameError
|
12
|
+
# Some tables are not models, for example: translation tables created by globalize2.
|
13
|
+
next
|
14
|
+
end
|
10
15
|
f.puts("_('#{model.human_name_without_translation}')")
|
11
16
|
|
12
17
|
#all columns namespaced under the model
|
@@ -18,6 +23,7 @@ module GettextI18nRails
|
|
18
23
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
19
24
|
end
|
20
25
|
end
|
26
|
+
module_function :store_model_attributes
|
21
27
|
|
22
28
|
class ModelAttributesFinder
|
23
29
|
# options:
|
@@ -44,7 +44,11 @@ module RubyGettextExtractor
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def run(content)
|
47
|
-
|
47
|
+
# ruby parser has an ugly bug which causes that several \000's take
|
48
|
+
# ages to parse. This avoids this probelm by stripping them away (they probably wont appear in keys anyway)
|
49
|
+
# See bug report: http://rubyforge.org/tracker/index.php?func=detail&aid=26898&group_id=439&atid=1778
|
50
|
+
safe_content = content.gsub(/\\\d\d\d/, '')
|
51
|
+
self.parse(safe_content)
|
48
52
|
return @results
|
49
53
|
end
|
50
54
|
|
@@ -109,7 +113,7 @@ module RubyGettextExtractor
|
|
109
113
|
def new_call recv, meth, args = nil
|
110
114
|
# we dont care if the method is called on a a object
|
111
115
|
if recv.nil?
|
112
|
-
if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext)
|
116
|
+
if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext || meth == :s_)
|
113
117
|
key = extract_key(args, "\004")
|
114
118
|
elsif meth == :n_
|
115
119
|
key = extract_key(args, "\000")
|
@@ -0,0 +1,20 @@
|
|
1
|
+
needed = "".respond_to?(:html_safe) and
|
2
|
+
(
|
3
|
+
"".html_safe % {:x => '<br/>'} == '<br/>' or
|
4
|
+
not ("".html_safe % {:x=>'a'}).html_safe?
|
5
|
+
)
|
6
|
+
|
7
|
+
if needed
|
8
|
+
class String
|
9
|
+
alias :interpolate_without_html_safe :%
|
10
|
+
|
11
|
+
def %(*args)
|
12
|
+
if args.first.is_a?(Hash) and html_safe?
|
13
|
+
safe_replacement = Hash[args.first.map{|k,v| [k,ERB::Util.h(v)] }]
|
14
|
+
interpolate_without_html_safe(safe_replacement).html_safe
|
15
|
+
else
|
16
|
+
interpolate_without_html_safe(*args).dup # make sure its not html_safe
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
namespace :gettext do
|
2
|
+
def load_gettext
|
3
|
+
require 'gettext'
|
4
|
+
require 'gettext/utils'
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Create mo-files for L10n"
|
8
|
+
task :pack => :environment do
|
9
|
+
load_gettext
|
10
|
+
GetText.create_mofiles(true, locale_path, locale_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Update pot/po files."
|
14
|
+
task :find => :environment do
|
15
|
+
load_gettext
|
16
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
|
17
|
+
require 'gettext_i18n_rails/haml_parser'
|
18
|
+
|
19
|
+
|
20
|
+
if GetText.respond_to? :update_pofiles_org
|
21
|
+
GetText.update_pofiles_org(
|
22
|
+
text_domain,
|
23
|
+
files_to_translate,
|
24
|
+
"version 0.0.1",
|
25
|
+
:po_root => locale_path,
|
26
|
+
:msgmerge=>['--sort-output']
|
27
|
+
)
|
28
|
+
else #we are on a version < 2.0
|
29
|
+
puts "install new GetText with gettext:install to gain more features..."
|
30
|
+
#kill ar parser...
|
31
|
+
require 'gettext/parser/active_record'
|
32
|
+
module GetText
|
33
|
+
module ActiveRecordParser
|
34
|
+
module_function
|
35
|
+
def init(x);end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#parse files.. (models are simply parsed as ruby files)
|
40
|
+
GetText.update_pofiles(
|
41
|
+
text_domain,
|
42
|
+
files_to_translate,
|
43
|
+
"version 0.0.1",
|
44
|
+
locale_path
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# This is more of an example, ignoring
|
50
|
+
# the columns/tables that mostly do not need translation.
|
51
|
+
# This can also be done with GetText::ActiveRecord
|
52
|
+
# but this crashed too often for me, and
|
53
|
+
# IMO which column should/should-not be translated does not
|
54
|
+
# belong into the model
|
55
|
+
#
|
56
|
+
# You can get your translations from GetText::ActiveRecord
|
57
|
+
# by adding this to you gettext:find task
|
58
|
+
#
|
59
|
+
# require 'active_record'
|
60
|
+
# gem "gettext_activerecord", '>=0.1.0' #download and install from github
|
61
|
+
# require 'gettext_activerecord/parser'
|
62
|
+
desc "write the model attributes to <locale_path>/model_attributes.rb"
|
63
|
+
task :store_model_attributes => :environment do
|
64
|
+
FastGettext.silence_errors
|
65
|
+
|
66
|
+
require 'gettext_i18n_rails/model_attributes_finder'
|
67
|
+
require 'gettext_i18n_rails/active_record'
|
68
|
+
|
69
|
+
storage_file = "#{locale_path}/model_attributes.rb"
|
70
|
+
puts "writing model translations to: #{storage_file}"
|
71
|
+
|
72
|
+
ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
|
73
|
+
GettextI18nRails.store_model_attributes(
|
74
|
+
:to => storage_file,
|
75
|
+
:ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],
|
76
|
+
:ignore_tables => ignore_tables
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "add a new language"
|
81
|
+
task :add_language, [:language] => :environment do |_, args|
|
82
|
+
language = args.language || ENV["LANGUAGE"]
|
83
|
+
|
84
|
+
# Let's do some pre-verification of the environment.
|
85
|
+
if language.nil?
|
86
|
+
puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:add_languange' or 'rake gettext:add_languange[eo]'"
|
87
|
+
next
|
88
|
+
end
|
89
|
+
pot = File.join(locale_path, "#{text_domain}.pot")
|
90
|
+
if !File.exists? pot
|
91
|
+
puts "You don't have a pot file yet, you probably should run 'rake gettext:find' at least once. Tried '#{pot}'."
|
92
|
+
next
|
93
|
+
end
|
94
|
+
|
95
|
+
# Create the directory for the new language.
|
96
|
+
dir = File.join(locale_path, language)
|
97
|
+
puts "Creating directory #{dir}"
|
98
|
+
Dir.mkdir dir
|
99
|
+
|
100
|
+
# Create the po file for the new language.
|
101
|
+
new_po = File.join(locale_path, language, "#{text_domain}.po")
|
102
|
+
puts "Initializing #{new_po} from #{pot}."
|
103
|
+
system "msginit --locale=#{language} --input=#{pot} --output=#{new_po}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def locale_path
|
107
|
+
FastGettext.translation_repositories[text_domain].instance_variable_get(:@options)[:path]
|
108
|
+
rescue
|
109
|
+
File.join(RAILS_ROOT, "locale")
|
110
|
+
end
|
111
|
+
|
112
|
+
def text_domain
|
113
|
+
# if your textdomain is not 'app': require the environment before calling e.g. gettext:find OR add TEXTDOMAIN=my_domain
|
114
|
+
ENV['TEXTDOMAIN'] || (FastGettext.text_domain rescue nil) || "app"
|
115
|
+
end
|
116
|
+
|
117
|
+
def files_to_translate
|
118
|
+
Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml}")
|
119
|
+
end
|
120
|
+
end
|
@@ -10,11 +10,18 @@ if Gem::Version.new(FastGettext::VERSION) < Gem::Version.new("0.4.8")
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# include translations into all the places it needs to go...
|
13
|
-
Object.send(:include,FastGettext::Translation)
|
13
|
+
Object.send(:include, FastGettext::Translation)
|
14
|
+
|
15
|
+
# make translations html_safe if possible and wanted
|
16
|
+
if "".respond_to?(:html_safe?)
|
17
|
+
require 'gettext_i18n_rails/html_safe_translations'
|
18
|
+
Object.send(:include, GettextI18nRails::HtmlSafeTranslations)
|
19
|
+
end
|
14
20
|
|
15
21
|
require 'gettext_i18n_rails/backend'
|
16
22
|
I18n.backend = GettextI18nRails::Backend.new
|
17
23
|
|
18
24
|
require 'gettext_i18n_rails/i18n_hacks'
|
19
|
-
require 'gettext_i18n_rails/active_record'
|
20
|
-
require 'gettext_i18n_rails/action_controller'
|
25
|
+
require 'gettext_i18n_rails/active_record' if defined?(ActiveRecord)
|
26
|
+
require 'gettext_i18n_rails/action_controller' if defined?(ActionController) # so that bundle console can work in a rails project
|
27
|
+
require 'gettext_i18n_rails/railtie'
|
@@ -1,74 +1 @@
|
|
1
|
-
|
2
|
-
def load_gettext
|
3
|
-
require 'gettext'
|
4
|
-
require 'gettext/utils'
|
5
|
-
end
|
6
|
-
|
7
|
-
desc "Create mo-files for L10n"
|
8
|
-
task :pack do
|
9
|
-
load_gettext
|
10
|
-
GetText.create_mofiles(true, "locale", "locale")
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Update pot/po files."
|
14
|
-
task :find do
|
15
|
-
load_gettext
|
16
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
|
17
|
-
require 'gettext_i18n_rails/haml_parser'
|
18
|
-
|
19
|
-
if GetText.respond_to? :update_pofiles_org
|
20
|
-
GetText.update_pofiles_org(
|
21
|
-
"app",
|
22
|
-
Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml}"),
|
23
|
-
"version 0.0.1",
|
24
|
-
:po_root => 'locale',
|
25
|
-
:msgmerge=>['--sort-output']
|
26
|
-
)
|
27
|
-
else #we are on a version < 2.0
|
28
|
-
puts "install new GetText with gettext:install to gain more features..."
|
29
|
-
#kill ar parser...
|
30
|
-
require 'gettext/parser/active_record'
|
31
|
-
module GetText
|
32
|
-
module ActiveRecordParser
|
33
|
-
module_function
|
34
|
-
def init(x);end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
#parse files.. (models are simply parsed as ruby files)
|
39
|
-
GetText.update_pofiles(
|
40
|
-
"app",
|
41
|
-
Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml}"),
|
42
|
-
"version 0.0.1",
|
43
|
-
'locale'
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# This is more of an example, ignoring
|
49
|
-
# the columns/tables that mostly do not need translation.
|
50
|
-
# This can also be done with GetText::ActiveRecord
|
51
|
-
# but this crashed too often for me, and
|
52
|
-
# IMO which column should/should-not be translated does not
|
53
|
-
# belong into the model
|
54
|
-
#
|
55
|
-
# You can get your translations from GetText::ActiveRecord
|
56
|
-
# by adding this to you gettext:find task
|
57
|
-
#
|
58
|
-
# require 'active_record'
|
59
|
-
# gem "gettext_activerecord", '>=0.1.0' #download and install from github
|
60
|
-
# require 'gettext_activerecord/parser'
|
61
|
-
desc "write the locale/model_attributes.rb"
|
62
|
-
task :store_model_attributes => :environment do
|
63
|
-
FastGettext.silence_errors
|
64
|
-
require 'gettext_i18n_rails/model_attributes_finder'
|
65
|
-
storage_file = 'locale/model_attributes.rb'
|
66
|
-
puts "writing model translations to: #{storage_file}"
|
67
|
-
ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions']
|
68
|
-
GettextI18nRails.store_model_attributes(
|
69
|
-
:to => storage_file,
|
70
|
-
:ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],
|
71
|
-
:ignore_tables => ignore_tables
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
1
|
+
require File.join(File.dirname(__FILE__), "/../gettext_i18n_rails/tasks")
|
@@ -12,10 +12,21 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
12
12
|
create_table :car_seats, :force=>true do |t|
|
13
13
|
t.string :seat_color
|
14
14
|
end
|
15
|
+
|
16
|
+
create_table :parts, :force=>true do |t|
|
17
|
+
t.string :name
|
18
|
+
t.references :car_seat
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
class CarSeat < ActiveRecord::Base
|
18
23
|
validates_presence_of :seat_color, :message=>"translate me"
|
24
|
+
has_many :parts
|
25
|
+
accepts_nested_attributes_for :parts
|
26
|
+
end
|
27
|
+
|
28
|
+
class Part < ActiveRecord::Base
|
29
|
+
belongs_to :car_seat
|
19
30
|
end
|
20
31
|
|
21
32
|
describe ActiveRecord::Base do
|
@@ -23,30 +34,50 @@ describe ActiveRecord::Base do
|
|
23
34
|
FastGettext.current_cache = {}
|
24
35
|
end
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
37
|
+
describe :human_name do
|
38
|
+
it "is translated through FastGettext" do
|
39
|
+
CarSeat.should_receive(:_).with('car seat').and_return('Autositz')
|
40
|
+
CarSeat.human_name.should == 'Autositz'
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
describe :human_attribute_name do
|
45
|
+
it "translates attributes through FastGettext" do
|
46
|
+
CarSeat.should_receive(:s_).with('CarSeat|Seat color').and_return('Sitz farbe')
|
47
|
+
CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe'
|
48
|
+
end
|
35
49
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
c.valid?
|
41
|
-
c.errors.on(:seat_color).should == "Übersetz mich!"
|
50
|
+
it "translates nested attributes through FastGettext" do
|
51
|
+
CarSeat.should_receive(:s_).with('CarSeat|Parts|Name').and_return('Handle')
|
52
|
+
CarSeat.human_attribute_name(:"parts.name").should == 'Handle'
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
describe 'error messages' do
|
57
|
+
let(:model){
|
58
|
+
c = CarSeat.new
|
59
|
+
c.valid?
|
60
|
+
c
|
61
|
+
}
|
62
|
+
|
63
|
+
it "translates error messages" do
|
64
|
+
FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz mich!")
|
65
|
+
FastGettext._('translate me').should == "Übersetz mich!"
|
66
|
+
model.errors.on(:seat_color).should == "Übersetz mich!"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "translates scoped error messages" do
|
70
|
+
pending 'scope is no longer added in 3.x' if ActiveRecord::VERSION::MAJOR >= 3
|
71
|
+
FastGettext.stub!(:current_repository).and_return('activerecord.errors.translate me'=>"Übersetz mich!")
|
72
|
+
FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!"
|
73
|
+
model.errors.on(:seat_color).should == "Übersetz mich!"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "translates error messages with %{fn}" do
|
77
|
+
pending
|
78
|
+
FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz %{fn} mich!")
|
79
|
+
FastGettext._('translate me').should == "Übersetz %{fn} mich!"
|
80
|
+
model.errors.on(:seat_color).should == "Übersetz car_seat mich!"
|
81
|
+
end
|
51
82
|
end
|
52
83
|
end
|