Chinese strftime

Hi guys,

I need to translate the strftime into chinese.

I found a tutorial (ref:
http://out-of-pc.blogspot.com/2008/01/ruby-on-rails.html)
<code>
require 'date'
Date::ABBR_DAYNAMES.replace %w(日 一 二 三 四 五 六)
Date::DAYNAMES.replace %w(星期日 星期一 星期二 星期三 星期四 星期五 星期六)
12月)
Date::MONTHNAMES.replace %w(nil 一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月)
</code>

It asked us to update the environment.rb.

However, I found "replace can't modify frozen array" error when I
restart the server.

I don't know whether this way to update the frozen array is correct? Is
there any better solution?

My Rails is "2.0.2".

Thanks much
Arthur

···

Date::ABBR_MONTHNAMES.replace %w(nil 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月
--
Posted via http://www.ruby-forum.com/.

well...

1.Date::ABBR_DAYNAMES is a const var, you can do force-assignment:
Date::ABBR_DAYNAMES=%w[日 一 二 三 四 五 六]
just ignore the warnings.

2.Date::ABBR_DAYNAMES is a frezon object, you do some hacking to unfreeze
it:

<code>

   1. require 'dl/struct'
   2.
   3. module Internal
   4. extend DL::Importable
   5.
   6. typealias "VALUE",nil,nil,nil,"unsigned long"
   7. typealias "ID",nil,nil,nil,"unsigned long"
   8.
   9. Basic=["long flags","VALUE klass"]
   10. RBasic=struct Basic
   11. RObject=struct(Basic+["st_table *iv_tbl"])
   12.
   13. FL_FREEZE=1<<10
   14. end
   15.
   16. class Object
   17. def immediate?
   18. [Fixnum,Symbol,NilClass,TrueClass,FalseClass].any?{ |klass| klass
   ===self}
   19. end
   20.
   21. def unfreeze
   22. return self if immediate?
   23. Internal::RObject.new(DL::PtrData.new(self.object_id * 2)).flags&= ~
   Internal::FL_FREEZE
   24. self
   25. end
   26.
   27. end
   28.
   29. Date::ABBR_DAYNAMES.unfreeze
   30. Date::ABBR_DAYNAMES.replace.....

</code>

But... I think it's much easizer *changing you local(set it to zh_CN.utf-8)
*to make strftime return chinese.

···

On Mon, Jun 8, 2009 at 1:25 PM, Arthur Chan <arthur@pixopixel.com> wrote:

Hi guys,

I need to translate the strftime into chinese.

I found a tutorial (ref:
http://out-of-pc.blogspot.com/2008/01/ruby-on-rails.html\)
<code>
require 'date'
Date::ABBR_DAYNAMES.replace %w(日 一 二 三 四 五 六)
Date::DAYNAMES.replace %w(星期日 星期一 星期二 星期三 星期四 星期五 星期六)
Date::ABBR_MONTHNAMES.replace %w(nil 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月
12月)
Date::MONTHNAMES.replace %w(nil 一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月)
</code>

It asked us to update the environment.rb.

However, I found "replace can't modify frozen array" error when I
restart the server.

I don't know whether this way to update the frozen array is correct? Is
there any better solution?

My Rails is "2.0.2".

Thanks much
Arthur
--
Posted via http://www.ruby-forum.com/\.

--
Best Regards,
   -- KDr2, at x-macro.com.