Revision 541272c5
Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt
SL/Form.pm | ||
---|---|---|
2413 | 2413 |
|
2414 | 2414 |
} |
2415 | 2415 |
|
2416 |
package Locale; |
|
2417 |
|
|
2418 |
sub new { |
|
2419 |
$main::lxdebug->enter_sub(); |
|
2420 |
|
|
2421 |
my ($type, $country, $NLS_file) = @_; |
|
2422 |
my $self = {}; |
|
2423 |
|
|
2424 |
if ($country && -d "locale/$country") { |
|
2425 |
local *IN; |
|
2426 |
$self->{countrycode} = $country; |
|
2427 |
if (open(IN, "locale/$country/$NLS_file")) { |
|
2428 |
my $code = join("", <IN>); |
|
2429 |
eval($code); |
|
2430 |
close(IN); |
|
2431 |
} |
|
2432 |
} |
|
2433 |
|
|
2434 |
$self->{NLS_file} = $NLS_file; |
|
2435 |
|
|
2436 |
push @{ $self->{LONG_MONTH} }, |
|
2437 |
("January", "February", "March", "April", |
|
2438 |
"May ", "June", "July", "August", |
|
2439 |
"September", "October", "November", "December"); |
|
2440 |
push @{ $self->{SHORT_MONTH} }, |
|
2441 |
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)); |
|
2442 |
|
|
2443 |
$main::lxdebug->leave_sub(); |
|
2444 |
|
|
2445 |
bless $self, $type; |
|
2446 |
} |
|
2447 |
|
|
2448 |
sub text { |
|
2449 |
my ($self, $text) = @_; |
|
2450 |
|
|
2451 |
return (exists $self->{texts}{$text}) ? $self->{texts}{$text} : $text; |
|
2452 |
} |
|
2453 |
|
|
2454 |
sub findsub { |
|
2455 |
$main::lxdebug->enter_sub(); |
|
2456 |
|
|
2457 |
my ($self, $text) = @_; |
|
2458 |
|
|
2459 |
if (exists $self->{subs}{$text}) { |
|
2460 |
$text = $self->{subs}{$text}; |
|
2461 |
} else { |
|
2462 |
if ($self->{countrycode} && $self->{NLS_file}) { |
|
2463 |
Form->error( |
|
2464 |
"$text not defined in locale/$self->{countrycode}/$self->{NLS_file}"); |
|
2465 |
} |
|
2466 |
} |
|
2467 |
|
|
2468 |
$main::lxdebug->leave_sub(); |
|
2469 |
|
|
2470 |
return $text; |
|
2471 |
} |
|
2472 |
|
|
2473 |
sub date { |
|
2474 |
$main::lxdebug->enter_sub(); |
|
2475 |
|
|
2476 |
my ($self, $myconfig, $date, $longformat) = @_; |
|
2477 |
|
|
2478 |
my $longdate = ""; |
|
2479 |
my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH'; |
|
2480 |
|
|
2481 |
if ($date) { |
|
2482 |
|
|
2483 |
# get separator |
|
2484 |
$spc = $myconfig->{dateformat}; |
|
2485 |
$spc =~ s/\w//g; |
|
2486 |
$spc = substr($spc, 1, 1); |
|
2487 |
|
|
2488 |
if ($date =~ /\D/) { |
|
2489 |
if ($myconfig->{dateformat} =~ /^yy/) { |
|
2490 |
($yy, $mm, $dd) = split /\D/, $date; |
|
2491 |
} |
|
2492 |
if ($myconfig->{dateformat} =~ /^mm/) { |
|
2493 |
($mm, $dd, $yy) = split /\D/, $date; |
|
2494 |
} |
|
2495 |
if ($myconfig->{dateformat} =~ /^dd/) { |
|
2496 |
($dd, $mm, $yy) = split /\D/, $date; |
|
2497 |
} |
|
2498 |
} else { |
|
2499 |
$date = substr($date, 2); |
|
2500 |
($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/); |
|
2501 |
} |
|
2502 |
|
|
2503 |
$dd *= 1; |
|
2504 |
$mm--; |
|
2505 |
$yy = ($yy < 70) ? $yy + 2000 : $yy; |
|
2506 |
$yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy; |
|
2507 |
|
|
2508 |
if ($myconfig->{dateformat} =~ /^dd/) { |
|
2509 |
if (defined $longformat && $longformat == 0) { |
|
2510 |
$mm++; |
|
2511 |
$dd = "0$dd" if ($dd < 10); |
|
2512 |
$mm = "0$mm" if ($mm < 10); |
|
2513 |
$longdate = "$dd$spc$mm$spc$yy"; |
|
2514 |
} else { |
|
2515 |
$longdate = "$dd"; |
|
2516 |
$longdate .= ($spc eq '.') ? ". " : " "; |
|
2517 |
$longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy"; |
|
2518 |
} |
|
2519 |
} elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") { |
|
2520 |
|
|
2521 |
# Use German syntax with the ISO date style "yyyy-mm-dd" because |
|
2522 |
# Lx-Office is mainly used in Germany or German speaking countries. |
|
2523 |
if (defined $longformat && $longformat == 0) { |
|
2524 |
$mm++; |
|
2525 |
$dd = "0$dd" if ($dd < 10); |
|
2526 |
$mm = "0$mm" if ($mm < 10); |
|
2527 |
$longdate = "$yy-$mm-$dd"; |
|
2528 |
} else { |
|
2529 |
$longdate = "$dd. "; |
|
2530 |
$longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy"; |
|
2531 |
} |
|
2532 |
} else { |
|
2533 |
if (defined $longformat && $longformat == 0) { |
|
2534 |
$mm++; |
|
2535 |
$dd = "0$dd" if ($dd < 10); |
|
2536 |
$mm = "0$mm" if ($mm < 10); |
|
2537 |
$longdate = "$mm$spc$dd$spc$yy"; |
|
2538 |
} else { |
|
2539 |
$longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy"; |
|
2540 |
} |
|
2541 |
} |
|
2542 |
|
|
2543 |
} |
|
2544 |
|
|
2545 |
$main::lxdebug->leave_sub(); |
|
2546 |
|
|
2547 |
return $longdate; |
|
2548 |
} |
|
2549 |
|
|
2550 |
sub parse_date { |
|
2551 |
$main::lxdebug->enter_sub(); |
|
2552 |
|
|
2553 |
my ($self, $myconfig, $date, $longformat) = @_; |
|
2554 |
|
|
2555 |
unless ($date) { |
|
2556 |
$main::lxdebug->leave_sub(); |
|
2557 |
return (); |
|
2558 |
} |
|
2559 |
|
|
2560 |
# get separator |
|
2561 |
$spc = $myconfig->{dateformat}; |
|
2562 |
$spc =~ s/\w//g; |
|
2563 |
$spc = substr($spc, 1, 1); |
|
2564 |
|
|
2565 |
if ($date =~ /\D/) { |
|
2566 |
if ($myconfig->{dateformat} =~ /^yy/) { |
|
2567 |
($yy, $mm, $dd) = split /\D/, $date; |
|
2568 |
} elsif ($myconfig->{dateformat} =~ /^mm/) { |
|
2569 |
($mm, $dd, $yy) = split /\D/, $date; |
|
2570 |
} elsif ($myconfig->{dateformat} =~ /^dd/) { |
|
2571 |
($dd, $mm, $yy) = split /\D/, $date; |
|
2572 |
} |
|
2573 |
} else { |
|
2574 |
$date = substr($date, 2); |
|
2575 |
($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/); |
|
2576 |
} |
|
2577 |
|
|
2578 |
$dd *= 1; |
|
2579 |
$mm *= 1; |
|
2580 |
$yy = ($yy < 70) ? $yy + 2000 : $yy; |
|
2581 |
$yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy; |
|
2582 |
|
|
2583 |
$main::lxdebug->leave_sub(); |
|
2584 |
return ($yy, $mm, $dd); |
|
2585 |
} |
|
2586 |
|
|
2587 |
sub reformat_date { |
|
2588 |
$main::lxdebug->enter_sub(); |
|
2589 |
|
|
2590 |
my ($self, $myconfig, $date, $output_format, $longformat) = @_; |
|
2591 |
|
|
2592 |
$main::lxdebug->leave_sub() and return "" unless ($date); |
|
2593 |
|
|
2594 |
my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date); |
|
2595 |
|
|
2596 |
$output_format =~ /d+/; |
|
2597 |
substr($output_format, $-[0], $+[0] - $-[0]) = |
|
2598 |
sprintf("%0" . (length($&)) . "d", $dd); |
|
2599 |
|
|
2600 |
$output_format =~ /m+/; |
|
2601 |
substr($output_format, $-[0], $+[0] - $-[0]) = |
|
2602 |
sprintf("%0" . (length($&)) . "d", $mm); |
|
2603 |
|
|
2604 |
$output_format =~ /y+/; |
|
2605 |
if (length($&) == 2) { |
|
2606 |
$yy -= $yy >= 2000 ? 2000 : 1900; |
|
2607 |
} |
|
2608 |
substr($output_format, $-[0], $+[0] - $-[0]) = |
|
2609 |
sprintf("%0" . (length($&)) . "d", $yy); |
|
2610 |
|
|
2611 |
$main::lxdebug->leave_sub(); |
|
2612 |
|
|
2613 |
return $output_format; |
|
2614 |
} |
|
2615 |
|
|
2616 | 2416 |
1; |
Auch abrufbar als: Unified diff
Beim Login wird jetzt ein Check durchgeführt, ob alle benötigten Perl-Module installiert sind. Wenn nicht, dann wird eine Fehlermeldung sowie eine Liste der fehlenden Module ausgegeben sowie grobe Informationen, wie man die fehlenden Module nachinstallieren kann.