Class: Tr8n::Config
- Inherits:
-
Object
- Object
- Tr8n::Config
- Defined in:
- lib/tr8n/config.rb
Class Method Summary collapse
- .admin_helpers ⇒ Object
- .admin_level ⇒ Object
- .admin_user?(user = Tr8n::Config.current_user) ⇒ Boolean
- .after_filters ⇒ Object
- .allow_nil_token_values? ⇒ Boolean
- .api ⇒ Object
- .api_after_filters ⇒ Object
- .api_before_filters ⇒ Object
- .api_skip_before_filters ⇒ Object
- .application_level ⇒ Object
-
.application_translator_for(user) ⇒ Object
only one allowed per application.
- .before_filters ⇒ Object
- .block_options ⇒ Object
- .cache_adapter ⇒ Object
- .cache_store ⇒ Object
- .cache_version ⇒ Object
-
.caching ⇒ Object
Config Sections.
- .config ⇒ Object
- .current_language ⇒ Object
- .current_locale_method ⇒ Object
- .current_source ⇒ Object
-
.current_translator ⇒ Object
when this method is called, we create the translator record right away and from this point on, will track the user this can happen any time user tries to translate something or enables inline translations.
- .current_user ⇒ Object
- .current_user_is_admin? ⇒ Boolean
- .current_user_is_guest? ⇒ Boolean
- .current_user_is_translator? ⇒ Boolean
- .current_user_method ⇒ Object
- .data_token_classes ⇒ Object
- .decoration_token_classes ⇒ Object
- .default_abbr_day_names ⇒ Object
- .default_abbr_month_names ⇒ Object
- .default_client_interval ⇒ Object
- .default_data_tokens ⇒ Object
- .default_date_formats ⇒ Object
- .default_date_rules(locale = default_locale) ⇒ Object
- .default_day_names ⇒ Object
- .default_decoration_tokens ⇒ Object
- .default_gender_list_rules(locale = default_locale) ⇒ Object
- .default_gender_rules(locale = default_locale) ⇒ Object
- .default_glossary ⇒ Object
- .default_language ⇒ Object
- .default_language_cases_for(locale = default_locale) ⇒ Object
- .default_languages ⇒ Object
- .default_list_rules(locale = default_locale) ⇒ Object
- .default_locale ⇒ Object
- .default_month_names ⇒ Object
- .default_numeric_rules(locale = default_locale) ⇒ Object
- .default_rank_styles ⇒ Object
- .default_shortcuts ⇒ Object
- .default_translation_key_level ⇒ Object
- .default_url ⇒ Object
- .default_value_rules(locale = default_locale) ⇒ Object
- .disabled? ⇒ Boolean
- .dump_config ⇒ Object
- .effects_library_path ⇒ Object
- .enable_admin_inline_mode? ⇒ Boolean
- .enable_admin_translations? ⇒ Boolean
-
.enable_api? ⇒ Boolean
API.
- .enable_browser_cache? ⇒ Boolean
-
.enable_caching? ⇒ Boolean
Caching.
- .enable_client_sdk? ⇒ Boolean
- .enable_country_tracking? ⇒ Boolean
- .enable_dictionary_lookup? ⇒ Boolean
- .enable_effects? ⇒ Boolean
- .enable_fallback_languages? ⇒ Boolean
- .enable_glossary_hints? ⇒ Boolean
- .enable_google_suggestions? ⇒ Boolean
- .enable_inline_translations? ⇒ Boolean
- .enable_key_caller_tracking? ⇒ Boolean
- .enable_key_source_tracking? ⇒ Boolean
- .enable_key_verification? ⇒ Boolean
- .enable_keyboard_shortcuts? ⇒ Boolean
- .enable_language_cases? ⇒ Boolean
- .enable_language_flags? ⇒ Boolean
- .enable_language_stats? ⇒ Boolean
-
.enable_logger? ⇒ Boolean
Logger.
- .enable_paranoia_mode? ⇒ Boolean
- .enable_registration_disclaimer? ⇒ Boolean
- .enable_software_keyboard? ⇒ Boolean
- .enable_tr8n_method ⇒ Object
- .enable_translator_language? ⇒ Boolean
- .enable_translator_tabs? ⇒ Boolean
- .enabled? ⇒ Boolean
- .env ⇒ Object
- .features ⇒ Object
- .google_api_key ⇒ Object
- .guest_user?(user = Tr8n::Config.current_user) ⇒ Boolean
-
.init(site_current_locale, site_current_user = nil, site_current_source = nil) ⇒ Object
initializes language, user and translator the variables are kept in a thread safe form throughout the request.
- .init_default_languages ⇒ Object
- .init_glossary ⇒ Object
-
.language_rule_classes ⇒ Object
rules engine.
- .language_rule_dependencies ⇒ Object
- .language_rule_suffixes ⇒ Object
- .language_rules_for_suffix(suffix) ⇒ Object
-
.load_default_rules(rules_type, locale = default_locale) ⇒ Object
get rules for specified locale, or get default language rules.
-
.load_json(file_path) ⇒ Object
json support.
- .load_yml(file_path, for_env = env) ⇒ Object
- .localization ⇒ Object
- .log_path ⇒ Object
- .logger ⇒ Object
- .manager_level ⇒ Object
- .models ⇒ Object
- .multiple_base_languages? ⇒ Boolean
- .open_registration_mode? ⇒ Boolean
- .registration_disclaimer_path ⇒ Object
- .reset! ⇒ Object
-
.reset_all! ⇒ Object
will clean all tables and initialize default values never ever do it on live !!!.
- .root ⇒ Object
- .rules_engine ⇒ Object
- .silhouette_image ⇒ Object
- .site_info ⇒ Object
-
.site_title ⇒ Object
Site Info.
-
.site_user_info ⇒ Object
site user info The following methods could be overloaded in the initializer.
- .site_user_info_disabled? ⇒ Boolean
- .site_user_info_enabled? ⇒ Boolean
- .sitemap_sections ⇒ Object
- .skip_before_filters ⇒ Object
- .splash_screen ⇒ Object
-
.strftime_symbol_to_token(symbol) ⇒ Object
localization.
- .synchronization ⇒ Object
- .synchronization_all_languages? ⇒ Boolean
-
.synchronization_batch_size ⇒ Object
Sync Process.
- .synchronization_key ⇒ Object
- .synchronization_push_enabled? ⇒ Boolean
- .synchronization_push_servers ⇒ Object
- .synchronization_secret ⇒ Object
- .synchronization_server ⇒ Object
- .system_image ⇒ Object
- .system_level ⇒ Object
-
.system_translator ⇒ Object
only one allowed per system.
- .tr8n_helpers ⇒ Object
- .translation_threshold ⇒ Object
- .translator_levels ⇒ Object
-
.translator_roles ⇒ Object
Translator Roles and Levels.
- .universal_language_rules ⇒ Object
- .user_class ⇒ Object
- .user_class_name ⇒ Object
- .user_gender(user) ⇒ Object
- .user_id(user) ⇒ Object
- .user_link(user) ⇒ Object
- .user_locale(user) ⇒ Object
- .user_mugshot(user) ⇒ Object
- .user_name(user) ⇒ Object
- .viewing_user_token_for(label) ⇒ Object
Class Method Details
.admin_helpers ⇒ Object
413 414 415 416 |
# File 'lib/tr8n/config.rb', line 413 def self.admin_helpers return [] unless site_info[:admin_helpers] @admin_helpers ||= site_info[:admin_helpers].collect{|helper| helper.to_sym} end |
.admin_level ⇒ Object
736 737 738 |
# File 'lib/tr8n/config.rb', line 736 def self.admin_level 10000 end |
.admin_user?(user = Tr8n::Config.current_user) ⇒ Boolean
510 511 512 513 514 515 516 |
# File 'lib/tr8n/config.rb', line 510 def self.admin_user?(user = Tr8n::Config.current_user) return false unless user user.send(site_user_info[:methods][:admin]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} admin flag: #{ex.to_s}") false end |
.after_filters ⇒ Object
428 429 430 431 |
# File 'lib/tr8n/config.rb', line 428 def self.after_filters return [] unless site_info[:after_filters] @after_filters ||= site_info[:after_filters].collect{|filter| filter.to_sym} end |
.allow_nil_token_values? ⇒ Boolean
595 596 597 |
# File 'lib/tr8n/config.rb', line 595 def self.allow_nil_token_values? rules_engine[:allow_nil_token_values] end |
.api ⇒ Object
323 324 325 |
# File 'lib/tr8n/config.rb', line 323 def self.api config[:api] end |
.api_after_filters ⇒ Object
781 782 783 784 |
# File 'lib/tr8n/config.rb', line 781 def self.api_after_filters return [] unless api[:after_filters] @api_after_filters ||= api[:after_filters].collect{|filter| filter.to_sym} end |
.api_before_filters ⇒ Object
776 777 778 779 |
# File 'lib/tr8n/config.rb', line 776 def self.api_before_filters return [] unless api[:before_filters] @api_before_filters ||= api[:before_filters].collect{|filter| filter.to_sym} end |
.api_skip_before_filters ⇒ Object
771 772 773 774 |
# File 'lib/tr8n/config.rb', line 771 def self.api_skip_before_filters return [] unless api[:skip_before_filters] @api_skip_before_filters ||= api[:skip_before_filters].collect{|filter| filter.to_sym} end |
.application_level ⇒ Object
740 741 742 |
# File 'lib/tr8n/config.rb', line 740 def self.application_level 100000 end |
.application_translator_for(user) ⇒ Object
only one allowed per application
80 81 82 |
# File 'lib/tr8n/config.rb', line 80 def self.application_translator_for(user) Tr8n::Translator.where(:user_id => user.id, :level => application_level).first || Tr8n::Translator.create(:user_id => user.id, :level => application_level) end |
.before_filters ⇒ Object
423 424 425 426 |
# File 'lib/tr8n/config.rb', line 423 def self.before_filters return [] unless site_info[:before_filters] @before_filters ||= site_info[:before_filters].collect{|filter| filter.to_sym} end |
.block_options ⇒ Object
58 59 60 |
# File 'lib/tr8n/config.rb', line 58 def self. Thread.current[:tr8n_block_options] ||= {} end |
.cache_adapter ⇒ Object
337 338 339 |
# File 'lib/tr8n/config.rb', line 337 def self.cache_adapter caching[:adapter] end |
.cache_store ⇒ Object
341 342 343 |
# File 'lib/tr8n/config.rb', line 341 def self.cache_store caching[:store] end |
.cache_version ⇒ Object
345 346 347 |
# File 'lib/tr8n/config.rb', line 345 def self.cache_version caching[:version] end |
.caching ⇒ Object
Config Sections
303 304 305 |
# File 'lib/tr8n/config.rb', line 303 def self.caching config[:caching] end |
.config ⇒ Object
169 170 171 |
# File 'lib/tr8n/config.rb', line 169 def self.config @config ||= load_yml("/config/tr8n/config.yml") end |
.current_language ⇒ Object
50 51 52 |
# File 'lib/tr8n/config.rb', line 50 def self.current_language Thread.current[:tr8n_current_language] ||= default_language end |
.current_locale_method ⇒ Object
388 389 390 |
# File 'lib/tr8n/config.rb', line 388 def self.current_locale_method site_info[:current_locale_method] end |
.current_source ⇒ Object
46 47 48 |
# File 'lib/tr8n/config.rb', line 46 def self.current_source Thread.current[:tr8n_current_source] end |
.current_translator ⇒ Object
when this method is called, we create the translator record right away and from this point on, will track the user this can happen any time user tries to translate something or enables inline translations
65 66 67 |
# File 'lib/tr8n/config.rb', line 65 def self.current_translator Thread.current[:tr8n_current_translator] ||= Tr8n::Translator.register end |
.current_user ⇒ Object
42 43 44 |
# File 'lib/tr8n/config.rb', line 42 def self.current_user Thread.current[:tr8n_current_user] end |
.current_user_is_admin? ⇒ Boolean
518 519 520 |
# File 'lib/tr8n/config.rb', line 518 def self.current_user_is_admin? admin_user? end |
.current_user_is_guest? ⇒ Boolean
530 531 532 |
# File 'lib/tr8n/config.rb', line 530 def self.current_user_is_guest? guest_user? end |
.current_user_is_translator? ⇒ Boolean
54 55 56 |
# File 'lib/tr8n/config.rb', line 54 def self.current_user_is_translator? Thread.current[:tr8n_current_translator] != nil end |
.current_user_method ⇒ Object
441 442 443 |
# File 'lib/tr8n/config.rb', line 441 def self.current_user_method site_user_info[:current_user_method] end |
.data_token_classes ⇒ Object
599 600 601 |
# File 'lib/tr8n/config.rb', line 599 def self.data_token_classes @data_token_classes ||= rules_engine[:data_token_classes].collect{|tc| tc.constantize} end |
.decoration_token_classes ⇒ Object
603 604 605 |
# File 'lib/tr8n/config.rb', line 603 def self.decoration_token_classes @decoration_token_classes ||= rules_engine[:decoration_token_classes].collect{|tc| tc.constantize} end |
.default_abbr_day_names ⇒ Object
699 700 701 |
# File 'lib/tr8n/config.rb', line 699 def self.default_abbr_day_names localization[:default_abbr_day_names] end |
.default_abbr_month_names ⇒ Object
707 708 709 |
# File 'lib/tr8n/config.rb', line 707 def self.default_abbr_month_names localization[:default_abbr_month_names] end |
.default_client_interval ⇒ Object
767 768 769 |
# File 'lib/tr8n/config.rb', line 767 def self.default_client_interval 5000 end |
.default_data_tokens ⇒ Object
181 182 183 |
# File 'lib/tr8n/config.rb', line 181 def self.default_data_tokens @default_data_tokens ||= load_yml("/config/tr8n/tokens/data.yml", nil) end |
.default_date_formats ⇒ Object
711 712 713 |
# File 'lib/tr8n/config.rb', line 711 def self.default_date_formats localization[:custom_date_formats] end |
.default_date_rules(locale = default_locale) ⇒ Object
653 654 655 |
# File 'lib/tr8n/config.rb', line 653 def self.default_date_rules(locale = default_locale) load_default_rules("date", locale) end |
.default_day_names ⇒ Object
695 696 697 |
# File 'lib/tr8n/config.rb', line 695 def self.default_day_names localization[:default_day_names] end |
.default_decoration_tokens ⇒ Object
177 178 179 |
# File 'lib/tr8n/config.rb', line 177 def self.default_decoration_tokens @default_decoration_tokens ||= load_yml("/config/tr8n/tokens/decorations.yml", nil) end |
.default_gender_list_rules(locale = default_locale) ⇒ Object
641 642 643 |
# File 'lib/tr8n/config.rb', line 641 def self.default_gender_list_rules(locale = default_locale) load_default_rules("gender_list", locale) end |
.default_gender_rules(locale = default_locale) ⇒ Object
637 638 639 |
# File 'lib/tr8n/config.rb', line 637 def self.default_gender_rules(locale = default_locale) load_default_rules("gender", locale) end |
.default_glossary ⇒ Object
185 186 187 |
# File 'lib/tr8n/config.rb', line 185 def self.default_glossary @default_glossary ||= load_yml("/config/tr8n/site/default_glossary.yml", nil) end |
.default_language ⇒ Object
69 70 71 72 |
# File 'lib/tr8n/config.rb', line 69 def self.default_language return Tr8n::Language.new(:locale => default_locale) if disabled? @default_language ||= Tr8n::Language.for(default_locale) || Tr8n::Language.new(:locale => default_locale) end |
.default_language_cases_for(locale = default_locale) ⇒ Object
661 662 663 664 665 |
# File 'lib/tr8n/config.rb', line 661 def self.default_language_cases_for(locale = default_locale) @default_cases ||= load_yml("/config/tr8n/rules/default_language_cases.yml", nil) return [] unless @default_cases[locale.to_s] @default_cases[locale.to_s].values end |
.default_languages ⇒ Object
173 174 175 |
# File 'lib/tr8n/config.rb', line 173 def self.default_languages @default_languages ||= load_yml("/config/tr8n/site/default_languages.yml", nil) end |
.default_list_rules(locale = default_locale) ⇒ Object
645 646 647 |
# File 'lib/tr8n/config.rb', line 645 def self.default_list_rules(locale = default_locale) load_default_rules("list", locale) end |
.default_locale ⇒ Object
375 376 377 378 |
# File 'lib/tr8n/config.rb', line 375 def self.default_locale return [:default_locale] if [:default_locale] site_info[:default_locale] end |
.default_month_names ⇒ Object
703 704 705 |
# File 'lib/tr8n/config.rb', line 703 def self.default_month_names localization[:default_month_names] end |
.default_numeric_rules(locale = default_locale) ⇒ Object
649 650 651 |
# File 'lib/tr8n/config.rb', line 649 def self.default_numeric_rules(locale = default_locale) load_default_rules("numeric", locale) end |
.default_rank_styles ⇒ Object
615 616 617 618 619 620 621 622 623 624 |
# File 'lib/tr8n/config.rb', line 615 def self.default_rank_styles @default_rank_styles ||= begin styles = {} rules_engine[:translation_rank_styles].each do |key, value| range = Range.new(*(key.to_s.split("..").map{|v| v.to_i})) styles[range] = value end styles end end |
.default_shortcuts ⇒ Object
217 218 219 |
# File 'lib/tr8n/config.rb', line 217 def self.default_shortcuts @default_shortcuts ||= load_yml("/config/tr8n/site/shortcuts.yml", nil) end |
.default_translation_key_level ⇒ Object
748 749 750 |
# File 'lib/tr8n/config.rb', line 748 def self.default_translation_key_level config[:default_translation_key_level] || 0 end |
.default_url ⇒ Object
384 385 386 |
# File 'lib/tr8n/config.rb', line 384 def self.default_url site_info[:default_url] end |
.default_value_rules(locale = default_locale) ⇒ Object
657 658 659 |
# File 'lib/tr8n/config.rb', line 657 def self.default_value_rules(locale = default_locale) load_default_rules("value", locale) end |
.disabled? ⇒ Boolean
205 206 207 |
# File 'lib/tr8n/config.rb', line 205 def self.disabled? not enabled? end |
.dump_config ⇒ Object
165 166 167 |
# File 'lib/tr8n/config.rb', line 165 def self.dump_config save_to_yaml("config.yaml", config) end |
.effects_library_path ⇒ Object
400 401 402 |
# File 'lib/tr8n/config.rb', line 400 def self.effects_library_path site_info[:effects_library_path] end |
.enable_admin_inline_mode? ⇒ Boolean
289 290 291 |
# File 'lib/tr8n/config.rb', line 289 def self.enable_admin_inline_mode? config[:enable_admin_inline_mode] end |
.enable_admin_translations? ⇒ Boolean
285 286 287 |
# File 'lib/tr8n/config.rb', line 285 def self.enable_admin_translations? config[:enable_admin_translations] end |
.enable_api? ⇒ Boolean
API
755 756 757 |
# File 'lib/tr8n/config.rb', line 755 def self.enable_api? api[:enabled] end |
.enable_browser_cache? ⇒ Boolean
763 764 765 |
# File 'lib/tr8n/config.rb', line 763 def self.enable_browser_cache? config[:enable_browser_cache] end |
.enable_caching? ⇒ Boolean
Caching
333 334 335 |
# File 'lib/tr8n/config.rb', line 333 def self.enable_caching? caching[:enabled] end |
.enable_client_sdk? ⇒ Boolean
759 760 761 |
# File 'lib/tr8n/config.rb', line 759 def self.enable_client_sdk? config[:enable_client_sdk] end |
.enable_country_tracking? ⇒ Boolean
293 294 295 |
# File 'lib/tr8n/config.rb', line 293 def self.enable_country_tracking? config[:enable_country_tracking] end |
.enable_dictionary_lookup? ⇒ Boolean
253 254 255 |
# File 'lib/tr8n/config.rb', line 253 def self.enable_dictionary_lookup? config[:enable_dictionary_lookup] end |
.enable_effects? ⇒ Boolean
404 405 406 |
# File 'lib/tr8n/config.rb', line 404 def self.enable_effects? site_info[:enable_effects] end |
.enable_fallback_languages? ⇒ Boolean
277 278 279 |
# File 'lib/tr8n/config.rb', line 277 def self.enable_fallback_languages? config[:enable_fallback_languages] end |
.enable_glossary_hints? ⇒ Boolean
249 250 251 |
# File 'lib/tr8n/config.rb', line 249 def self.enable_glossary_hints? config[:enable_glossary_hints] end |
.enable_google_suggestions? ⇒ Boolean
241 242 243 |
# File 'lib/tr8n/config.rb', line 241 def self.enable_google_suggestions? config[:enable_google_suggestions] end |
.enable_inline_translations? ⇒ Boolean
221 222 223 |
# File 'lib/tr8n/config.rb', line 221 def self.enable_inline_translations? config[:enable_inline_translations] end |
.enable_key_caller_tracking? ⇒ Boolean
233 234 235 |
# File 'lib/tr8n/config.rb', line 233 def self.enable_key_caller_tracking? config[:enable_key_caller_tracking] end |
.enable_key_source_tracking? ⇒ Boolean
229 230 231 |
# File 'lib/tr8n/config.rb', line 229 def self.enable_key_source_tracking? config[:enable_key_source_tracking] end |
.enable_key_verification? ⇒ Boolean
237 238 239 |
# File 'lib/tr8n/config.rb', line 237 def self.enable_key_verification? config[:enable_key_verification] end |
.enable_keyboard_shortcuts? ⇒ Boolean
213 214 215 |
# File 'lib/tr8n/config.rb', line 213 def self.enable_keyboard_shortcuts? config[:enable_keyboard_shortcuts] end |
.enable_language_cases? ⇒ Boolean
225 226 227 |
# File 'lib/tr8n/config.rb', line 225 def self.enable_language_cases? config[:enable_language_cases] end |
.enable_language_flags? ⇒ Boolean
257 258 259 |
# File 'lib/tr8n/config.rb', line 257 def self.enable_language_flags? config[:enable_language_flags] end |
.enable_language_stats? ⇒ Boolean
261 262 263 |
# File 'lib/tr8n/config.rb', line 261 def self.enable_language_stats? config[:enable_language_stats] end |
.enable_logger? ⇒ Boolean
Logger
352 353 354 |
# File 'lib/tr8n/config.rb', line 352 def self.enable_logger? logger[:enabled] end |
.enable_paranoia_mode? ⇒ Boolean
360 361 362 |
# File 'lib/tr8n/config.rb', line 360 def self.enable_paranoia_mode? logger[:enable_paranoia_mode] end |
.enable_registration_disclaimer? ⇒ Boolean
269 270 271 |
# File 'lib/tr8n/config.rb', line 269 def self.enable_registration_disclaimer? config[:enable_registration_disclaimer] end |
.enable_software_keyboard? ⇒ Boolean
209 210 211 |
# File 'lib/tr8n/config.rb', line 209 def self.enable_software_keyboard? config[:enable_software_keyboard] end |
.enable_tr8n_method ⇒ Object
392 393 394 |
# File 'lib/tr8n/config.rb', line 392 def self.enable_tr8n_method site_info[:enable_tr8n_method] end |
.enable_translator_language? ⇒ Boolean
281 282 283 |
# File 'lib/tr8n/config.rb', line 281 def self.enable_translator_language? config[:enable_translator_language] end |
.enable_translator_tabs? ⇒ Boolean
297 298 299 |
# File 'lib/tr8n/config.rb', line 297 def self.enable_translator_tabs? config[:enable_translator_tabs] end |
.enabled? ⇒ Boolean
201 202 203 |
# File 'lib/tr8n/config.rb', line 201 def self.enabled? config[:enable_tr8n] end |
.env ⇒ Object
147 148 149 |
# File 'lib/tr8n/config.rb', line 147 def self.env Rails.env end |
.features ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/tr8n/config.rb', line 189 def self.features @features ||= begin defs = load_yml("/config/tr8n/site/features.yml") feats = [] defs[:enabled_features].each do |key| defs[key][:key] = key feats << defs[key] end feats end end |
.google_api_key ⇒ Object
245 246 247 |
# File 'lib/tr8n/config.rb', line 245 def self.google_api_key config[:google_api_key] end |
.guest_user?(user = Tr8n::Config.current_user) ⇒ Boolean
522 523 524 525 526 527 528 |
# File 'lib/tr8n/config.rb', line 522 def self.guest_user?(user = Tr8n::Config.current_user) return true unless user user.send(site_user_info[:methods][:guest]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} guest flag: #{ex.to_s}") true end |
.init(site_current_locale, site_current_user = nil, site_current_source = nil) ⇒ Object
initializes language, user and translator the variables are kept in a thread safe form throughout the request
34 35 36 37 38 39 40 |
# File 'lib/tr8n/config.rb', line 34 def self.init(site_current_locale, site_current_user = nil, site_current_source = nil) Thread.current[:tr8n_current_language] = Tr8n::Language.for(site_current_locale) || default_language Thread.current[:tr8n_current_user] = site_current_user Thread.current[:tr8n_current_translator] = Tr8n::Translator.for(site_current_user) Thread.current[:tr8n_current_source] = site_current_source Thread.current[:tr8n_block_options] = {} end |
.init_default_languages ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/tr8n/config.rb', line 123 def self.init_default_languages puts "Initializing default languages..." default_languages.each do |locale, info| puts ">> Initializing #{info[:english_name]}..." lang = Tr8n::Language.find_or_create(locale, info[:english_name]) info[:right_to_left] = false if info[:right_to_left].nil? fallback_key = info.delete(:fallback_key) lang.update_attributes(info) lang.reset! end puts "Created #{default_languages.size} languages." end |
.init_glossary ⇒ Object
136 137 138 139 140 141 |
# File 'lib/tr8n/config.rb', line 136 def self.init_glossary puts "Initializing default glossary..." default_glossary.each do |keyword, description| Tr8n::Glossary.create(:keyword => keyword, :description => description) end end |
.language_rule_classes ⇒ Object
rules engine
545 546 547 |
# File 'lib/tr8n/config.rb', line 545 def self.language_rule_classes @language_rule_classes ||= rules_engine[:language_rule_classes].collect{|lrc| lrc.constantize} end |
.language_rule_dependencies ⇒ Object
549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/tr8n/config.rb', line 549 def self.language_rule_dependencies @language_rule_dependencies ||= begin depts = HashWithIndifferentAccess.new language_rule_classes.each do |cls| if depts[cls.dependency] raise Tr8n::Exception.new("The same dependency key #{cls.dependency} has been registered for multiple rules. This is not allowed.") end depts[cls.dependency] = cls end depts end end |
.language_rule_suffixes ⇒ Object
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/tr8n/config.rb', line 573 def self.language_rule_suffixes @language_rule_suffixes ||= begin sfx = {} language_rule_classes.each do |cls| next unless cls.suffixes.is_a?(Array) cls.suffixes.each do |suffix| if suffix.index("_") raise Tr8n::Exception.new("Incorrect rule suffix: #{suffix}. Suffix may not have '_' in it.") end sfx[suffix] ||= [] sfx[suffix] << cls end end sfx end end |
.language_rules_for_suffix(suffix) ⇒ Object
590 591 592 593 |
# File 'lib/tr8n/config.rb', line 590 def self.language_rules_for_suffix(suffix) suffix_rules = language_rule_suffixes[suffix] || [] suffix_rules + universal_language_rules end |
.load_default_rules(rules_type, locale = default_locale) ⇒ Object
get rules for specified locale, or get default language rules
627 628 629 630 631 632 633 634 635 |
# File 'lib/tr8n/config.rb', line 627 def self.load_default_rules(rules_type, locale = default_locale) @default_rules ||= {} @default_rules[rules_type] ||= load_yml("/config/tr8n/rules/default_#{rules_type}_rules.yml", nil) rules_for_locale = @default_rules[rules_type][locale.to_s] return rules_for_locale.values unless rules_for_locale.nil? return [] if @default_rules[rules_type][default_locale].nil? @default_rules[rules_type][default_locale].values end |
.load_json(file_path) ⇒ Object
json support
152 153 154 155 156 157 |
# File 'lib/tr8n/config.rb', line 152 def self.load_json(file_path) json = JSON.parse(File.read("#{root}#{file_path}")) return HashWithIndifferentAccess.new(json) if json.is_a?(Hash) map = {"map" => json} HashWithIndifferentAccess.new(map)[:map] end |
.load_yml(file_path, for_env = env) ⇒ Object
159 160 161 162 163 |
# File 'lib/tr8n/config.rb', line 159 def self.load_yml(file_path, for_env = env) yml = YAML.load_file("#{root}#{file_path}") yml = yml['defaults'].rmerge(yml[for_env] || {}) unless for_env.nil? HashWithIndifferentAccess.new(yml) end |
.localization ⇒ Object
319 320 321 |
# File 'lib/tr8n/config.rb', line 319 def self.localization config[:localization] end |
.log_path ⇒ Object
356 357 358 |
# File 'lib/tr8n/config.rb', line 356 def self.log_path logger[:log_path] end |
.logger ⇒ Object
307 308 309 |
# File 'lib/tr8n/config.rb', line 307 def self.logger config[:logger] end |
.manager_level ⇒ Object
732 733 734 |
# File 'lib/tr8n/config.rb', line 732 def self.manager_level 1000 end |
.models ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tr8n/config.rb', line 93 def self.models [ Tr8n::LanguageRule, Tr8n::LanguageUser, Tr8n::Language, Tr8n::LanguageMetric, Tr8n::LanguageCase, Tr8n::LanguageCaseValueMap, Tr8n::LanguageCaseRule, Tr8n::TranslationKey, Tr8n::TranslationKeySource, Tr8n::TranslationKeyComment, Tr8n::TranslationKeyLock, Tr8n::TranslationSource, Tr8n::TranslationDomain, Tr8n::TranslationSourceLanguage, Tr8n::Translation, Tr8n::TranslationVote, Tr8n::Translator, Tr8n::TranslatorLog, Tr8n::TranslatorMetric, Tr8n::TranslatorFollowing, Tr8n::TranslatorReport, Tr8n::LanguageForumTopic, Tr8n::LanguageForumMessage, Tr8n::LanguageForumAbuseReport, Tr8n::Glossary, Tr8n::IpLocation, Tr8n::SyncLog ] end |
.multiple_base_languages? ⇒ Boolean
380 381 382 |
# File 'lib/tr8n/config.rb', line 380 def self.multiple_base_languages? 'en-US' == default_locale end |
.open_registration_mode? ⇒ Boolean
265 266 267 |
# File 'lib/tr8n/config.rb', line 265 def self.open_registration_mode? config[:open_registration_mode] end |
.registration_disclaimer_path ⇒ Object
273 274 275 |
# File 'lib/tr8n/config.rb', line 273 def self.registration_disclaimer_path config[:registration_disclaimer_path] || "/tr8n/common/terms_of_service" end |
.reset! ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/tr8n/config.rb', line 84 def self.reset! # thread based variables Thread.current[:tr8n_current_language] = nil Thread.current[:tr8n_current_user] = nil Thread.current[:tr8n_current_translator] = nil Thread.current[:tr8n_block_options] = nil Thread.current[:tr8n_current_source] = nil end |
.reset_all! ⇒ Object
will clean all tables and initialize default values never ever do it on live !!!
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/tr8n/config.rb', line 109 def self.reset_all! puts "Resetting tr8n tables..." models.each do |cls| puts ">> Resetting #{cls.name}..." cls.delete_all end puts "Done." init_default_languages init_glossary puts "Done." end |
.root ⇒ Object
143 144 145 |
# File 'lib/tr8n/config.rb', line 143 def self.root Rails.root end |
.rules_engine ⇒ Object
315 316 317 |
# File 'lib/tr8n/config.rb', line 315 def self.rules_engine config[:rules_engine] end |
.silhouette_image ⇒ Object
534 535 536 |
# File 'lib/tr8n/config.rb', line 534 def self.silhouette_image "/assets/tr8n/photo_silhouette.gif" end |
.site_info ⇒ Object
311 312 313 |
# File 'lib/tr8n/config.rb', line 311 def self.site_info config[:site_info] end |
.site_title ⇒ Object
Site Info
367 368 369 |
# File 'lib/tr8n/config.rb', line 367 def self.site_title site_info[:title] end |
.site_user_info ⇒ Object
site user info The following methods could be overloaded in the initializer
437 438 439 |
# File 'lib/tr8n/config.rb', line 437 def self.site_user_info site_info[:user_info] end |
.site_user_info_disabled? ⇒ Boolean
449 450 451 |
# File 'lib/tr8n/config.rb', line 449 def self.site_user_info_disabled? !site_user_info_enabled? end |
.site_user_info_enabled? ⇒ Boolean
445 446 447 |
# File 'lib/tr8n/config.rb', line 445 def self.site_user_info_enabled? site_user_info[:enabled].nil? ? true : site_user_info[:enabled] end |
.sitemap_sections ⇒ Object
396 397 398 |
# File 'lib/tr8n/config.rb', line 396 def self.sitemap_sections @sitemap_sections ||= load_json(site_info[:sitemap_path]) end |
.skip_before_filters ⇒ Object
418 419 420 421 |
# File 'lib/tr8n/config.rb', line 418 def self.skip_before_filters return [] unless site_info[:skip_before_filters] @skip_before_filters ||= site_info[:skip_before_filters].collect{|filter| filter.to_sym} end |
.splash_screen ⇒ Object
371 372 373 |
# File 'lib/tr8n/config.rb', line 371 def self.splash_screen site_info[:splash_screen] end |
.strftime_symbol_to_token(symbol) ⇒ Object
localization
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/tr8n/config.rb', line 671 def self.strftime_symbol_to_token(symbol) { "%a" => "{short_week_day_name}", "%A" => "{week_day_name}", "%b" => "{short_month_name}", "%B" => "{month_name}", "%p" => "{am_pm}", "%d" => "{days}", "%e" => "{day_of_month}", "%j" => "{year_days}", "%m" => "{months}", "%W" => "{week_num}", "%w" => "{week_days}", "%y" => "{short_years}", "%Y" => "{years}", "%l" => "{trimed_hour}", "%H" => "{full_hours}", "%I" => "{short_hours}", "%M" => "{minutes}", "%S" => "{seconds}", "%s" => "{since_epoch}" }[symbol] end |
.synchronization ⇒ Object
327 328 329 |
# File 'lib/tr8n/config.rb', line 327 def self.synchronization config[:synchronization] end |
.synchronization_all_languages? ⇒ Boolean
806 807 808 |
# File 'lib/tr8n/config.rb', line 806 def self.synchronization_all_languages? synchronization[:all_languages] end |
.synchronization_batch_size ⇒ Object
Sync Process
790 791 792 |
# File 'lib/tr8n/config.rb', line 790 def self.synchronization_batch_size synchronization[:batch_size] end |
.synchronization_key ⇒ Object
798 799 800 |
# File 'lib/tr8n/config.rb', line 798 def self.synchronization_key synchronization[:key] end |
.synchronization_push_enabled? ⇒ Boolean
810 811 812 |
# File 'lib/tr8n/config.rb', line 810 def self.synchronization_push_enabled? synchronization[:enable_push] end |
.synchronization_push_servers ⇒ Object
814 815 816 |
# File 'lib/tr8n/config.rb', line 814 def self.synchronization_push_servers synchronization[:push_servers] end |
.synchronization_secret ⇒ Object
802 803 804 |
# File 'lib/tr8n/config.rb', line 802 def self.synchronization_secret synchronization[:secret] end |
.synchronization_server ⇒ Object
794 795 796 |
# File 'lib/tr8n/config.rb', line 794 def self.synchronization_server synchronization[:server] end |
.system_image ⇒ Object
538 539 540 |
# File 'lib/tr8n/config.rb', line 538 def self.system_image "/assets/tr8n/photo_system.gif" end |
.system_level ⇒ Object
744 745 746 |
# File 'lib/tr8n/config.rb', line 744 def self.system_level 1000000 end |
.system_translator ⇒ Object
only one allowed per system
75 76 77 |
# File 'lib/tr8n/config.rb', line 75 def self.system_translator @system_translator ||= Tr8n::Translator.where(:level => system_level).first || Tr8n::Translator.create(:user_id => 0, :level => system_level) end |
.tr8n_helpers ⇒ Object
408 409 410 411 |
# File 'lib/tr8n/config.rb', line 408 def self.tr8n_helpers return [] unless site_info[:tr8n_helpers] @tr8n_helpers ||= site_info[:tr8n_helpers].collect{|helper| helper.to_sym} end |
.translation_threshold ⇒ Object
611 612 613 |
# File 'lib/tr8n/config.rb', line 611 def self.translation_threshold rules_engine[:translation_threshold] end |
.translator_levels ⇒ Object
722 723 724 725 726 727 728 729 730 |
# File 'lib/tr8n/config.rb', line 722 def self.translator_levels @translator_levels ||= begin levels = HashWithIndifferentAccess.new translator_roles.each do |key, val| levels[val] = key end levels end end |
.translator_roles ⇒ Object
Translator Roles and Levels
718 719 720 |
# File 'lib/tr8n/config.rb', line 718 def self.translator_roles config[:translator_roles] end |
.universal_language_rules ⇒ Object
562 563 564 565 566 567 568 569 570 571 |
# File 'lib/tr8n/config.rb', line 562 def self.universal_language_rules @universal_language_rules ||= begin urs = [] language_rule_classes.each do |cls| next unless cls.suffixes.is_a?(String) urs << cls if cls.suffixes == "*" end urs end end |
.user_class ⇒ Object
458 459 460 |
# File 'lib/tr8n/config.rb', line 458 def self.user_class user_class_name.constantize end |
.user_class_name ⇒ Object
453 454 455 456 |
# File 'lib/tr8n/config.rb', line 453 def self.user_class_name return site_user_info[:class_name] if site_user_info_enabled? "Tr8n::Translator" end |
.user_gender(user) ⇒ Object
478 479 480 481 482 483 484 |
# File 'lib/tr8n/config.rb', line 478 def self.user_gender(user) return "unknown" unless user user.send(site_user_info[:methods][:gender]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} name: #{ex.to_s}") "unknown" end |
.user_id(user) ⇒ Object
462 463 464 465 466 467 468 |
# File 'lib/tr8n/config.rb', line 462 def self.user_id(user) return 0 unless user user.send(site_user_info[:methods][:id]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch user id: #{ex.to_s}") 0 end |
.user_link(user) ⇒ Object
494 495 496 497 498 499 500 |
# File 'lib/tr8n/config.rb', line 494 def self.user_link(user) return "/tr8n" unless user user.send(site_user_info[:methods][:link]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} link: #{ex.to_s}") "/tr8n" end |
.user_locale(user) ⇒ Object
502 503 504 505 506 507 508 |
# File 'lib/tr8n/config.rb', line 502 def self.user_locale(user) return default_locale unless user user.send(site_user_info[:methods][:locale]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} locale: #{ex.to_s}") default_locale end |
.user_mugshot(user) ⇒ Object
486 487 488 489 490 491 492 |
# File 'lib/tr8n/config.rb', line 486 def self.user_mugshot(user) return silhouette_image unless user user.send(site_user_info[:methods][:mugshot]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} image: #{ex.to_s}") silhouette_image end |
.user_name(user) ⇒ Object
470 471 472 473 474 475 476 |
# File 'lib/tr8n/config.rb', line 470 def self.user_name(user) return "Unknown user" unless user user.send(site_user_info[:methods][:name]) rescue Exception => ex Tr8n::Logger.error("Failed to fetch #{user_class_name} name: #{ex.to_s}") "Invalid user" end |
.viewing_user_token_for(label) ⇒ Object
607 608 609 |
# File 'lib/tr8n/config.rb', line 607 def self.viewing_user_token_for(label) Tr8n::Tokens::DataToken.new(label, "{#{rules_engine[:viewing_user_token]}:gender}") end |