Project

stamp-i18n

0.01
No commit activity in last 3 years
No release in over 3 years
Little plugin for 'stamp' gem. It uses I18n locale files to customize date and time stamps.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
= 0.4.0
 Project Readme

StampI18n

Build Status

Little plugin for 'stamp' gem. It uses I18n locale files to customize date and time stamps.

This only works with versions of stamp up to 0.4. Check out stamp-l10n for more recent versions of stamp.

Installation

Add this lines to your application's Gemfile:

gem 'stamp', '0.4.0' # does not work with newer versions
gem 'stamp-i18n'

And then execute:

$ bundle

Before using

This gem uses i18n translation mechnism, which means before using it, first we need to add proper translation files to locales folder and then setup i18n configuration. Example YML files used for testing is written in few various languages and are located in ./locale folder. Look for more examples here: https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale

Usage

Same as in http://rubydoc.info/gems/stamp but instead of using method 'stamp' like this:

date = Date.new(2011, 6, 9)
date.stamp("March 1, 1999")         #=> "June  9, 2011"

we are using new method 'localize_stamp' like this:

date = Date.new(2011, 6, 9)
date.localize_stamp("March 1, 1999")         #=> "junio  9, 2011" if default locale is :de
date.localize_stamp("March 1, 1999")         #=> "czerwiec  9, 2011" if default locale is :pl

Note that we are still using english names in examples passed to stamp methods.

You can also optionally pass options (as hash) to new method that will eventually be passed to underling 'I18n.translate' (therefore lookup this methods options for complete reference). For example if you want to use other locale than your default you can use:

date = Date.new(2011, 6, 9)
date.localize_stamp("March 1, 1999", :locale => 'en')       #=> "June  9, 2011"
date.localize_stamp("March 1, 1999", :locale => 'de')       #=> "Juni  9, 2011"
date.localize_stamp("March 1, 1999", :locale => 'pl')       #=> "Czerwiec 9, 2011"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request