Class: SgtnClient::TranslationLoader::LocalTranslation
- Inherits:
-
Object
- Object
- SgtnClient::TranslationLoader::LocalTranslation
- Defined in:
- lib/sgtn-client/loader/local_translation.rb
Constant Summary collapse
- BUNDLE_PREFIX =
'messages_'.freeze
- BUNDLE_SUFFIX =
'.json'.freeze
Instance Method Summary collapse
- #available_bundles ⇒ Object
-
#initialize(config) ⇒ LocalTranslation
constructor
A new instance of LocalTranslation.
- #load_bundle(component, locale) ⇒ Object
Constructor Details
#initialize(config) ⇒ LocalTranslation
Returns a new instance of LocalTranslation.
14 15 16 |
# File 'lib/sgtn-client/loader/local_translation.rb', line 14 def initialize(config) @base_path = Pathname.new(config.translation_bundle) + config.product_name + config.version.to_s end |
Instance Method Details
#available_bundles ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/sgtn-client/loader/local_translation.rb', line 33 def available_bundles SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}]" } @available_bundles = @base_path.glob('*/*.json').reduce(Set.new) do |bundles, f| locale = f.basename.to_s.sub(/\A#{BUNDLE_PREFIX}/i, '').sub(/#{BUNDLE_SUFFIX}\z/i, '') bundles.add Common::BundleID.new(f.parent.basename.to_s, locale) end end |
#load_bundle(component, locale) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sgtn-client/loader/local_translation.rb', line 18 def load_bundle(component, locale) SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] component=#{component}, locale=#{locale}" } file_name = BUNDLE_PREFIX + locale + BUNDLE_SUFFIX file_path = @base_path + component + file_name bundle_data = JSON.parse(File.read(file_path)) = bundle_data['messages'] raise SingletonError, "no messages in local bundle file: #{file_path}." unless Common::BundleData.new(, origin: self, component: component, locale: locale == CONSTS::REAL_SOURCE_LOCALE ? LocaleUtil.get_source_locale : locale) end |