Module: HammerCLI::I18n
- Defined in:
- lib/hammer_cli/i18n.rb,
lib/hammer_cli/i18n/find_task.rb
Defined Under Namespace
Modules: Debug
Classes: AbstractLocaleDomain, FindTask, LocaleDomain, SystemLocaleDomain
Constant Summary
collapse
- TEXT_DOMAIN =
'hammer-cli'
Class Method Summary
collapse
Class Method Details
.add_domain(domain) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/hammer_cli/i18n.rb', line 97
def self.add_domain(domain)
if domain.available?
domains << domain
if base_repo_type == :merge
translation_repository.add_repo(build_repository(domain))
else
translation_repository.chain << build_repository(domain)
end
end
end
|
.base_repo_type ⇒ Object
116
117
118
|
# File 'lib/hammer_cli/i18n.rb', line 116
def self.base_repo_type
(fast_gettext_version >= '1.2.0') ? :merge : :chain
end
|
.build_repository(domain) ⇒ Object
108
109
110
|
# File 'lib/hammer_cli/i18n.rb', line 108
def self.build_repository(domain)
FastGettext::TranslationRepository.build(domain.domain_name, :path => domain.locale_dir, :type => domain.type, :report_warning => false)
end
|
.domains ⇒ Object
93
94
95
|
# File 'lib/hammer_cli/i18n.rb', line 93
def self.domains
@domains ||= []
end
|
.fast_gettext_version ⇒ Object
120
121
122
|
# File 'lib/hammer_cli/i18n.rb', line 120
def self.fast_gettext_version
FastGettext::VERSION
end
|
.find_by_name(name) ⇒ Object
140
141
142
|
# File 'lib/hammer_cli/i18n.rb', line 140
def self.find_by_name(name)
domains.find { |domain| domain.class.to_s.split('::').first.underscore == name }
end
|
.init(default_domains = []) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/hammer_cli/i18n.rb', line 124
def self.init(default_domains = [])
Encoding.default_external='UTF-8' if defined? Encoding
FastGettext.locale = locale
FastGettext.text_domain = HammerCLI::I18n::TEXT_DOMAIN
FastGettext.translation_repositories[HammerCLI::I18n::TEXT_DOMAIN] = FastGettext::TranslationRepository.build(HammerCLI::I18n::TEXT_DOMAIN, :type => base_repo_type, :chain => [])
@domains = []
default_domains.each do |domain|
add_domain(domain)
end
end
|
.locale ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/hammer_cli/i18n.rb', line 81
def self.locale
lang_variant = Locale.current.to_simple.to_str
lang = lang_variant.gsub(/_.*/, "")
hammer_domain = HammerCLI::I18n::LocaleDomain.new
if hammer_domain.available_locales.include? lang_variant
lang_variant
else
lang
end
end
|
.main_makefile ⇒ Object
136
137
138
|
# File 'lib/hammer_cli/i18n.rb', line 136
def self.main_makefile
File.expand_path(File.join(File.dirname(__FILE__), '../../locale/Makefile.def'))
end
|
.translation_repository ⇒ Object
112
113
114
|
# File 'lib/hammer_cli/i18n.rb', line 112
def self.translation_repository
FastGettext.translation_repositories[HammerCLI::I18n::TEXT_DOMAIN]
end
|