Sha256: 6d97603886b7e9e1cde41e84deac49013eebe575dfd37c83ec0c524dc0262c6e
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'rubygems' require 'yaml' module Jekyll module LanguagePlugin module Loaders class RailsI18nLoader < BaseLoader @@data = nil def load if !@is_loaded self.class.load_data if @@data.nil? @is_loaded = true end end def get(key, language) return nil unless loaded? traverse_hash(@@data, [language, key]) end def self.load_data gem_root = Gem.loaded_specs['rails-i18n'].full_gem_path files = Dir[File.join(gem_root, 'rails', '**', '*.yml')] @@data = files.inject(Hash.new) do |data, file| key = File.basename(file, '.yml') source = YAML.load_file(file) break data if !source.has_key?(key) || source[key]['date'].nil? # extract date object date = source[key]['date'] date.delete_if { |k, _| k !~ /\A(?:abbr_day_names|abbr_month_names|day_names|month_names)\z/ } date = Hash[date.map { |k, v| [k.sub(/_names\Z/, 'names'), v] }] date['abbr_monthnames'].shift date['monthnames'].shift data.merge!({ key => { 'date' => date } }) end end end end end end begin require 'rails-i18n' Jekyll::LanguagePlugin.register_loader(Jekyll::LanguagePlugin::Loaders::RailsI18nLoader) rescue LoadError end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll-language-plugin-1.2.0 | lib/jekyll/language-plugin/loaders/rails_i18n_loader.rb |