Skip to content
Browse files

Updated README formatting

* Added GitHub Flavoured Markdown for syntax highlighting
  • Loading branch information...
1 parent 0277c1f commit 81d642df464956a2fe8ab113c54af78ac5481bb3 @parndt committed
Showing with 147 additions and 126 deletions.
  1. +147 −126 README.markdown
View
273 README.markdown
@@ -14,7 +14,9 @@ You can use delocalize as a gem (preferred). Using delocalize as a Rails plugin
To use delocalize, put the following gem requirement in your `Gemfile`:
- gem "delocalize"
+```ruby
+gem "delocalize"
+```
### Rails 2
@@ -22,7 +24,9 @@ Note: Support for Rails 2 has been discontinued. This version is only considered
To use delocalize, put the following gem requirement in your `environment.rb`:
- config.gem "delocalize", :source => 'http://gemcutter.org'
+```ruby
+config.gem "delocalize", :source => 'http://gemcutter.org'
+```
In Rails 2.3, alternatively, you can use it with Bundler. See http://gembundler.com/rails23.html for instructions.
@@ -33,44 +37,48 @@ Delocalize, just as the name suggest, does pretty much the opposite of localize.
In the grey past, if you want your users to be able to input localized data, such as dates and numbers, you had to manually override attribute accessors:
- def price=(price)
- write_attribute(:price, price.gsub(',', '.'))
- end
+```ruby
+def price=(price)
+ write_attribute(:price, price.gsub(',', '.'))
+end
+```
delocalize does this under the covers -- all you need is your regular translation data (as YAML or Ruby file) where you need Rails' standard translations:
- de:
- number:
- format:
- separator: ','
- delimiter: '.'
- date:
- input:
- formats: [:default, :long, :short] # <- this and ...
-
- formats:
- default: "%d.%m.%Y"
- short: "%e. %b"
- long: "%e. %B %Y"
- only_day: "%e"
-
- day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
- abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa]
- month_names: [~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember]
- abbr_month_names: [~, Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]
- order: [ :day, :month, :year ]
-
- time:
- input:
- formats: [:long, :medium, :short, :default, :time] # <- ... this are the only non-standard keys
- formats:
- default: "%A, %e. %B %Y, %H:%M Uhr"
- short: "%e. %B, %H:%M Uhr"
- long: "%A, %e. %B %Y, %H:%M Uhr"
- time: "%H:%M"
-
- am: "vormittags"
- pm: "nachmittags"
+```yml
+de:
+ number:
+ format:
+ separator: ','
+ delimiter: '.'
+ date:
+ input:
+ formats: [:default, :long, :short] # <- this and ...
+
+ formats:
+ default: "%d.%m.%Y"
+ short: "%e. %b"
+ long: "%e. %B %Y"
+ only_day: "%e"
+
+ day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
+ abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa]
+ month_names: [~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember]
+ abbr_month_names: [~, Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]
+ order: [ :day, :month, :year ]
+
+ time:
+ input:
+ formats: [:long, :medium, :short, :default, :time] # <- ... this are the only non-standard keys
+ formats:
+ default: "%A, %e. %B %Y, %H:%M Uhr"
+ short: "%e. %B, %H:%M Uhr"
+ long: "%A, %e. %B %Y, %H:%M Uhr"
+ time: "%H:%M"
+
+ am: "vormittags"
+ pm: "nachmittags"
+```
For dates and times, you have to define input formats which are taken from the actual formats. The important thing here is to define input formats sorted by descending complexity; in other words: the format which contains the most (preferably non-numeric) information should be first in the list because it can produce the most reliable match. Exception: If you think there most complex format is not the one that most users will input, you can put the most-used in front so you save unnecessary iterations.
@@ -78,12 +86,14 @@ Careful with formats containing only numbers: It's very hard to produce reliable
delocalize then overrides `to_input_field_tag` in ActionView's `InstanceTag` so you can use localized text fields:
- <% form_for @product do |f| %>
- <%= f.text_field :name %>
- <%= f.text_field :released_on %>
- <%= f.text_field :price %>
- <% end %>
-
+```erb
+<% form_for @product do |f| %>
+ <%= f.text_field :name %>
+ <%= f.text_field :released_on %>
+ <%= f.text_field :price %>
+<% end %>
+```
+
In this example, a user can enter the release date and the price just like he's used to in his language, for example:
> Name: "Couch"
@@ -97,13 +107,22 @@ Edit forms then also show localized dates/numbers. By default, dates and times a
You can also customize the output using some options:
The price should always show two decimal digits and we don't need the delimiter:
- <%= f.text_field :price, :precision => 2, :delimiter => '' %>
- The `released_on` date should be shown in the `:full` format:
- <%= f.text_field :released_on, :format => :full %>
+```erb
+<%= f.text_field :price, :precision => 2, :delimiter => '' %>
+```
+ The `released_on` date should be shown in the `:full` format:
+
+```erb
+<%= f.text_field :released_on, :format => :full %>
+```
+
Since `I18n.localize` supports localizing `strftime` strings, we can also do this:
- <%= f.text_field :released_on, :format => "%B %Y" %>
+
+```erb
+<%= f.text_field :released_on, :format => "%B %Y" %>
+```
### Ruby 1.9 + Psych YAML Parser
@@ -121,85 +140,87 @@ http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-
__Psych Preferred Formatting:__
- en:
- number:
- format:
- separator: '.'
- delimiter: ','
- precision: 2
- date:
- input:
- formats:
- - :default
- - :long
- - :short
- formats:
- default: "%m/%d/%Y"
- short: "%b %e"
- long: "%B %e, %Y"
- only_day: "%e"
- day_names:
- - Sunday
- - Monday
- - Tuesday
- - Wednesday
- - Thursday
- - Friday
- - Saturday
- abbr_day_names:
- - Sun
- - Mon
- - Tue
- - Wed
- - Thur
- - Fri
- - Sat
- month_names:
- - ~
- - January
- - February
- - March
- - April
- - May
- - June
- - July
- - August
- - September
- - October
- - November
- - December
- abbr_month_names:
- - ~
- - Jan
- - Feb
- - Mar
- - Apr
- - May
- - Jun
- - Jul
- - Aug
- - Sep
- - Oct
- - Nov
- - Dec
- order:
- - :month
- - :day
- - :year
- time:
- input:
- formats:
- - :default
- - :long
- - :short
- - :time
- formats:
- default: "%m/%d/%Y %I:%M%p"
- short: "%B %e %I:%M %p"
- long: "%A, %B %e, %Y %I:%M%p"
- time: "%l:%M%p"
- am: "am"
- pm: "pm"
+```yml
+en:
+ number:
+ format:
+ separator: '.'
+ delimiter: ','
+ precision: 2
+ date:
+ input:
+ formats:
+ - :default
+ - :long
+ - :short
+ formats:
+ default: "%m/%d/%Y"
+ short: "%b %e"
+ long: "%B %e, %Y"
+ only_day: "%e"
+ day_names:
+ - Sunday
+ - Monday
+ - Tuesday
+ - Wednesday
+ - Thursday
+ - Friday
+ - Saturday
+ abbr_day_names:
+ - Sun
+ - Mon
+ - Tue
+ - Wed
+ - Thur
+ - Fri
+ - Sat
+ month_names:
+ - ~
+ - January
+ - February
+ - March
+ - April
+ - May
+ - June
+ - July
+ - August
+ - September
+ - October
+ - November
+ - December
+ abbr_month_names:
+ - ~
+ - Jan
+ - Feb
+ - Mar
+ - Apr
+ - May
+ - Jun
+ - Jul
+ - Aug
+ - Sep
+ - Oct
+ - Nov
+ - Dec
+ order:
+ - :month
+ - :day
+ - :year
+ time:
+ input:
+ formats:
+ - :default
+ - :long
+ - :short
+ - :time
+ formats:
+ default: "%m/%d/%Y %I:%M%p"
+ short: "%B %e %I:%M %p"
+ long: "%A, %B %e, %Y %I:%M%p"
+ time: "%l:%M%p"
+ am: "am"
+ pm: "pm"
+```
### Compatibility

0 comments on commit 81d642d

Please sign in to comment.
Something went wrong with that request. Please try again.