Module: Tml
- Defined in:
- lib/tml.rb,
lib/tml/cache.rb,
lib/tml/utils.rb,
lib/tml/config.rb,
lib/tml/logger.rb,
lib/tml/session.rb,
lib/tml/version.rb,
lib/tml/tokens/data.rb,
lib/tml/cache_version.rb,
lib/tml/tokenizers/dom.rb,
lib/tml/tokenizers/data.rb,
lib/tml/tokens/decoration.rb,
lib/tml/rules_engine/parser.rb,
lib/tml/tokenizers/x_message.rb,
lib/tml/tokenizers/decoration.rb,
lib/tml/rules_engine/evaluator.rb
Overview
– Copyright © 2017 Translation Exchange, Inc
_______ _ _ _ ______ _
|__ __| | | | | (_) | __| | |
| |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
| | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
| | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
__/ |
|___/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Defined Under Namespace
Modules: Api, CacheAdapters, Decorators, Generators, Rules, RulesEngine, Tokenizers, Tokens Classes: Application, Base, Cache, CacheVersion, Config, Exception, Language, LanguageCase, LanguageCaseRule, LanguageContext, LanguageContextRule, Logger, Session, Source, Translation, TranslationKey, Translator, Utils
Constant Summary collapse
- VERSION =
'5.7.9'
- CACHE_VERSION_KEY =
'current_version'
Class Attribute Summary collapse
-
.config ⇒ Object
Initializes default config.
Class Method Summary collapse
- .cache ⇒ Object
-
.configure {|self.config| ... } ⇒ Object
Allows you to configure Tml.
- .current_language ⇒ Object
- .default_language ⇒ Object
- .full_version ⇒ Object
- .language(locale) ⇒ Object
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
- .session ⇒ Object
- .translate(label, description = '', tokens = {}, options = {}) ⇒ Object
-
.with_config_settings {|@config| ... } ⇒ Object
Allows you to create a block to perform something on adjusted config settings Once the block exists, the config will be reset back to what it was before:.
- .with_options(opts) ⇒ Object
Class Attribute Details
.config ⇒ Object
Initializes default config
41 42 43 |
# File 'lib/tml/config.rb', line 41 def config @config end |
Class Method Details
.cache ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tml/cache.rb', line 41 def self.cache @cache ||= begin if Tml.config.cache_enabled? # .capitalize is not ideal, but .camelcase is not available in pure ruby. # This works for the current class names. klass = Tml::CacheAdapters.const_get(Tml.config.cache[:adapter].to_s.capitalize) klass.new else # blank implementation Tml::Cache.new end end end |
.configure {|self.config| ... } ⇒ Object
Allows you to configure Tml
Tml.configure do |config|
config.application = {:key => "", :secret => ""}
end
53 54 55 |
# File 'lib/tml/config.rb', line 53 def self.configure yield(self.config) end |
.current_language ⇒ Object
48 49 50 |
# File 'lib/tml.rb', line 48 def self.current_language Tml.session.current_language end |
.default_language ⇒ Object
44 45 46 |
# File 'lib/tml.rb', line 44 def self.default_language Tml.config.default_language end |
.full_version ⇒ Object
36 37 38 |
# File 'lib/tml/version.rb', line 36 def self.full_version "tml-ruby v#{Tml::VERSION} (Faraday v#{Faraday::VERSION})" end |
.language(locale) ⇒ Object
52 53 54 |
# File 'lib/tml.rb', line 52 def self.language(locale) Tml.session.application.language(locale) end |
.logger ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tml/logger.rb', line 37 def self.logger @logger ||= begin logfile_path = File.(Tml.config.logger[:path] || './log/tml.log') logfile_dir = logfile_path.split("/")[0..-2].join("/") FileUtils.mkdir_p(logfile_dir) unless File.exist?(logfile_dir) logfile = File.open(logfile_path, 'a') logfile.sync = true logger = Tml::Logger.new(logfile) if Tml.config.logger[:type].to_s == 'rails' logger.external_logger = Rails.logger end logger end end |
.logger=(logger) ⇒ Object
54 55 56 |
# File 'lib/tml/logger.rb', line 54 def self.logger=(logger) @logger = logger end |
.session ⇒ Object
35 36 37 |
# File 'lib/tml/session.rb', line 35 def self.session Thread.current[:tml_context] ||= Tml::Session.new end |
.translate(label, description = '', tokens = {}, options = {}) ⇒ Object
56 57 58 |
# File 'lib/tml.rb', line 56 def self.translate(label, description = '', tokens = {}, = {}) Tml.session.translate(label, description, tokens, ) end |
.with_config_settings {|@config| ... } ⇒ Object
Allows you to create a block to perform something on adjusted config settings Once the block exists, the config will be reset back to what it was before:
Tml.with_config_settings do |config|
config.format = :text
Do something....
end
68 69 70 71 72 |
# File 'lib/tml/config.rb', line 68 def self.with_config_settings old_config = @config.dup yield(@config) @config = old_config end |