afalkear_translation_center 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +293 -0
- data/Rakefile +40 -0
- data/app/assets/images/translation_center/badr_it.png +0 -0
- data/app/assets/images/translation_center/loading.gif +0 -0
- data/app/assets/images/translation_center/translation_center_logo.png +0 -0
- data/app/assets/javascripts/translation_center/application.js +75 -0
- data/app/assets/javascripts/translation_center/bootstrap.js +2025 -0
- data/app/assets/javascripts/translation_center/categories.js +18 -0
- data/app/assets/javascripts/translation_center/center.js +55 -0
- data/app/assets/javascripts/translation_center/inspector.js.erb +59 -0
- data/app/assets/javascripts/translation_center/jquery-ui.js +14912 -0
- data/app/assets/javascripts/translation_center/jquery.jeditable.mini.js +38 -0
- data/app/assets/javascripts/translation_center/routes.js +15 -0
- data/app/assets/javascripts/translation_center/spin.min.js +1 -0
- data/app/assets/javascripts/translation_center/translation_keys.js +31 -0
- data/app/assets/javascripts/translation_center/translations.js +245 -0
- data/app/assets/stylesheets/translation_center/application.css +49 -0
- data/app/assets/stylesheets/translation_center/bootstrap.css +5894 -0
- data/app/assets/stylesheets/translation_center/categories.css +29 -0
- data/app/assets/stylesheets/translation_center/center.css +28 -0
- data/app/assets/stylesheets/translation_center/inspector.css +110 -0
- data/app/assets/stylesheets/translation_center/translation_keys.css +48 -0
- data/app/assets/stylesheets/translation_center/translations.css +32 -0
- data/app/controllers/translation_center/application_controller.rb +42 -0
- data/app/controllers/translation_center/categories_controller.rb +61 -0
- data/app/controllers/translation_center/center_controller.rb +67 -0
- data/app/controllers/translation_center/translation_keys_controller.rb +93 -0
- data/app/controllers/translation_center/translations_controller.rb +78 -0
- data/app/helpers/translation_center/application_helper.rb +58 -0
- data/app/helpers/translation_center/categories_helper.rb +4 -0
- data/app/helpers/translation_center/center_helper.rb +19 -0
- data/app/helpers/translation_center/translation_keys_helper.rb +4 -0
- data/app/helpers/translation_center/translations_helper.rb +4 -0
- data/app/models/translation_center/activity_query.rb +46 -0
- data/app/models/translation_center/category.rb +46 -0
- data/app/models/translation_center/translation.rb +94 -0
- data/app/models/translation_center/translation_key.rb +188 -0
- data/app/views/layouts/translation_center/application.html.haml +82 -0
- data/app/views/translation_center/categories/_category.html.haml +11 -0
- data/app/views/translation_center/categories/index.html.haml +7 -0
- data/app/views/translation_center/categories/keys.js.haml +10 -0
- data/app/views/translation_center/categories/show.html.haml +32 -0
- data/app/views/translation_center/categories/show.js.haml +7 -0
- data/app/views/translation_center/center/_activity.html.haml +49 -0
- data/app/views/translation_center/center/dashboard.html.haml +102 -0
- data/app/views/translation_center/center/manage.js.haml +3 -0
- data/app/views/translation_center/center/search_activity.js.haml +1 -0
- data/app/views/translation_center/errors/exception.html.haml +50 -0
- data/app/views/translation_center/translation_keys/_form.html.haml +18 -0
- data/app/views/translation_center/translation_keys/_show.html.haml +27 -0
- data/app/views/translation_center/translation_keys/_show_keys.html.haml +25 -0
- data/app/views/translation_center/translation_keys/_translation_keys.html.haml +16 -0
- data/app/views/translation_center/translation_keys/destroy.js.haml +4 -0
- data/app/views/translation_center/translation_keys/show.html.haml +8 -0
- data/app/views/translation_center/translation_keys/translations.js.haml +3 -0
- data/app/views/translation_center/translations/_accept_translation.html.haml +6 -0
- data/app/views/translation_center/translations/_index.html.haml +9 -0
- data/app/views/translation_center/translations/_search_results.html.haml +30 -0
- data/app/views/translation_center/translations/_show.html.haml +35 -0
- data/app/views/translation_center/translations/accept.js.haml +18 -0
- data/app/views/translation_center/translations/destroy.js.haml +11 -0
- data/app/views/translation_center/translations/search.html.haml +2 -0
- data/app/views/translation_center/translations/search.js.haml +1 -0
- data/app/views/translation_center/translations/unaccept.js.haml +9 -0
- data/app/views/translation_center/translations/unvote.js.haml +1 -0
- data/app/views/translation_center/translations/vote.js.haml +1 -0
- data/config/routes.rb +34 -0
- data/lib/afalkear_translation_center.rb +12 -0
- data/lib/generators/translation_center/USAGE +6 -0
- data/lib/generators/translation_center/add_lang/add_lang_generator.rb +31 -0
- data/lib/generators/translation_center/add_lang/templates/migrations/add_lang_status_translation_keys.rb +5 -0
- data/lib/generators/translation_center/install/install_generator.rb +38 -0
- data/lib/generators/translation_center/install/templates/assets/translation_center_logo.png +0 -0
- data/lib/generators/translation_center/install/templates/config/translation_center.yml +55 -0
- data/lib/generators/translation_center/install/templates/migrations/create_translation_center_categories.rb +9 -0
- data/lib/generators/translation_center/install/templates/migrations/create_translation_center_translation_keys.rb +16 -0
- data/lib/generators/translation_center/install/templates/migrations/create_translation_center_translations.rb +32 -0
- data/lib/tasks/translation_center.rake +56 -0
- data/lib/translation_center/acts_as_translator.rb +22 -0
- data/lib/translation_center/engine.rb +15 -0
- data/lib/translation_center/locale/en.yml +75 -0
- data/lib/translation_center/translation_helpers.rb +133 -0
- data/lib/translation_center/translations_transfer.rb +131 -0
- data/lib/translation_center/version.rb +3 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/images/translation_center_logo.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +16 -0
- data/test/dummy/app/assets/javascripts/articles.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +14 -0
- data/test/dummy/app/assets/stylesheets/articles.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +6 -0
- data/test/dummy/app/controllers/articles_controller.rb +85 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/articles_helper.rb +2 -0
- data/test/dummy/app/models/article.rb +7 -0
- data/test/dummy/app/models/user.rb +16 -0
- data/test/dummy/app/views/articles/_form.html.haml +16 -0
- data/test/dummy/app/views/articles/edit.html.haml +7 -0
- data/test/dummy/app/views/articles/index.html.haml +32 -0
- data/test/dummy/app/views/articles/new.html.haml +5 -0
- data/test/dummy/app/views/articles/show.html.haml +14 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/config/application.rb +60 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +42 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/devise.rb +240 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/ar.yml +6 -0
- data/test/dummy/config/locales/de.yml +2 -0
- data/test/dummy/config/locales/devise.en.yml +59 -0
- data/test/dummy/config/locales/en.yml +361 -0
- data/test/dummy/config/routes.rb +10 -0
- data/test/dummy/config/translation_center.yml +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20130410082611_devise_create_users.rb +46 -0
- data/test/dummy/db/migrate/20130410082701_create_articles.rb +10 -0
- data/test/dummy/db/migrate/20130410084711234392_create_translation_center_categories.rb +9 -0
- data/test/dummy/db/migrate/20130410084711235054_create_translation_center_translation_keys.rb +14 -0
- data/test/dummy/db/migrate/20130410084711235601_create_translation_center_translations.rb +13 -0
- data/test/dummy/db/migrate/20130410084711235602_install_audited.rb +28 -0
- data/test/dummy/db/migrate/20130410084711_acts_as_votable_migration.rb +23 -0
- data/test/dummy/db/migrate/20130410113111070575_add_de_status_translation_center_translation_keys.rb +5 -0
- data/test/dummy/db/migrate/20130417134539377014_add_ar_status_translation_center_translation_keys.rb +5 -0
- data/test/dummy/db/migrate/20130506103956_fix_translation_user_relation.rb +12 -0
- data/test/dummy/db/migrate/20130801102022_add_indicies.rb +8 -0
- data/test/dummy/db/schema.rb +110 -0
- data/test/dummy/log/test.log +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/spec/spec_helper.rb +38 -0
- data/test/dummy/test/fixtures/articles.yml +9 -0
- data/test/dummy/test/fixtures/posts.yml +9 -0
- data/test/dummy/test/fixtures/users.yml +11 -0
- data/test/dummy/test/functional/articles_controller_test.rb +49 -0
- data/test/dummy/test/functional/posts_controller_test.rb +49 -0
- data/test/dummy/test/unit/article_test.rb +7 -0
- data/test/dummy/test/unit/helpers/articles_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
- data/test/dummy/test/unit/post_test.rb +7 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/fixtures/translation_center/categories.yml +7 -0
- data/test/fixtures/translation_center/translation_keys.yml +11 -0
- data/test/fixtures/translation_center/translations.yml +15 -0
- data/test/functional/translation_center/categories_controller_test.rb +51 -0
- data/test/functional/translation_center/center_controller_test.rb +9 -0
- data/test/functional/translation_center/translation_keys_controller_test.rb +51 -0
- data/test/functional/translation_center/translations_controller_test.rb +51 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/translation_center_test.rb +7 -0
- data/test/unit/helpers/translation_center/categories_helper_test.rb +6 -0
- data/test/unit/helpers/translation_center/center_helper_test.rb +6 -0
- data/test/unit/helpers/translation_center/translation_keys_helper_test.rb +6 -0
- data/test/unit/helpers/translation_center/translations_helper_test.rb +6 -0
- data/test/unit/translation_center/category_test.rb +9 -0
- data/test/unit/translation_center/translation_key_test.rb +9 -0
- data/test/unit/translation_center/translation_test.rb +9 -0
- metadata +418 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'jquery-rails'
|
2
|
+
require 'jquery-ui-rails'
|
3
|
+
require 'haml'
|
4
|
+
require 'haml-rails'
|
5
|
+
require 'acts_as_votable'
|
6
|
+
require 'ya2yaml'
|
7
|
+
require 'font-awesome-rails'
|
8
|
+
require 'audited-activerecord'
|
9
|
+
|
10
|
+
module TranslationCenter
|
11
|
+
|
12
|
+
class Engine < ::Rails::Engine
|
13
|
+
isolate_namespace TranslationCenter
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
en:
|
2
|
+
translation_center:
|
3
|
+
pagination:
|
4
|
+
next: Next
|
5
|
+
first: First
|
6
|
+
prev: Prev.
|
7
|
+
last: Last
|
8
|
+
actions:
|
9
|
+
are_you_sure: "Are you sure ?"
|
10
|
+
back_to_app: "Back To App"
|
11
|
+
categories:
|
12
|
+
category:
|
13
|
+
complete: Complete
|
14
|
+
keys: Keys
|
15
|
+
index:
|
16
|
+
categories: Categories
|
17
|
+
show:
|
18
|
+
all: All
|
19
|
+
pending: Pending
|
20
|
+
translated: Translated
|
21
|
+
untranslated: Untranslated
|
22
|
+
center:
|
23
|
+
activity:
|
24
|
+
ago: ago
|
25
|
+
changes: Changes
|
26
|
+
key: Key
|
27
|
+
locale: Locale
|
28
|
+
time: Time
|
29
|
+
user: User
|
30
|
+
dashboard:
|
31
|
+
activity: Activity
|
32
|
+
all: All
|
33
|
+
controls: Controls
|
34
|
+
dashboard: Dashboard
|
35
|
+
language: Language
|
36
|
+
pending: Pending
|
37
|
+
progress: Progress
|
38
|
+
reset: Reset
|
39
|
+
search: Search
|
40
|
+
select_locale: "Select Locale"
|
41
|
+
these_actions_will_affect_existing_data: "These actions will affect existing data"
|
42
|
+
translated: Translated
|
43
|
+
untranslated: Untranslated
|
44
|
+
search:
|
45
|
+
title: "Keys with translations that contain '%{value}'"
|
46
|
+
dashboard: Dashboard
|
47
|
+
search_keys: "Keys"
|
48
|
+
search_translations: "Translations"
|
49
|
+
translate_to: "Translate To"
|
50
|
+
translation_center: "Translation Center"
|
51
|
+
translation_keys:
|
52
|
+
destroyed_successfully: "Destroyed Successfully"
|
53
|
+
show:
|
54
|
+
translations: Translations
|
55
|
+
add_edit_translation: "Add/Edit Translation"
|
56
|
+
back_to_category: "Back to"
|
57
|
+
destroy: Destroy
|
58
|
+
show_keys:
|
59
|
+
created_on: "created on"
|
60
|
+
translated: Translated
|
61
|
+
translation_keys:
|
62
|
+
no_translation_keys: "No Translation Keys"
|
63
|
+
translations:
|
64
|
+
accept_translation:
|
65
|
+
unaccept: Unaccept
|
66
|
+
index:
|
67
|
+
date: Date
|
68
|
+
sort_by: "Sort by"
|
69
|
+
votings: Votes
|
70
|
+
show:
|
71
|
+
by: by
|
72
|
+
on_date: "on"
|
73
|
+
vote: Vote
|
74
|
+
votings: Votes
|
75
|
+
you: You
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module TranslationCenter
|
2
|
+
|
3
|
+
# Return the default translator by building and returning the translator object
|
4
|
+
def self.prepare_translator
|
5
|
+
|
6
|
+
translator = TranslationCenter::CONFIG['translator_type'].camelize.constantize.where(TranslationCenter::CONFIG['identifier_type'] => TranslationCenter::CONFIG['yaml_translator_identifier']).first
|
7
|
+
|
8
|
+
# if translator doesn't exist then create him
|
9
|
+
if translator.blank?
|
10
|
+
translator = TranslationCenter::CONFIG['translator_type'].camelize.constantize.new
|
11
|
+
translator.send "#{TranslationCenter::CONFIG['identifier_type']}=", TranslationCenter::CONFIG['yaml_translator_identifier']
|
12
|
+
begin
|
13
|
+
translator.save(validate: false)
|
14
|
+
# needed if the user is using confirmable with devise
|
15
|
+
translator.update_attribute(:confirmed_at, Time.now) if translator.attributes.has_key?('confirmed_at')
|
16
|
+
rescue
|
17
|
+
translator = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
translator
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.class_eval do
|
25
|
+
alias_method_chain :translate, :adding if(TranslationCenter::CONFIG['enabled'])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# wraps a span if inspector option is set to all
|
30
|
+
def wrap_span(translation, translation_key)
|
31
|
+
# put the inspector class if inspector is all and the key doesn't belongs to translation_center
|
32
|
+
if TranslationCenter::CONFIG['inspector'] == 'all' && translation_key.name.to_s.split('.').first != 'translation_center'
|
33
|
+
"<span class='tc-inspector-key' data-locale='#{I18n.locale}' data-type='#{translation_key.status(I18n.locale)}' data-id='#{translation_key.id}'> #{translation} </span>".html_safe
|
34
|
+
else
|
35
|
+
translation
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# make sure the complete key is build using the options such as scope and count
|
40
|
+
def prepare_key(key, options)
|
41
|
+
complete_key = key
|
42
|
+
|
43
|
+
# if a scope is passed in options then build the full key
|
44
|
+
complete_key = options[:scope].present? ? "#{options[:scope].to_s}.#{complete_key}" : complete_key
|
45
|
+
|
46
|
+
# add the correct count suffix
|
47
|
+
if options[:count].present? && options[:count] == 1
|
48
|
+
complete_key = "#{complete_key}.one"
|
49
|
+
elsif options[:count].present? && options[:count] != 1
|
50
|
+
complete_key = "#{complete_key}.other"
|
51
|
+
end
|
52
|
+
complete_key
|
53
|
+
end
|
54
|
+
|
55
|
+
def translate_with_adding(locale, key, options = {})
|
56
|
+
# handle calling translation with a blank key
|
57
|
+
# or translation center tables don't exist
|
58
|
+
return translate_without_adding(locale, key, options) if key.blank? || !ActiveRecord::Base.connection.table_exists?('translation_center_translation_keys')
|
59
|
+
|
60
|
+
complete_key = prepare_key(key, options) # prepare complete key
|
61
|
+
|
62
|
+
# add the new key or update it
|
63
|
+
translation_key = TranslationCenter::TranslationKey.find_or_create_by_name(complete_key)
|
64
|
+
# UNCOMMENT THIS LATER TO SET LAST ACCESSED AT
|
65
|
+
# translation_key.update_attribute(:last_accessed, Time.now)
|
66
|
+
|
67
|
+
# save the default value (Which is the titleized key name as the translation) if the option is enabled and no translation exists for that key in the db
|
68
|
+
translation_key.create_default_translation if TranslationCenter::CONFIG['save_default_translation'] && translation_key.translations.in(:en).empty? && !translation_key.has_children?
|
69
|
+
|
70
|
+
# if i18n_source is set to db and not overriden by options then fetch from db
|
71
|
+
if TranslationCenter::CONFIG['i18n_source'] == 'db' && options.delete(:yaml).blank?
|
72
|
+
val = translation_key.accepted_translation_in(locale).try(:value) || options[:default]
|
73
|
+
# replace variables in a translation with passed values
|
74
|
+
options.each_pair{ |key, value| val.gsub!("%{#{key.to_s}}", value.to_s) } if val.is_a?(String)
|
75
|
+
|
76
|
+
if val.blank? && !translation_key.has_children?
|
77
|
+
throw(:exception, I18n::MissingTranslation.new(locale, complete_key, options))
|
78
|
+
elsif translation_key.has_children?
|
79
|
+
# TODO should use ancestors for keys
|
80
|
+
return translation_key.children_translations(locale)
|
81
|
+
end
|
82
|
+
wrap_span(val, translation_key)
|
83
|
+
else
|
84
|
+
translation_value = translate_without_adding(locale, key, options)
|
85
|
+
translation_value.class == Hash ? translation_value : wrap_span(translation_value, translation_key)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# load tha translation config
|
91
|
+
if FileTest.exists?("config/translation_center.yml")
|
92
|
+
TranslationCenter::CONFIG = YAML.load_file("config/translation_center.yml")[Rails.env]
|
93
|
+
# identifier is by default email
|
94
|
+
TranslationCenter::CONFIG['identifier_type'] ||= 'email'
|
95
|
+
TranslationCenter::CONFIG['translator_type'] ||= 'User'
|
96
|
+
else
|
97
|
+
puts "WARNING: translation_center will be using default options if config/translation_center.yml doesn't exists"
|
98
|
+
TranslationCenter::CONFIG = {'enabled' => false, 'inspector' => 'missing', 'lang' => {'en' => {'name' => 'English', 'direction' => 'ltr'}}, 'yaml_translator_identifier' => 'coder@tc.com', 'i18n_source' => 'yaml', 'yaml2db_translations_accepted' => true,
|
99
|
+
'accept_admin_translations' => true, 'save_default_translation' => true, 'identifier_type' => 'email', 'translator_type' => 'User' }
|
100
|
+
end
|
101
|
+
I18n.available_locales = TranslationCenter::CONFIG['lang'].keys
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
# override html_message to add a class to the returned span
|
106
|
+
module I18n
|
107
|
+
class MissingTranslation
|
108
|
+
module Base
|
109
|
+
# added another class to be used
|
110
|
+
def html_message
|
111
|
+
category = keys.first
|
112
|
+
key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
|
113
|
+
translation_key = keys
|
114
|
+
# remove locale
|
115
|
+
translation_key.shift
|
116
|
+
|
117
|
+
translation_key = TranslationCenter::TranslationKey.find_by_name(translation_key.join('.'))
|
118
|
+
# don't put the inspector class if inspector is off or the key belongs to translation_center
|
119
|
+
if TranslationCenter::CONFIG['inspector'] == 'off' || category == 'translation_center'
|
120
|
+
%(<span class="translation_missing" title="translation missing: #{keys.join('.')}">#{key}</span>)
|
121
|
+
else
|
122
|
+
%(<span class="translation_missing tc-inspector-key" data-locale='#{I18n.locale}' data-type="#{translation_key.status(I18n.locale)}" data-id="#{translation_key.id}" title="translation missing: #{keys.join('.')}">#{key}</span>)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
I18n::Backend::Base.send :include, TranslationCenter
|
131
|
+
|
132
|
+
|
133
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module TranslationCenter
|
2
|
+
|
3
|
+
# needed for interpolated translations in I18n
|
4
|
+
def self.get_translation_from_hash(key, hash)
|
5
|
+
path = key.split('.')
|
6
|
+
last_step = hash
|
7
|
+
path.each do |step|
|
8
|
+
break if last_step.blank? || !last_step.is_a?(Hash)
|
9
|
+
last_step = last_step[step.to_s.to_sym]
|
10
|
+
end
|
11
|
+
last_step
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.collect_keys(scope, translations)
|
15
|
+
full_keys = []
|
16
|
+
translations.to_a.each do |key, translations|
|
17
|
+
new_scope = scope.dup << key
|
18
|
+
if translations.is_a?(Hash)
|
19
|
+
full_keys += collect_keys(new_scope, translations)
|
20
|
+
else
|
21
|
+
full_keys << new_scope.join('.')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
return full_keys
|
25
|
+
end
|
26
|
+
|
27
|
+
# gets the translation of a a key in certian lang and inserts it in the db
|
28
|
+
# returns true if the translation was fonud in yaml
|
29
|
+
def self.yaml2db_key(locale, translation_key, translator, all_yamls)
|
30
|
+
I18n.locale = locale
|
31
|
+
translation = TranslationCenter::Translation.find_or_initialize_by_translation_key_id_and_lang_and_translator_id(translation_key.id, locale.to_s, translator.id)
|
32
|
+
translation.translator_type = TranslationCenter::CONFIG['translator_type']
|
33
|
+
|
34
|
+
# get the translation for this key from the yamls
|
35
|
+
value = get_translation_from_hash(translation_key.name, all_yamls[locale])
|
36
|
+
|
37
|
+
# if the value is not empty and is different from the existing value the update
|
38
|
+
if !value.blank? && value != translation.value
|
39
|
+
translation.update_attribute(:value, value)
|
40
|
+
# accept this yaml translation
|
41
|
+
translation.accept if TranslationCenter::CONFIG['yaml2db_translations_accepted']
|
42
|
+
true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# takes array of keys and creates/updates the keys in the db with translations in the given locales
|
47
|
+
def self.yaml2db_keys(keys, translator, locales, all_yamls)
|
48
|
+
# initialize stats variables
|
49
|
+
new_keys = 0
|
50
|
+
missing_keys = locales.inject({}) do |memo, lang|
|
51
|
+
memo[lang] = 0
|
52
|
+
memo
|
53
|
+
end
|
54
|
+
|
55
|
+
# for each key create it in the db if it doesn't exist, and add its translation to
|
56
|
+
# the db in every locale
|
57
|
+
keys.each do |key|
|
58
|
+
|
59
|
+
translation_key = TranslationCenter::TranslationKey.find_or_initialize_by_name(key)
|
60
|
+
if translation_key.new_record?
|
61
|
+
translation_key.save
|
62
|
+
new_keys += 1
|
63
|
+
end
|
64
|
+
|
65
|
+
# for each locale create/update its translation
|
66
|
+
locales.each do |locale|
|
67
|
+
missing_keys[locale] += 1 unless self.yaml2db_key(locale, translation_key, translator, all_yamls)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "found new #{new_keys} key(s)"
|
73
|
+
missing_keys.each do |locale, count|
|
74
|
+
puts "missing #{count} translation(s) for #{locale}" if count > 0
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# take the yaml translations and update the db with them
|
79
|
+
def self.yaml2db(locale=nil)
|
80
|
+
|
81
|
+
# prepare translator by creating the translator if he doesn't exist
|
82
|
+
translator = TranslationCenter.prepare_translator
|
83
|
+
|
84
|
+
# if couldn't create translator then print error msg and quit
|
85
|
+
if translator.blank?
|
86
|
+
puts "ERROR: Unable to create default translator with #{TranslationCenter::CONFIG['identifier_type']} = #{TranslationCenter::CONFIG['yaml_translator_identifier']}"
|
87
|
+
puts "Create this user manually and run the rake again"
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
|
91
|
+
# Make sure we've loaded the translations
|
92
|
+
I18n.backend.send(:init_translations)
|
93
|
+
puts "#{I18n.available_locales.size} #{I18n.available_locales.size == 1 ? 'locale' : 'locales'} available: #{I18n.available_locales.join(', ')}"
|
94
|
+
|
95
|
+
# Get all keys from all locales
|
96
|
+
all_yamls = I18n.backend.send(:translations)
|
97
|
+
all_keys = all_yamls.collect do |check_locale, translations|
|
98
|
+
collect_keys([], translations).sort
|
99
|
+
end.flatten.uniq
|
100
|
+
|
101
|
+
puts "#{all_keys.size} #{all_keys.size == 1 ? 'unique key' : 'unique keys'} found."
|
102
|
+
|
103
|
+
locales = locale.blank? ? I18n.available_locales : [locale.to_sym]
|
104
|
+
|
105
|
+
# create records for all keys that exist in the yaml
|
106
|
+
yaml2db_keys(all_keys, translator, locales, all_yamls)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.db2yaml(locale=nil)
|
110
|
+
locales = locale.blank? ? I18n.available_locales : [locale.to_sym]
|
111
|
+
|
112
|
+
# for each locale build a hash for the translations and write to file
|
113
|
+
locales.each do |locale|
|
114
|
+
result = {}
|
115
|
+
I18n.locale = locale
|
116
|
+
puts "Started exporting translations in #{locale}"
|
117
|
+
TranslationCenter::TranslationKey.translated(locale).each do |key|
|
118
|
+
begin
|
119
|
+
key.add_to_hash(result, locale)
|
120
|
+
rescue
|
121
|
+
puts "Error writing key: #{key.name} to yaml for #{locale}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
File.open("config/locales/#{locale.to_s}.yml", 'w') do |file|
|
125
|
+
file.write({locale.to_s => result}.ya2yaml)
|
126
|
+
end
|
127
|
+
puts "Done exporting translations of #{locale} to #{locale.to_s}.yml"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| |-- images
|
161
|
+
| |-- javascripts
|
162
|
+
| `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| `-- tasks
|
177
|
+
|-- log
|
178
|
+
|-- public
|
179
|
+
|-- script
|
180
|
+
|-- test
|
181
|
+
| |-- fixtures
|
182
|
+
| |-- functional
|
183
|
+
| |-- integration
|
184
|
+
| |-- performance
|
185
|
+
| `-- unit
|
186
|
+
|-- tmp
|
187
|
+
| |-- cache
|
188
|
+
| |-- pids
|
189
|
+
| |-- sessions
|
190
|
+
| `-- sockets
|
191
|
+
`-- vendor
|
192
|
+
|-- assets
|
193
|
+
`-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
16
|
+
//= require translation_center/inspector
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*= require translation_center/inspector
|
14
|
+
*/
|