Sha256: 039819e9564136d6f350de6f006cd3ea9890abbfe9419ee109655be4894e4cdf

Contents?: true

Size: 1.98 KB

Versions: 13

Compression:

Stored size: 1.98 KB

Contents

module I18n::Tasks
  class ConsoleContext < BaseTask
    def to_s
      @to_s ||= "i18n-tasks-#{I18n::Tasks::VERSION}"
    end

    def banner
      puts Messages.banner
    end

    def guide
      puts Messages.guide
    end

    class << self
      def start
        require 'irb'
        IRB.setup nil
        ctx = IRB::Irb.new.context
        IRB.conf[:MAIN_CONTEXT] = ctx
        $stderr.puts Messages.banner
        require 'irb/ext/multi-irb'
        IRB.irb nil, new
      end
    end

    module Messages
      include Term::ANSIColor
      extend self

      def banner
        bold("i18n-tasks v#{I18n::Tasks::VERSION} IRB") + "\nType #{green 'guide'} to learn more"
      end

      def guide
        green(bold "i18n-tasks IRB Quick Start guide") + "\n" + <<-TEXT
#{yellow 'Data as trees'}
  tree(locale)
  missing_tree(locale, compared_to = base_locale)
  used_tree(source_occurrences: false, key_filter: nil)
  unused_tree(locale)
  build_tree('es' => {'hello' => 'Hola'})

#{yellow 'Traversal'}
  tree = missing_tree(base_locale)
  tree.nodes { |node| }
  tree.nodes.to_a
  tree.leaves { |node| }
  tree.each { |root_node| }
  # also levels, depth_first, and breadth_first

#{yellow 'Select nodes'}
  tree.select_nodes { |node| } # new tree with only selected nodes

#{yellow 'Match by full key'}
  tree.select_keys { |key, leaf| } # new tree with only selected keys
  tree.grep_keys(/hello/)          # grep, using ===
  tree.keys { |key, leaf| }        # enumerate over [full_key, leaf_node]
  # Pass {root: true} to include root node in full_key (usually locale)

#{yellow 'Nodes'}
  node = node(key, locale)
  node.key      # only the part after the last dot
  node.full_key # full key. Includes root key, pass {root: false} to override.
  # also: value, value_or_children_hash, data, walk_to_root, walk_from_root
  Tree::Node.new(key: 'en')

#{yellow 'Keys'}
  t(key, locale)
  key_value?(key, locale)
  depluralize_key(key, locale) # convert 'hat.one' to 'hat'
        TEXT
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
i18n-tasks-0.8.5 lib/i18n/tasks/console_context.rb
i18n-tasks-0.8.4 lib/i18n/tasks/console_context.rb
i18n-tasks-0.8.3 lib/i18n/tasks/console_context.rb
i18n-tasks-0.8.2 lib/i18n/tasks/console_context.rb
i18n-tasks-0.8.1 lib/i18n/tasks/console_context.rb
i18n-tasks-0.8.0 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.13 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.12 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.11 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.10 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.9 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.8 lib/i18n/tasks/console_context.rb
i18n-tasks-0.7.7 lib/i18n/tasks/console_context.rb