Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 3.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[7,078 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 whoever posted them. This site is not responsible for what they say.
Translate cal's weekdays into other languages
Authored by: englabenny on Jun 17, '03 12:41:48PM
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 Jun 17, '03 01:28:43PM
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 Jun 17, '03 04:19:51PM
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 Jun 18, '03 06:45:40AM

perhaps TCSH checks back to the first alias made?



[ Reply to This | # ]
recompile from source
Authored by: hayne on Jun 17, '03 01:33:09PM
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 Jun 17, '03 03:43:32PM

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 Jun 17, '03 05:52:46PM
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 Jun 17, '03 07:55:18PM

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 Jun 18, '03 01:55:44AM
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 | # ]