Sha256: 466e6fc697497b2fbc0f0e7c7c3258105eae69b65395bdd1d92db36d3bca62fb
Contents?: true
Size: 1.28 KB
Versions: 3
Compression:
Stored size: 1.28 KB
Contents
require 'yaml' require 'psych' require 'missing_translation/translation_file' module MissingTranslation class TranslationFile attr_accessor :pathname, :content, :group, :language, :translations, :locale_prefix def initialize(pathname = nil) return unless pathname @pathname = pathname @file = File.open(pathname) if @file @content = (YAML.load(@file.read) || {}) end end def to_json return nil unless @content hash_content = @content.to_hash return hash_content[language] if hash_content.has_key?(language) hash_content end def group return @group if @group groups = pathname.split('/').last.gsub('.yml', '').split('.') return '' unless groups.size > 1 @group = groups.first end def language return @language if @language @language = pathname.split('/').last.gsub('.yml', '').split('.').last end def write(directory) return nil unless translations filename = [group, language, "yml"].compact.reject{|s| s.size <= 0}.join('.') filepath = "#{directory}/#{filename}" p "Writing file #{filepath}..." File.write(filepath, translations.to_yaml) MissingTranslation::Util.sort_file(filepath) end end end
Version data entries
3 entries across 3 versions & 1 rubygems