Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use :en as a default locale (in favor of :en-US)

  • Loading branch information...
commit b0cacab580324bca1ba034c207cfba01203f4b1a 1 parent 7468f7a
@zargony zargony authored
View
20 README
@@ -12,8 +12,8 @@ To install the plugin, change into an existing Rails application and run
ruby script/plugin install git://github.com/clemens/localized_dates.git
This will download the plugin and store it in vendor/plugins/localized_dates. It will also create a directory named
-config/locales and copy three locale files, en-US.rb, en-US.yml, and de-AT.yml into this directory. While the en-US
-locale files mimic current Rails formats, de-AT serves as a demo on how date and time formats can be customized.
+config/locales and copy three locale files, en.rb, en.yml, and de.yml into this directory. While the "en"
+locale files mimic current Rails formats, "de" serves as a demo on how date and time formats can be customized.
Adding a new locale
=================
@@ -24,9 +24,9 @@ locale and basing your new locale on it.
Adding new date and time formats
=================
-Adding new date and time formats is easy. Take a look at the basic structure of the locale file en-US.yml:
+Adding new date and time formats is easy. Take a look at the basic structure of the locale file en.yml:
- "en-US":
+ en:
date:
formats:
default: "%Y-%m-%d"
@@ -50,13 +50,13 @@ Adding new date and time formats is easy. Take a look at the basic structure of
pm: 'pm'
As you can see, there are two basic entites: date and time. time also has two children, datetime and time_with_zone
-that both inherit from :time so you usually don't even need to define them (the de-AT locale, for, example doesn't).
+that both inherit from :time so you usually don't even need to define them (the "de" locale, for, example doesn't).
If you need more complex Ruby constructs such as lambdas, you still need to define them in a separate Ruby file. Take
-a look at the following default formats of en-US.rb:
+a look at the following default formats of en.rb:
{
- :'en-US' => {
+ :en => {
:date => {
:formats => {
:long_ordinal => lambda { |date| "%B #{date.day.ordinalize}, %Y" }
@@ -107,7 +107,7 @@ Customizing day and month names
If you localize your application for a language other than English, you most likely want to change the default month
and day names to your own countries' names. Here's how it's done:
- "de-AT":
+ de:
date:
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
@@ -122,10 +122,10 @@ the definition of day names starts with Sunday (not Monday).
Changing the default locale
=================
-If you want to use a default locale other than en-US, you have to tell the i18n plugin the locale you want to use by
+If you want to use a default locale other than "en", you have to tell the i18n plugin the locale you want to use by
default. Simply put the following line in an initializer in config/initializers or include it in your environment.rb:
- I18n.default_locale = 'de-AT'
+ I18n.default_locale = :de
Contributors
=================
View
4 init.rb
@@ -9,5 +9,5 @@
Rails.logger.info '** [localized_dates] locales loaded from config/locales.'
-# set default locale to en-US
-I18n.default_locale = 'en-US'
+# set default locale to en
+I18n.default_locale = 'en'
View
2  install.rb
@@ -4,7 +4,7 @@
Dir.mkdir(locales_dir) unless File.directory?(locales_dir)
locales_template_dir = File.join(File.dirname(__FILE__), 'lib', 'templates', 'locales')
-['en-US.rb', 'en-US.yml', 'de-AT.yml'].each do |locale|
+['en.rb', 'en.yml', 'de.yml'].each do |locale|
FileUtils.cp(File.join(locales_template_dir, locale), File.join(locales_dir, locale))
end
View
2  lib/templates/locales/de-AT.yml → lib/templates/locales/de.yml
@@ -1,4 +1,4 @@
-"de-AT":
+de:
date:
formats:
default: "%d.%m.%Y"
View
2  lib/templates/locales/en-US.rb → lib/templates/locales/en.rb
@@ -1,5 +1,5 @@
{
- :'en-US' => {
+ :en => {
:date => {
:formats => {
:long_ordinal => lambda { |date| "%B #{date.day.ordinalize}, %Y" }
View
2  lib/templates/locales/en-US.yml → lib/templates/locales/en.yml
@@ -1,4 +1,4 @@
-"en-US":
+en:
date:
formats:
default: "%Y-%m-%d"
View
4 spec/localized_dates_spec.rb
@@ -4,8 +4,8 @@
before(:each) do
# load locale files
locales_dir = File.dirname(__FILE__) + "/../lib/templates/locales"
- I18n.load_translations("#{locales_dir}/en-US.rb")
- I18n.load_translations("#{locales_dir}/en-US.yml")
+ I18n.load_translations("#{locales_dir}/en.rb")
+ I18n.load_translations("#{locales_dir}/en.yml")
# set up defaults
@date_defaults = { :default => "%Y-%m-%d",
Please sign in to comment.
Something went wrong with that request. Please try again.