Class: Tr8n::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tr8n/config.rb

Class Method Summary collapse

Class Method Details

.admin_helpersObject



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_levelObject



736
737
738
# File 'lib/tr8n/config.rb', line 736

def self.admin_level
  10000
end

.admin_user?(user = Tr8n::Config.current_user) ⇒ Boolean

Returns:

  • (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([:methods][:admin])
rescue Exception => ex
  Tr8n::Logger.error("Failed to fetch #{user_class_name} admin flag: #{ex.to_s}")
  false
end

.after_filtersObject



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

Returns:

  • (Boolean)


595
596
597
# File 'lib/tr8n/config.rb', line 595

def self.allow_nil_token_values?
  rules_engine[:allow_nil_token_values]
end

.apiObject



323
324
325
# File 'lib/tr8n/config.rb', line 323

def self.api
  config[:api]
end

.api_after_filtersObject



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_filtersObject



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_filtersObject



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_levelObject



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_filtersObject



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_optionsObject



58
59
60
# File 'lib/tr8n/config.rb', line 58

def self.block_options
  Thread.current[:tr8n_block_options] ||= {}
end

.cache_adapterObject



337
338
339
# File 'lib/tr8n/config.rb', line 337

def self.cache_adapter
  caching[:adapter]
end

.cache_storeObject



341
342
343
# File 'lib/tr8n/config.rb', line 341

def self.cache_store
  caching[:store]
end

.cache_versionObject



345
346
347
# File 'lib/tr8n/config.rb', line 345

def self.cache_version
  caching[:version]
end

.cachingObject

Config Sections



303
304
305
# File 'lib/tr8n/config.rb', line 303

def self.caching
  config[:caching]
end

.configObject



169
170
171
# File 'lib/tr8n/config.rb', line 169

def self.config
  @config ||= load_yml("/config/tr8n/config.yml")
end

.current_languageObject



50
51
52
# File 'lib/tr8n/config.rb', line 50

def self.current_language
  Thread.current[:tr8n_current_language] ||= default_language
end

.current_locale_methodObject



388
389
390
# File 'lib/tr8n/config.rb', line 388

def self.current_locale_method
  site_info[:current_locale_method]
end

.current_sourceObject



46
47
48
# File 'lib/tr8n/config.rb', line 46

def self.current_source
  Thread.current[:tr8n_current_source]
end

.current_translatorObject

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_userObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_methodObject



441
442
443
# File 'lib/tr8n/config.rb', line 441

def self.current_user_method
  [:current_user_method]
end

.data_token_classesObject



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_classesObject



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_namesObject



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_namesObject



707
708
709
# File 'lib/tr8n/config.rb', line 707

def self.default_abbr_month_names
  localization[:default_abbr_month_names]
end

.default_client_intervalObject



767
768
769
# File 'lib/tr8n/config.rb', line 767

def self.default_client_interval
  5000
end

.default_data_tokensObject



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_formatsObject



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_namesObject



695
696
697
# File 'lib/tr8n/config.rb', line 695

def self.default_day_names
  localization[:default_day_names]
end

.default_decoration_tokensObject



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_glossaryObject



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_languageObject



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_languagesObject



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_localeObject



375
376
377
378
# File 'lib/tr8n/config.rb', line 375

def self.default_locale
  return block_options[:default_locale] if block_options[:default_locale]
  site_info[:default_locale]
end

.default_month_namesObject



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_stylesObject



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_shortcutsObject



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_levelObject



748
749
750
# File 'lib/tr8n/config.rb', line 748

def self.default_translation_key_level
  config[:default_translation_key_level] || 0
end

.default_urlObject



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

Returns:

  • (Boolean)


205
206
207
# File 'lib/tr8n/config.rb', line 205

def self.disabled?
  not enabled?
end

.dump_configObject



165
166
167
# File 'lib/tr8n/config.rb', line 165

def self.dump_config
  save_to_yaml("config.yaml", config)
end

.effects_library_pathObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


755
756
757
# File 'lib/tr8n/config.rb', line 755

def self.enable_api?
  api[:enabled]
end

.enable_browser_cache?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


333
334
335
# File 'lib/tr8n/config.rb', line 333

def self.enable_caching?
  caching[:enabled]
end

.enable_client_sdk?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


253
254
255
# File 'lib/tr8n/config.rb', line 253

def self.enable_dictionary_lookup?
  config[:enable_dictionary_lookup]
end

.enable_effects?Boolean

Returns:

  • (Boolean)


404
405
406
# File 'lib/tr8n/config.rb', line 404

def self.enable_effects?
  site_info[:enable_effects]
end

.enable_fallback_languages?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


352
353
354
# File 'lib/tr8n/config.rb', line 352

def self.enable_logger?
  logger[:enabled]
end

.enable_paranoia_mode?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


209
210
211
# File 'lib/tr8n/config.rb', line 209

def self.enable_software_keyboard?
  config[:enable_software_keyboard]
end

.enable_tr8n_methodObject



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

Returns:

  • (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

Returns:

  • (Boolean)


297
298
299
# File 'lib/tr8n/config.rb', line 297

def self.enable_translator_tabs?
  config[:enable_translator_tabs]
end

.enabled?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/tr8n/config.rb', line 201

def self.enabled?
  config[:enable_tr8n] 
end

.envObject



147
148
149
# File 'lib/tr8n/config.rb', line 147

def self.env
  Rails.env
end

.featuresObject



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_keyObject



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

Returns:

  • (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([: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_languagesObject



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_glossaryObject



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_classesObject

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_dependenciesObject



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_suffixesObject



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

.localizationObject



319
320
321
# File 'lib/tr8n/config.rb', line 319

def self.localization
  config[:localization]
end

.log_pathObject



356
357
358
# File 'lib/tr8n/config.rb', line 356

def self.log_path
  logger[:log_path]
end

.loggerObject



307
308
309
# File 'lib/tr8n/config.rb', line 307

def self.logger
  config[:logger]
end

.manager_levelObject



732
733
734
# File 'lib/tr8n/config.rb', line 732

def self.manager_level
  1000
end

.modelsObject



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

Returns:

  • (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

Returns:

  • (Boolean)


265
266
267
# File 'lib/tr8n/config.rb', line 265

def self.open_registration_mode?
  config[:open_registration_mode]
end

.registration_disclaimer_pathObject



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

.rootObject



143
144
145
# File 'lib/tr8n/config.rb', line 143

def self.root
  Rails.root
end

.rules_engineObject



315
316
317
# File 'lib/tr8n/config.rb', line 315

def self.rules_engine
  config[:rules_engine]
end

.silhouette_imageObject



534
535
536
# File 'lib/tr8n/config.rb', line 534

def self.silhouette_image
  "/assets/tr8n/photo_silhouette.gif"
end

.site_infoObject



311
312
313
# File 'lib/tr8n/config.rb', line 311

def self.site_info
  config[:site_info]
end

.site_titleObject

Site Info



367
368
369
# File 'lib/tr8n/config.rb', line 367

def self.site_title
  site_info[:title] 
end

.site_user_infoObject

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_info[:user_info]
end

.site_user_info_disabled?Boolean

Returns:

  • (Boolean)


449
450
451
# File 'lib/tr8n/config.rb', line 449

def self.
  !
end

.site_user_info_enabled?Boolean

Returns:

  • (Boolean)


445
446
447
# File 'lib/tr8n/config.rb', line 445

def self.
  [:enabled].nil? ? true : [:enabled]
end

.sitemap_sectionsObject



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_filtersObject



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_screenObject



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

.synchronizationObject



327
328
329
# File 'lib/tr8n/config.rb', line 327

def self.synchronization
  config[:synchronization]
end

.synchronization_all_languages?Boolean

Returns:

  • (Boolean)


806
807
808
# File 'lib/tr8n/config.rb', line 806

def self.synchronization_all_languages?
  synchronization[:all_languages]
end

.synchronization_batch_sizeObject

Sync Process



790
791
792
# File 'lib/tr8n/config.rb', line 790

def self.synchronization_batch_size
  synchronization[:batch_size]
end

.synchronization_keyObject



798
799
800
# File 'lib/tr8n/config.rb', line 798

def self.synchronization_key
  synchronization[:key]
end

.synchronization_push_enabled?Boolean

Returns:

  • (Boolean)


810
811
812
# File 'lib/tr8n/config.rb', line 810

def self.synchronization_push_enabled?
  synchronization[:enable_push]
end

.synchronization_push_serversObject



814
815
816
# File 'lib/tr8n/config.rb', line 814

def self.synchronization_push_servers
  synchronization[:push_servers]
end

.synchronization_secretObject



802
803
804
# File 'lib/tr8n/config.rb', line 802

def self.synchronization_secret
  synchronization[:secret]
end

.synchronization_serverObject



794
795
796
# File 'lib/tr8n/config.rb', line 794

def self.synchronization_server
  synchronization[:server]
end

.system_imageObject



538
539
540
# File 'lib/tr8n/config.rb', line 538

def self.system_image
  "/assets/tr8n/photo_system.gif"
end

.system_levelObject



744
745
746
# File 'lib/tr8n/config.rb', line 744

def self.system_level
  1000000
end

.system_translatorObject

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_helpersObject



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_thresholdObject



611
612
613
# File 'lib/tr8n/config.rb', line 611

def self.translation_threshold
  rules_engine[:translation_threshold]
end

.translator_levelsObject



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_rolesObject

Translator Roles and Levels



718
719
720
# File 'lib/tr8n/config.rb', line 718

def self.translator_roles
  config[:translator_roles]
end

.universal_language_rulesObject



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_classObject



458
459
460
# File 'lib/tr8n/config.rb', line 458

def self.user_class
  user_class_name.constantize
end

.user_class_nameObject



453
454
455
456
# File 'lib/tr8n/config.rb', line 453

def self.user_class_name
  return [:class_name] if 
  "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([: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([:methods][:id])
rescue Exception => ex
  Tr8n::Logger.error("Failed to fetch user id: #{ex.to_s}")
  0
end


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([: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([: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([: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([: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