This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to Replace WEEKDAY to another Language in tcl script

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Foxman
Voice
Posts: 9
Joined: Wed Jan 10, 2007 5:24 pm
Location: Delft, Zuid-Holland, The Netherlands
Contact:

How to Replace WEEKDAY to another Language in tcl script

Post by Foxman »

I've translated a script to Dutch (BogusTrivia) all good...

But i would also like to tranlate the Weekday's in the script the day's are called like this:

Code: Select all

[strftime %A $lut]
This will show: sunday, monday, tuesday, wednesday, thursday, friday or saturday

I thought doing something like:

Code: Select all

[TDoDay [strftime %A $lut]]

proc TDoDay {} {
  Sunday {  return Zondag  }
  Monday {  return Maandag  }
  Tuesday {  return Dinsdag  }
  Wednesday {  return Woensdag  }
  Thursday {  return Donderdag  }
  Friday {  return Vrijdag }
  Saturday {  return Zaterdag  }
 }
would do the thrick, but it doesn't work so far.

Does anyone have a suggestion on how to make this work?
Thank you
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

set nameOfDay [string map {
	Sunday    Zondag 
	Monday    Maandag
	Tuesday   Dinsdag
	Wednesday Woensdag
	Thursday  Donderdag
	Friday    Vrijdag
	Saturday  Zaterdag
} [strftime %A $lut]]
or use %w to get the day of week as an integer (0-6, 0 being sunday):

Code: Select all

set nameOfDay [lindex {Zondag Maandag Dinsdag Woensdag Donderdag Vrijdag Zaterdag} [clock format $lut -format %w]]
Have you ever read "The Manual"?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Use lindex and string map, assuming your strftime returns something like:

Thursday, Month Day Year Time

You can do:

set TDoDay [string map {Monday Maandag Tuesday Dinsdag (and so on)} [lindex [split [strftime %A $lut] ,] 0]]

Check the manpage for 'string' to see how to use string map.
Note the comma in the [split] command, if your strftime uses a comma after the day of week, otherwise [split [strftime %A $lut]] should do the trick. The way I did the line above stacks all of the commands into 1 line.
User avatar
Foxman
Voice
Posts: 9
Joined: Wed Jan 10, 2007 5:24 pm
Location: Delft, Zuid-Holland, The Netherlands
Contact:

Post by Foxman »

I take it:

If I would use:

Code: Select all

set nameOfDay [string map { 
   Sunday    Zondag 
   Monday    Maandag 
   Tuesday   Dinsdag 
   Wednesday Woensdag 
   Thursday  Donderdag 
   Friday    Vrijdag 
   Saturday  Zaterdag 
} [strftime %A $lut]]
I should replace
[strftime %A $lut] for $nameOfDay
in the script?

The actual line in the script is:

Code: Select all

set sholine "$tclr(-d10) [string toupper [strftime %A $lut]]S Top 10 - "
Thanks for the fast help again :)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

.tcl set lut [unixtime]
Tcl: 1173395909

.tcl set nameOfDay [string map {
Sunday Zondag
Monday Maandag
Tuesday Dinsdag
Wednesday Woensdag
Thursday Donderdag
Friday Vrijdag
Saturday Zaterdag} [strftime %A $lut]]
Tcl: Vrijdag

.tcl set nameOfDay [lindex {Zondag Maandag Dinsdag Woensdag Donderdag Vrijdag Zaterdag} [clock format $lut -format %w]]
Tcl: Vrijdag
User avatar
Foxman
Voice
Posts: 9
Joined: Wed Jan 10, 2007 5:24 pm
Location: Delft, Zuid-Holland, The Netherlands
Contact:

Post by Foxman »

Thanks a lot all, it worked! now i can do the same for MONTHS. %B

you guy's are great!
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

Hi,

I tried to do the same in spanish, so:
.tcl set lut [unixtime]
Tcl: 1173633454

.tcl set nameOfDay [lindex {Domingo Lunes Martes Miercoles Jueves Viernes Sabado} [clock format $lut -format %w]]
Tcl: Domingo

.tcl set nameOfMonth [lindex {Diciembre Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre} [clock format $lut -format %m]]
Tcl: Marzo
Nothing changed in the script, it still displays weekdays and months in English.

I didn't change anything in the script, dunno what should I add exactly, and where... I just made what I wrote above (in the console) :roll:
User avatar
Foxman
Voice
Posts: 9
Joined: Wed Jan 10, 2007 5:24 pm
Location: Delft, Zuid-Holland, The Netherlands
Contact:

Post by Foxman »

Hi Fly,


You have to look for the line

Code: Select all

set sholine "$tclr(-d10) [string toupper [strftime %A $lut]]S Top 10 - "
And add the new code/change old code like this

Code: Select all

       set nameOfDay [lindex {Domingo Lunes Martes Miercoles Jueves Viernes Sabado} [clock format $lut -format %w]] 
       set sholine "$tclr(-d10) [string toupper $nameOfDay]S Top 10 - "
       if {$t2(history)=="1" && $lcnt>"10"} {  set lcnt 10  }
       if {$t2(history)>"1" && $lcnt>"11"} {
         if {$lcnt>"20"} {  set lcnt 20  }
         set sholin2 "$tclr(-d10) [string toupper $nameOfDay]S Top 11-20: - "  }
Then it will work, and you can do the same for the Months

Further in the script you have to do it again for [strftime %A $dut], [strftime %B $dut]

Good luck :)

ps: you have to do it like this because $lut does only exist in that part of the script, and it shouldn't be unixtime (that is how i understand it. And it works for me :P)
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

Thanks Foxman, it works :wink:
User avatar
Foxman
Voice
Posts: 9
Joined: Wed Jan 10, 2007 5:24 pm
Location: Delft, Zuid-Holland, The Netherlands
Contact:

Post by Foxman »

About the month translation [lindex.. works only for 8 months ;)
i'll try the [string Map... now

See yah :)
Post Reply