Initial commit.
This commit is contained in:
108
lib/perl5/Selima/ShortCut.pm
Normal file
108
lib/perl5/Selima/ShortCut.pm
Normal file
@@ -0,0 +1,108 @@
|
||||
# Selima Website Content Management System
|
||||
# ShortCut.pm: The shortcut subroutines.
|
||||
|
||||
# Copyright (c) 2003-2018 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
# First written: 2003-03-23
|
||||
|
||||
package Selima::ShortCut;
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(Exporter);
|
||||
use vars qw(@EXPORT @EXPORT_OK);
|
||||
BEGIN {
|
||||
@EXPORT = qw(h dh __ C_ F_ N_);
|
||||
@EXPORT_OK = @EXPORT;
|
||||
# Prototype declaration
|
||||
sub h($);
|
||||
sub dh($);
|
||||
sub __($@);
|
||||
sub C_($@);
|
||||
sub F_($@);
|
||||
sub N_($@);
|
||||
}
|
||||
|
||||
use Selima::DataVars qw(:l10n);
|
||||
|
||||
# Define them first
|
||||
# h: Escape the HTML characters
|
||||
sub h($) {
|
||||
local ($_, %_);
|
||||
$_ = $_[0];
|
||||
return "" if !defined $_;
|
||||
s/&/&/g;
|
||||
s/</</g;
|
||||
s/>/>/g;
|
||||
s/"/"/g; # (xgettext) "
|
||||
return $_;
|
||||
}
|
||||
|
||||
# dh: De-escape the HTML characters
|
||||
sub dh($) {
|
||||
local ($_, %_);
|
||||
$_ = $_[0];
|
||||
return "" if !defined $_;
|
||||
s/"/"/g; # (xgettext) "
|
||||
s/>/>/g;
|
||||
s/</</g;
|
||||
s/&/&/g;
|
||||
return $_;
|
||||
}
|
||||
|
||||
# N_: Null maketext function
|
||||
sub N_($@) {
|
||||
# Watch out for this perl magic! :p
|
||||
return $_[0] unless wantarray;
|
||||
return @_;
|
||||
}
|
||||
|
||||
# We must load SetL10N after N_().
|
||||
use Selima::SetL10N;
|
||||
|
||||
# __: Maketext/gettext
|
||||
sub __($@) {
|
||||
local ($_, %_);
|
||||
my ($key, @params, $pkg);
|
||||
($key, @params) = @_;
|
||||
# Initialize the localization framework
|
||||
set_l10n if !defined $LH;
|
||||
return $LH->maketext($key, @params);
|
||||
}
|
||||
# C_: Maketext in the common domain
|
||||
sub C_($@) {
|
||||
local ($_, %_);
|
||||
my ($key, @params);
|
||||
($key, @params) = @_;
|
||||
# Initialize the localization framework
|
||||
set_l10n if !defined $CLH;
|
||||
return $CLH->maketext($key, @params);
|
||||
}
|
||||
# F_: Maketext, fallback from the current domain to the common domain
|
||||
sub F_($@) {
|
||||
local ($_, %_);
|
||||
my ($key, @params, $pkg);
|
||||
($key, @params) = @_;
|
||||
# Initialize the localization framework
|
||||
Selima::SetL10N::set_l10n if !defined $LH || !defined $CLH;
|
||||
# Try the local text
|
||||
return $LH->maketext($key, @params)
|
||||
if exists ${$LH->{"Lexicon"}}{$key};
|
||||
# Try the common text
|
||||
return $CLH->maketext($key, @params);
|
||||
}
|
||||
|
||||
return 1;
|
||||
Reference in New Issue
Block a user