[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Chinese strftime

Arthur Chan

6/8/2009 5:26:00 AM

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-...)
<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-....

1 Answer

KDr2

6/8/2009 5:49:00 AM

0

well...

1.Date::ABBR_DAYNAMES is a const var, you can do force-assignment:
Date::ABBR_DAYNAMES=3D%w[=E6=97=A5 =E4=B8=80 =E4=BA=8C =E4=B8=89 =E5=9B=9B =
=E4=BA=94 =E5=85=AD]
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=3D["long flags","VALUE klass"]
10. RBasic=3Dstruct Basic
11. RObject=3Dstruct(Basic+["st_table *iv_tbl"])
12.
13. FL_FREEZE=3D1<<10
14. end
15.
16. class Object
17. def immediate?
18. [Fixnum,Symbol,NilClass,TrueClass,FalseClass].any?{ |klass| klas=
s
=3D=3D=3Dself}
19. end
20.
21. def unfreeze
22. return self if immediate?
23. Internal::RObject.new(DL::PtrData.new(self.object_id * 2)).flags=
&=3D ~
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-...)
> <code>
> require 'date'
> Date::ABBR_DAYNAMES.replace %w(=E6=97=A5 =E4=B8=80 =E4=BA=8C =E4=B8=89 =
=E5=9B=9B =E4=BA=94 =E5=85=AD)
> Date::DAYNAMES.replace %w(=E6=98=9F=E6=9C=9F=E6=97=A5 =E6=98=9F=E6=9C=9F=
=E4=B8=80 =E6=98=9F=E6=9C=9F=E4=BA=8C =E6=98=9F=E6=9C=9F=E4=B8=89 =E6=98=9F=
=E6=9C=9F=E5=9B=9B =E6=98=9F=E6=9C=9F=E4=BA=94 =E6=98=9F=E6=9C=9F=E5=85=AD)
> Date::ABBR_MONTHNAMES.replace %w(nil 1=E6=9C=88 2=E6=9C=88 3=E6=9C=88 4=
=E6=9C=88 5=E6=9C=88 6=E6=9C=88 7=E6=9C=88 8=E6=9C=88 9=E6=9C=88 10=E6=9C=
=88 11=E6=9C=88
> 12=E6=9C=88)
> Date::MONTHNAMES.replace %w(nil =E4=B8=80=E6=9C=88 =E4=BA=8C=E6=9C=88 =E4=
=B8=89=E6=9C=88 =E5=9B=9B=E6=9C=88 =E4=BA=94=E6=9C=88 =E5=85=AD=E6=9C=88 =
=E4=B8=83=E6=9C=88 =E5=85=AB=E6=9C=88 =E4=B9=9D=E6=9C=88 =E5=8D=81=E6=9C=88=
=E5=8D=81=E4=B8=80=E6=9C=88 =E5=8D=81=E4=BA=8C=E6=9C=88)
> </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-....
>
>


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