Giter Club home page Giter Club logo

i18n-debug's Introduction

Ruby I18n Debug

Build Status Gem Version

Ever wondered which translations are being looked up by Rails, a gem, or simply your app? Wonder no more!

Rails' implicit translations, for instance, are a nice feature. But sometimes getting the key to, let's say, the BillingAddress' street attribute in a nested form inside an Order can be quite tricky to get right on the first try. The key for this example would be activerecord.attributes.order/billing_address.street. Good luck figuring that out!

With this gem you can easily see which translations are being looked up. The key above would have created the following debug log entry:

[i18n-debug] activerecord.attributes.order/billing_address.name => nil

After setting the translation for that key you just discovered, the log entry changes to this:

[i18n-debug] activerecord.attributes.order/billing_address.name => "Order billing name"

Installation

Simply add the gem to your Gemfile. You probably only want this in development. Thus, place it inside the development group.

gem 'i18n-debug', group: :development

If you need support for ruby <= 2.0, make sure to use version 1.0.0.

Usage

This gem works straight out of the box. If Rails is available, it will log using Rails.logger.debug. Otherwise it will log using Logger.new($stdout).debug.

If you wish to use a custom logger, simply set it as follows (make sure it responds to debug):

I18n::Debug.logger = my_custom_logger

Every lookup invokes the lambda I18n::Debug.on_lookup with the key and the translation value as arguments. The default lambda simply logs it to the logger mentioned above. If you want to change the logging format or do something totally different, simply set your own handler to do so:

# Collect stats on I18n key usage.
i18n_stats = Hash.new { |stats, key| stats[key] = 0 }

I18n::Debug.on_lookup do |key, value|
  i18n_stats[key] += 1 if value
end

Additional Information

Dependencies

Author

Philipe Fatio (fphilipe)

License

MIT License. Copyright 2014 Philipe Fatio

i18n-debug's People

Contributors

aleksandrs-ledovskis avatar fphilipe avatar lostapathy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.