Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Translate cal's weekdays into other languages UNIX

If your preferred language is other than English, you'd probably like to have the cal command in you own language. To do this, replace the English name of the days using a sed expression, and include it in an alias in your .tcshrc file. For French, it is:

alias cal "cal | sed 's/ S  M Tu  W Th  F  S/Di Lu Ma Me Je Ve Sa/'"
Now when you run cal, you'll actually be running the alias, and it will replace the English dates with your language's versions.
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[4,839 views]  

Translate cal's weekdays into other languages | 9 comments | Create New Account
Click here to return to the 'Translate cal's weekdays into other languages' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Translate cal's weekdays into other languages
Authored by: englabenny on Tue, Jun 17 2003 at 12:41PM PDT
What if you want to view the whole year with cal -y? You have to do your alias this way: (for tcsh)
alias cal "cal \!* | sed 's/ S  M Tu  W Th  F  S/ S  M  Ti O  To F  L/g'"
Now the alias will accept cal options and replace every occurrence of the weekdays string if there are many.

[ Reply to This | # ]
Translate cal's weekdays into other languages
Authored by: Evil B on Tue, Jun 17 2003 at 1:28PM PDT
how come this cal function doesn't get stuck in an infinite loop?

would it be more logical to use

alias cal "/usr/bin/cal \!* | sed 's/ S M Tu W Th F S/ S M Ti O To F L/g'"

[ Reply to This | # ]

Translate cal's weekdays into other languages
Authored by: englabenny on Tue, Jun 17 2003 at 4:19PM PDT
Tcsh seems to know that loops can occur, and checks for them. If I made up an alias called cal, where cal wasn't the first command called, tcsh would report it.

It would complain on such a thing as: (not that it makes sense, but it's just an example.)
% alias cal 'date | cal'
% cal
Alias loop.


[ Reply to This | # ]
Translate cal's weekdays into other languages
Authored by: Evil B on Wed, Jun 18 2003 at 6:45AM PDT
perhaps TCSH checks back to the first alias made?

[ Reply to This | # ]
recompile from source
Authored by: hayne on Tue, Jun 17 2003 at 1:33PM PDT
I know this is harder for most people, but an alternative would be to recompile the 'cal' command from source (after changing the day & month names to your language).

The source code is available after you register (for free), agreeing to Apple's Open Source License: source for cal

[ Reply to This | # ]

Translate cal's weekdays into other languages
Authored by: Greedo on Tue, Jun 17 2003 at 3:43PM PDT

The "proper" way to do this would be to use the LANG environment variable to define what language to show text in. However, it doesn't appear that OS X has proper locale support, or cal wasn't built with it.

On most *nixes, you could do:

export LANG=fr_FR
cal

Oh well ... I bet the fink version of cal supports this.



[ Reply to This | # ]
locale
Authored by: hayne on Tue, Jun 17 2003 at 5:52PM PDT
While OS X does support locale, programs need to be explicitly written to use the locale facility in order for it to have any effect. The 'cal' program does not make any effort to use other languages. The source code shows the following:
char *month_names[12] = {
        "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December",
};
char *day_headings = " S  M Tu  W Th  F  S";
And which "fink version of cal" were you referring to? I don't see any version of 'cal' available from fink.

[ Reply to This | # ]
locale
Authored by: Greedo on Tue, Jun 17 2003 at 7:55PM PDT
I spoke too soon about fink. You are right: there is no cal package in fink. I just assumed there was. Oops!



[ Reply to This | # ]
Translate cal's weekdays into other languages
Authored by: sjk on Wed, Jun 18 2003 at 1:55AM PDT
Gcal is a command line calendar with many features. Compiles easily on 10.2.x. Not sure if it's available with Fink.

[ Reply to This | # ]