date stamp macro and german formats

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
stfurrer
Posts: 5
Joined: 2005-12-03 12:17:06
Location: Switzerland

date stamp macro and german formats

Post by stfurrer »

Is there an easy way to change the format of the date-stamp-macro from english to german, i.e. from "December 18, 2005" to "18. Dezember 2005"? My main problem are the names of the months, not the order. I'm thankfull for every help.[/b]
cchapin
Posts: 424
Joined: 2004-02-25 18:28:40
Location: Nagoya, Japan

Post by cchapin »

I adapted a date macro I posted elsewhere. I don't speak German, so I got the month names off of the Internet, choosing randomly where I was given options. Edit the names to your liking. The macro works for me. I hope it works for you. Here is the code.

Code: Select all

#Nisus Macro Block
#destination clipboard
#source none
#Before Execution
#Clipboard 1
#After Execution
#Paste
#Clipboard 0
#End Nisus Macro Block
use strict;

# This macro gets the system date, formats it, then inserts it at the
# insertion point in the current Nisus Writer Express document.
# It was originally written for English use, but I’ve adapted it for
# German.
# --Craig Chapin (December 17, 2005)

#Declaration of variables.  Comment out (#) those you don't need.

my $Month;
my $DayMonth;
my $Year;

# The following block is used farther down to translate month abbreviations
# to German.

my %MonthName = (
	"Jan" => "Januar",
	"Feb" => "Februar",
	"Mar" => "März",
	"Apr" => "April",
	"May" => "Mai",
	"Jun" => "Juni",
	"Jul" => "Juli",
	"Aug" => "Augu?t",
	"Sep" => "September",
	"Oct" => "Oktober",
	"Nov" => "November",
	"Dec" => "Dezember"
);

# The following block gets the system time and formats some its elements.
# Comment out (#) the elements that you don't need.
# Don't comment the first line out. It gets the system time and isolates
# its elements.
# A typical system time string looks like this: Mon Jan  31 13:30:00 2000

if (localtime(time()) =~ /(\w+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/) {
	$Month = $MonthName{$2};	#Captures month abbr. and converts to German
	$DayMonth = $3;	#Captures day of month, just for ease of use
	$Year = $7;	#Captures year, just for ease of use
}

# The following lines format and insert the time.
# Choose the format you want and comment out the others.

print "$DayMonth. $Month $Year";
	# Example: January 31, 2000
--Craig

EDIT: You will definitely want to edit the month names. I see that August didn't come out right.
stfurrer
Posts: 5
Joined: 2005-12-03 12:17:06
Location: Switzerland

Post by stfurrer »

Many thanks to Craig/cchapin, your solution works fine for me, exactly what I needed. Merry X-mas!
cchapin
Posts: 424
Joined: 2004-02-25 18:28:40
Location: Nagoya, Japan

Post by cchapin »

You're welcome. Glad it helped.

I see another mistake in the last line of the macro. It should be

Code: Select all

   # Example: 31. Januar 2000
It's part of a comment, so it won't affect how the macro runs.

Incidentally, for others looking for the fuller English macro, it's here.

--Craig
Post Reply