From 82cb71ac6024a63d7b8b1abe883db36831a50920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 7 Feb 2021 17:46:47 +0800 Subject: [PATCH] Various fixes to avoid JetBrains IDE problem detection. --- Changes | 26 ++-- lib/Locale/Maketext/Gettext.pm | 79 ++++++------- lib/Locale/Maketext/Gettext/Functions.pm | 144 +++++++++++------------ script/maketext | 33 +++--- t/11-command-line.t | 2 +- t/12-cache.t | 5 +- 6 files changed, 142 insertions(+), 147 deletions(-) mode change 100755 => 100644 script/maketext diff --git a/Changes b/Changes index 3851013..1e1e04e 100644 --- a/Changes +++ b/Changes @@ -13,7 +13,7 @@ Locale-Maketext-Gettext change log 1. Gettext.pm: Added support to purge the lexicon cache and reread the MO file on calling textdomain() when MO file is updated automatically. This enables MO file live update with - persistant applications like Mojolicious or mod_perl. + persistent applications like Mojolicious or mod_perl. 2. Source is now on Github. See: https://github.com/imacat/Locale-Maketext-Gettext @@ -38,7 +38,7 @@ Locale-Maketext-Gettext change log the test is skipped on the target test system. 2008-11-11 - 1. INSTALL: Fixed the grammer, changed "none" to "None.". + 1. INSTALL: Fixed the grammar, changed "none" to "None.". 2008-04-22 version 1.26 Documentation fix. No code changes. @@ -69,7 +69,7 @@ Locale-Maketext-Gettext change log test_native.po and test_native.mo. 5. Build.PL: Added "build_requires". 6. t/08-f-errors.t: Fixed so that it finds the newest MO file - found on the system, in order to avoid lagacy MO files. + found on the system, in order to avoid legacy MO files. (gettext 0.10 in 1995?) 7. t/08-f-errors.t: Fixed test 38 so that it skips in the eval() block, and dumps the error on failure. @@ -153,7 +153,7 @@ Locale-Maketext-Gettext change log preference. 13. Gettext.pm and Functions.pm: In maketext(), check if the key is Perl utf8 text with Encode::is_utf8() first before decode() the - key, so that user can safely run a multibyte-awared script. + key, so that user can safely run a multibyte-aware script. 14. Gettext.pm and Functions.pm: In maketext(), check if the key is Perl utf8 text with Encode::is_utf8() first before encode(), for empty/invalid lexicon with key_encoding() set but no output @@ -164,7 +164,7 @@ Locale-Maketext-Gettext change log 15. Functions.pm: In __(), removed unused variables $encoding, $lh_encoding and $key_encoding. 16. maketext: In parse_args(), check the return value of the eval { } - block instead of $@, and remove the extra new line when outputing + block instead of $@, and remove the extra new line when writing the error in $@. 17. maketext: Added an example at the DESCRIPTION chapter of the POD documentation. @@ -179,7 +179,7 @@ Locale-Maketext-Gettext change log the fail_with() method, instead of our own. Clean up encoding mess. You may need to check if your application was depending on the previous wrong, hard-to-handle behavior on look - up failurs. The new behavior should be easier to deal with. + up failures. The new behavior should be easier to deal with. 1. Gettext.pm: In the textdomain() function, make sure {"ENCODING"} is not set to undef when MO file does not exists. 2. Functions.pm: In the encoding() function, removed a piece of long @@ -250,7 +250,7 @@ Locale-Maketext-Gettext change log as its error message. Tests replying on $@ may fail for this. But I should check the return value of the eval{} block rather than $@ anyway. - 1. t/*.t: Adition of $r as the return value of the eval{} blocks. + 1. t/*.t: Addition of $r as the return value of the eval{} blocks. Addition of "return 1;" to the eval{} blocks to specify the return values. Changing tests "ok($@, "");" to "ok($r, 1);". Changing tests "ok($@, qr/maketext doesn't know how to say/);" and @@ -334,7 +334,7 @@ Locale-Maketext-Gettext change log 14. Functions.pm: Warning is added to the use of key_encoding(). 2005-04-05 - 1. Gettext.pm: Subroutine attribute "method" is taged on the + 1. Gettext.pm: Subroutine attribute "method" is tagged on the following methods: encoding(), key_encoding(), new(), subclass_init(), bindtextdomain(), textdomain(), maketext(), reload_text(), die_for_lookup_failures() and encode_failure(). @@ -413,7 +413,7 @@ Locale-Maketext-Gettext change log 1. Support for MO files without encoding specified was added. I don't know there are MO files born without its encoding. ^^; 2. L::M::G::F: textdomain() now works for default system locale - directories, too. For domains that are not binded with + directories, too. For domains that are not bound with bindtextdomain(), it searches the system locale directories to find the domain MO files. Unlike textdomain() in L::M::G, it remembers the search result in order to build the index key. @@ -421,7 +421,7 @@ Locale-Maketext-Gettext change log may be skipped, though. 2003-05-02 version 1.03 - 1. L::M::G: A algorism bug about key_encoding with auto-lexicon was + 1. L::M::G: A algorithm bug about key_encoding with auto-lexicon was fixed. 2. L::M::G::F: I decide to give up mod_perl safety for encoding, key_encoding, encode_failure and die_for_lookup_failures(). @@ -505,13 +505,13 @@ Locale-Maketext-Gettext change log 2003-04-27 version 0.06 Improvements. 1. textdomain() works for default system locale directories now. For - domains that are not binded with bindtextdomain(), it searches the + domains that are not bound with bindtextdomain(), it searches the system locale directories to find the MO file. No test suite is available for this functionality. I cannot predict what MO files are available in your system locale directories. ^^; Please report bugs if it does not work. 2. Slave package Locale::Maketext::Gettext::_AUTO::L10N is added, in - order to process the _AUTO Lexicon seperately. This saves + order to process the _AUTO Lexicon separately. This saves resources when user change the die_for_lookup_failures() setting. Changing die_for_lookup_failures() setting won't trigger copying and replacing your whole %Lexicon anymore. As an effect, the @@ -520,7 +520,7 @@ Locale-Maketext-Gettext change log 3. read_mo() is added to retire the readmo(). Use of readmo() is deprecated. This idea is inspired by the implementation of readmo() as "parse_mo" in Locale::Maketext::Lexicon by Autrijus. - There is far too much meta infomation to be returned other than + There is far too much meta information to be returned other than its encoding. It's not possible to change the API for each new requirement. To enable sharing of the algorithm used in read_mo() with whoever need it, it's necessary to limit its function to read diff --git a/lib/Locale/Maketext/Gettext.pm b/lib/Locale/Maketext/Gettext.pm index 7471e06..94b3dfc 100644 --- a/lib/Locale/Maketext/Gettext.pm +++ b/lib/Locale/Maketext/Gettext.pm @@ -1,16 +1,16 @@ # Locale::Maketext::Gettext - Joins the gettext and Maketext frameworks -# Copyright (c) 2003-2019 imacat. All rights reserved. This program is free +# Copyright (c) 2003-2021 imacat. All rights reserved. This program is free # software; you can redistribute it and/or modify it under the same terms # as Perl itself. -# First written: 2003-04-23 +# First written: 2003/4/23 package Locale::Maketext::Gettext; use 5.008; use strict; use warnings; use base qw(Locale::Maketext Exporter); -use vars qw($VERSION @ISA %Lexicon @EXPORT @EXPORT_OK); +our ($VERSION, @EXPORT, @EXPORT_OK); $VERSION = 1.30; @EXPORT = qw(read_mo); @EXPORT_OK = @EXPORT; @@ -21,15 +21,15 @@ use Encode qw(encode decode FB_DEFAULT); use File::Spec::Functions qw(catfile); no strict qw(refs); -use vars qw(%CACHE $REREAD_MO $MO_FILE); +our (%CACHE, $REREAD_MO, $MO_FILE); %CACHE = qw(); $REREAD_MO = 0; $MO_FILE = ""; -use vars qw(@SYSTEM_LOCALEDIRS); +our (@SYSTEM_LOCALEDIRS); @SYSTEM_LOCALEDIRS = qw(/usr/share/locale /usr/lib/locale /usr/local/share/locale /usr/local/lib/locale); -# encoding: Set or retrieve the output encoding +# Set or retrieve the output encoding sub encoding : method { local ($_, %_); my $self; @@ -52,7 +52,7 @@ sub encoding : method { return exists $self->{"ENCODING"}? $self->{"ENCODING"}: undef; } -# key_encoding: Specify the encoding used in the keys +# Specify the encoding used in the keys sub key_encoding : method { local ($_, %_); my $self; @@ -74,7 +74,7 @@ sub key_encoding : method { return exists $self->{"KEY_ENCODING"}? $self->{"KEY_ENCODING"}: undef; } -# new: Initialize the language handler +# Initialize the language handler sub new : method { local ($_, %_); my ($self, $class); @@ -85,8 +85,8 @@ sub new : method { return $self; } -# subclass_init: Initialize at the subclass level, so that it can be -# inherited by calling $self->SUPER:subclass_init +# Initialize at the subclass level, so that it can be +# inherited by calling $self->SUPER:subclass_init sub subclass_init : method { local ($_, %_); my ($self, $class); @@ -119,7 +119,7 @@ sub subclass_init : method { return; } -# bindtextdomain: Bind a text domain to a locale directory +# Bind a text domain to a locale directory sub bindtextdomain : method { local ($_, %_); my ($self, $DOMAIN, $LOCALEDIR); @@ -139,7 +139,7 @@ sub bindtextdomain : method { return ${$self->{"LOCALEDIRS"}}{$DOMAIN}; } -# textdomain: Set the current text domain +# Set the current text domain sub textdomain : method { local ($_, %_); my ($self, $class, $DOMAIN, $LOCALEDIR, $mo_file); @@ -232,7 +232,7 @@ sub textdomain : method { } else { delete $self->{"MO_ENCODING"}; } - # Respect the MO file encoding unless there is a user preferrence + # Respect the MO file encoding unless there is a user preference if (!exists $self->{"USERSET_ENCODING"}) { if (exists $self->{"MO_ENCODING"}) { $self->{"ENCODING"} = $self->{"MO_ENCODING"}; @@ -247,7 +247,7 @@ sub textdomain : method { return $DOMAIN; } -# _is_using_cache: Return whether we are using our cache. +# Return whether we are using our cache. sub _is_using_cache : method { local ($_, %_); my ($self, $mo_file, @stats, $mtime, $size); @@ -272,7 +272,7 @@ sub _is_using_cache : method { } } -# maketext: Encode after maketext +# Encode after maketext sub maketext : method { local ($_, %_); my ($self, $key, @param, $class, $keyd); @@ -320,25 +320,25 @@ sub maketext : method { return $_; } -# pmaketext: Maketext with context +# Maketext with context sub pmaketext : method { local ($_, %_); - my ($self, $ctxt, $key, @param); - ($self, $ctxt, $key, @param) = @_; + my ($self, $context, $key, @param); + ($self, $context, $key, @param) = @_; # This is not a static method - NOW return if ref($self) eq ""; # This is actually a wrapper to the maketext() method - return $self->maketext("$ctxt\x04$key", @param); + return $self->maketext("$context\x04$key", @param); } -# read_mo: Subroutine to read and parse the MO file -# Refer to gettext documentation section 8.3 +# Subroutine to read and parse the MO file +# Refer to gettext documentation section 8.3 sub read_mo($) { local ($_, %_); my ($mo_file, $len, $FH, $content, $tmpl); $mo_file = $_[0]; - # Avild being stupid + # Avoid being stupid return unless -f $mo_file && -r $mo_file; # Read the MO file $len = (stat $mo_file)[7]; @@ -397,7 +397,7 @@ sub read_mo($) { return %_; } -# reload_text: Method to purge the lexicon cache +# Method to purge the lexicon cache sub reload_text : method { local ($_, %_); @@ -408,7 +408,7 @@ sub reload_text : method { return; } -# fail_with: A wrapper to the fail_with() of Locale::Maketext, in order +# A wrapper to the fail_with() of Locale::Maketext, in order # to record the preferred failure handler of the user, so that # die_for_lookup_failures() knows where to return to. sub fail_with : method { @@ -434,7 +434,7 @@ sub fail_with : method { return exists $self->{"USERSET_FAIL"}? $self->{"USERSET_FAIL"}: undef; } -# die_for_lookup_failures: Whether we should die for lookup failure +# Whether we should die for lookup failure # The default is no. GNU gettext never fails. sub die_for_lookup_failures : method { local ($_, %_); @@ -464,7 +464,7 @@ sub die_for_lookup_failures : method { $self->{"DIE_FOR_LOOKUP_FAILURES"}: undef; } -# encode_failure: What to do if the text is out of your output encoding +# What to do if the text is out of your output encoding # Refer to Encode on possible values of this check sub encode_failure : method { local ($_, %_); @@ -482,9 +482,9 @@ sub encode_failure : method { return undef; } -# failure_handler_auto: Our local version of failure_handler_auto(), +# Our local version of failure_handler_auto(), # Copied and rewritten from Locale::Maketext, with bug#33938 patch applied. -# See http://rt.perl.org/rt3//Public/Bug/Display.html?id=33938 +# See https://github.com/Perl/perl5/issues/7767 sub failure_handler_auto : method { local ($_, %_); my ($self, $key, @param, $r); @@ -523,7 +523,6 @@ sub failure_handler_auto : method { s<\s+at\s+\(eval\s+\d+\)\s+line\s+(\d+)\.?\n?> <\n in bracket code [compiled line $1],>s; Carp::croak "Error in maketexting \"$key\":\n$_ as used"; - return; } # OK @@ -580,7 +579,7 @@ that follows the way GNU gettext works. It works seamlessly, I. As a result, you I -You start as an usual GNU gettext localization project: Work on +You start as a usual GNU gettext localization project: Work on PO files with the help of translators, reviewers and Emacs. Turn them into MO files with F. Copy them into the appropriate locale directory, such as @@ -615,7 +614,7 @@ returns the text message Cd according to the current C. Refer to L for the maketext plural notation. -=item $text = $LH->pmaketext($ctxt, $key, @param...) +=item $text = $LH->pmaketext($context, $key, @param...) Lookup the $key in a particular context in the current lexicon and return a translated message in the language of the user. Use @@ -651,7 +650,7 @@ be working. =item $LH->encode_failure(CHECK) Set the action when encode fails. This happens when the output text -is out of the scope of your output encoding. For exmaple, output +is out of the scope of your output encoding. For example, output Chinese into US-ASCII. Refer to L for the possible values of this C. The default is C, which is a safe choice that never fails. But part of your text may @@ -677,8 +676,8 @@ Purge the MO text cache. It purges the MO text cache from the base class Locale::Maketext::Gettext. The next time C is called, the MO file will be read and parse from the disk again. This is used when your MO file is updated, but you cannot shutdown and -restart the application. For example, when you are a co-hoster on a -mod_perl-enabled Apache, or when your mod_perl-enabled Apache is too +restart the application. For example, when you are a virtual host on +a mod_perl-enabled Apache, or when your mod_perl-enabled Apache is too vital to be restarted for every update of your MO file, or if you are running a vital daemon, such as an X display server. @@ -693,7 +692,7 @@ are running a vital daemon, such as an X display server. Read and parse the MO file. Returns the read %Lexicon. The returned lexicon is in its original encoding. -If you need the meta infomation of your MO file, parse the entry +If you need the meta information of your MO file, parse the entry C<$Lexicon{""}>. For example: /^Content-Type: text\/plain; charset=(.*)$/im; @@ -729,7 +728,7 @@ But, well, here comes Locale::Maketext::Gettext to rescue. With Locale::Maketext::Gettext, you can sit back and relax now, leaving all this mess to the excellent GNU gettext framework. -The idea of Locale::Maketext::Getttext came from +The idea of Locale::Maketext::Gettext came from L, a great work by Autrijus. But it has several problems at that time (version 0.16). I was first trying to write a wrapper to fix it, but finally @@ -760,7 +759,7 @@ text may be lost, as C does. If you do not like this C, change the failure behavior with the method C. -If you need the behavior of auto Traditional Chinese/Simplfied +If you need the behavior of auto Traditional Chinese/Simplified Chinese conversion, as GNU gettext smartly does, do it yourself with L, too. There may be a solution for this in the future, but not now. @@ -802,7 +801,7 @@ this problem by saving a copy of the current lexicon as an instance variable, and replacing the class lexicon with the current instance lexicon whenever it is changed by another language handle instance. But this involves large scaled memory copy, which affects the -proformance seriously. This is discouraged. You are adviced to use +performance seriously. This is discouraged. You are advised to use a single textdomain for a single localization class. The C is a workaround, not a solution. There is no @@ -834,7 +833,7 @@ L, L, L, L, L. Also, please refer to the official GNU -gettext manual at L. +gettext manual at L. =head1 AUTHOR @@ -842,7 +841,7 @@ imacat =head1 COPYRIGHT -Copyright (c) 2003-2019 imacat. All rights reserved. This program is free +Copyright (c) 2003-2021 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/lib/Locale/Maketext/Gettext/Functions.pm b/lib/Locale/Maketext/Gettext/Functions.pm index 658b6c8..accd98e 100644 --- a/lib/Locale/Maketext/Gettext/Functions.pm +++ b/lib/Locale/Maketext/Gettext/Functions.pm @@ -1,22 +1,22 @@ # Locale::Maketext::Gettext::Functions - Functional interface to Locale::Maketext::Gettext -# Copyright (c) 2003-2008 imacat. All rights reserved. This program is free +# Copyright (c) 2003-2021 imacat. All rights reserved. This program is free # software; you can redistribute it and/or modify it under the same terms # as Perl itself. -# First written: 2003-04-28 +# First written: 2003/4/28 package Locale::Maketext::Gettext::Functions; use 5.008; use strict; use warnings; use base qw(Exporter); -use vars qw($VERSION @EXPORT @EXPORT_OK); +our ($VERSION, @EXPORT, @EXPORT_OK); $VERSION = 0.13; -@EXPORT = qw(); -push @EXPORT, qw(bindtextdomain textdomain get_handle maketext __ N_); -push @EXPORT, qw(dmaketext pmaketext dpmaketext); -push @EXPORT, qw(reload_text read_mo encoding key_encoding encode_failure); -push @EXPORT, qw(die_for_lookup_failures); +@EXPORT = qw( +bindtextdomain textdomain get_handle maketext __ N_ +dmaketext pmaketext dpmaketext +reload_text read_mo encoding key_encoding encode_failure +die_for_lookup_failures); @EXPORT_OK = @EXPORT; # Prototype declaration sub bindtextdomain($;$); @@ -34,7 +34,7 @@ sub key_encoding(;$); sub encode_failure(;$); sub die_for_lookup_failures(;$); sub _declare_class($); -sub _catclass(@); +sub _cat_class(@); sub _init_textdomain($); sub _get_langs($$); sub _get_handle(); @@ -47,13 +47,13 @@ sub _lang($); use Encode qw(encode decode from_to FB_DEFAULT); use File::Spec::Functions qw(catdir catfile); use Locale::Maketext::Gettext qw(read_mo); -use vars qw(%LOCALEDIRS %RIDS %CLASSES %LANGS); -use vars qw(%LHS $_EMPTY $LH $DOMAIN $CATEGORY $CLASSBASE @LANGS %PARAMS); -use vars qw(@SYSTEM_LOCALEDIRS); +our (%LOCALEDIRS, %RIDS, %CLASSES, %LANGS); +our (%LHS, $_EMPTY, $LH, $DOMAIN, $CATEGORY, $BASE_CLASS, @LANGS, %PARAMS); +our (@SYSTEM_LOCALEDIRS); %LHS = qw(); # The category is always LC_MESSAGES $CATEGORY = "LC_MESSAGES"; -$CLASSBASE = "Locale::Maketext::Gettext::_runtime"; +$BASE_CLASS = "Locale::Maketext::Gettext::_runtime"; # Current language parameters @LANGS = qw(); @SYSTEM_LOCALEDIRS = @Locale::Maketext::Gettext::SYSTEM_LOCALEDIRS; @@ -62,12 +62,12 @@ $PARAMS{"KEY_ENCODING"} = "US-ASCII"; $PARAMS{"ENCODE_FAILURE"} = FB_DEFAULT; $PARAMS{"DIE_FOR_LOOKUP_FAILURES"} = 0; # Parameters for random class IDs -use vars qw($RID_LEN @RID_CHARS); +our ($RID_LEN, @RID_CHARS); $RID_LEN = 8; @RID_CHARS = split //, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -# bindtextdomain: Bind a text domain to a locale directory +# Bind a text domain to a locale directory sub bindtextdomain($;$) { local ($_, %_); my ($domain, $LOCALEDIR); @@ -85,7 +85,7 @@ sub bindtextdomain($;$) { return $LOCALEDIR; } -# textdomain: Set the current text domain +# Set the current text domain sub textdomain(;$) { local ($_, %_); my ($new_domain); @@ -101,7 +101,7 @@ sub textdomain(;$) { return $DOMAIN; } -# get_handle: Get a language handle +# Get a language handle sub get_handle(@) { local ($_, %_); # Register the current get_handle arguments @@ -110,13 +110,13 @@ sub get_handle(@) { return _get_handle(); } -# maketext: Maketext, in its long name +# Maketext, in its long name # Use @ instead of $@ in prototype, so that we can pass @_ to it. sub maketext(@) { return __($_[0], @_[1..$#_]); } -# __: Maketext, in its shortcut name +# Maketext, in its shortcut name # Use @ instead of $@ in prototype, so that we can pass @_ to it. sub __(@) { local ($_, %_); @@ -144,8 +144,8 @@ sub __(@) { return $_; } -# N_: Return the original text untouched, so that it can be catched -# with xgettext +# Return the original text untouched, so that it can be cached +# with xgettext # Use @ instead of $@ in prototype, so that we can pass @_ to it. sub N_(@) { # Watch out for this Perl magic! :p @@ -153,8 +153,8 @@ sub N_(@) { return @_; } -# dmaketext: Maketext in another text domain temporarily, -# an equivalent to dgettext(). +# Maketext in another text domain temporarily, +# an equivalent to dgettext(). sub dmaketext($$@) { local ($_, %_); my ($domain, $key, @param, $lh0, $domain0, $text); @@ -171,33 +171,33 @@ sub dmaketext($$@) { return $text; } -# pmaketext: Maketext with context, -# an equivalent to pgettext(). +# Maketext with context, +# an equivalent to pgettext(). sub pmaketext($$@) { local ($_, %_); - my ($ctxt, $key, @param); - ($ctxt, $key, @param) = @_; + my ($context, $key, @param); + ($context, $key, @param) = @_; # This is actually a wrapper to the maketext() function - return maketext("$ctxt\x04$key", @param); + return maketext("$context\x04$key", @param); } -# dpmaketext: Maketext with context in another text domain temporarily, -# an equivalent to dpgettext(). +# Maketext with context in another text domain temporarily, +# an equivalent to dpgettext(). sub dpmaketext($$$@) { local ($_, %_); - my ($domain, $ctxt, $key, @param); - ($domain, $ctxt, $key, @param) = @_; + my ($domain, $context, $key, @param); + ($domain, $context, $key, @param) = @_; # This is actually a wrapper to the dmaketext() function - return dmaketext($domain, "$ctxt\x04$key", @param); + return dmaketext($domain, "$context\x04$key", @param); } -# reload_text: Purge the lexicon cache +# Purge the lexicon cache sub reload_text() { # reload_text is static. Locale::Maketext::Gettext->reload_text; } -# encoding: Set the output encoding +# Set the output encoding sub encoding(;$) { local ($_, %_); $_ = $_[0]; @@ -216,7 +216,7 @@ sub encoding(;$) { return exists $PARAMS{"ENCODING"}? $PARAMS{"ENCODING"}: undef; } -# key_encoding: Set the encoding of the original text +# Set the encoding of the original text sub key_encoding(;$) { local ($_, %_); $_ = $_[0]; @@ -234,7 +234,7 @@ sub key_encoding(;$) { return exists $PARAMS{"KEY_ENCODING"}? $PARAMS{"KEY_ENCODING"}: undef; } -# encode_failure: What to do if the text is out of your output encoding +# What to do if the text is out of your output encoding # Refer to Encode on possible values of this check sub encode_failure(;$) { local ($_, %_); @@ -245,7 +245,7 @@ sub encode_failure(;$) { return $PARAMS{"ENCODE_FAILURE"}; } -# die_for_lookup_failures: Whether we should die for lookup failure +# Whether we should die for lookup failure # The default is no. GNU gettext never fails. sub die_for_lookup_failures(;$) { local ($_, %_); @@ -261,23 +261,23 @@ sub die_for_lookup_failures(;$) { return $PARAMS{"DIE_FOR_LOOKUP_FAILURES"}; } -# _declare_class: Declare a class +# Declare a class sub _declare_class($) { local ($_, %_); $_ = $_[0]; eval << "EOT"; package $_[0]; use base qw(Locale::Maketext::Gettext); -use vars qw(\@ISA %Lexicon); +our (\@ISA, %Lexicon); EOT } -# _catclass: Catenate the class name -sub _catclass(@) { +# Concatenate the class name +sub _cat_class(@) { return join("::", @_);; } -# _init_textdomain: Initialize a text domain +# Initialize a text domain sub _init_textdomain($) { local ($_, %_); my ($domain, $k, @langs, $langs); @@ -287,10 +287,10 @@ sub _init_textdomain($) { return if !defined $domain; # Obtain the available locales - # A binded domain + # A bound domain if (exists $LOCALEDIRS{$domain}) { @langs = _get_langs($LOCALEDIRS{$domain}, $domain); - # Not binded + # Not bound } else { @langs = qw(); # Search the system locale directories @@ -322,22 +322,22 @@ sub _init_textdomain($) { # Get a new class ID $rid = _new_rid(); # Obtain the class name - $class = _catclass($CLASSBASE, $rid); + $class = _cat_class($BASE_CLASS, $rid); # Register the domain with this class $CLASSES{$k} = $class; # Declare this class _declare_class($class); # Declare its language subclasses - _declare_class(_catclass($class, $_)) + _declare_class(_cat_class($class, $_)) foreach @langs; return; } -# _get_langs: Search a locale directory and return the available languages +# Search a locale directory and return the available languages sub _get_langs($$) { local ($_, %_); - my ($dir, $domain, $DH, $entry, $MOfile); + my ($dir, $domain, $DH, $entry, $MO_file); ($dir, $domain) = @_; @_ = qw(); @@ -351,9 +351,9 @@ sub _get_langs($$) { # Skip locales with dot "." (trailing encoding) next if $entry =~ /\./; # Get the MO file name - $MOfile = catfile($dir, $entry, $CATEGORY, "$domain.mo"); + $MO_file = catfile($dir, $entry, $CATEGORY, "$domain.mo"); # Skip if MO file is not available for this locale - next if ! -f $MOfile && ! -r $MOfile; + next if ! -f $MO_file && ! -r $MO_file; # Map C to i_default $entry = "i_default" if $entry eq "C"; # Add this language @@ -364,12 +364,12 @@ sub _get_langs($$) { return @_; } -# _get_handle: Set the language handle with the current DOMAIN and @LANGS +# Set the language handle with the current DOMAIN and @LANGS sub _get_handle() { local ($_, %_); my ($k, $class, $subclass); - # Lexicon empty if text domain not specified, or not binded yet + # Lexicon empty if text domain not specified, or not bound yet return _get_empty_handle if !defined $DOMAIN || !exists $LOCALEDIRS{$DOMAIN}; # Obtain the registry key $k = _k($DOMAIN); @@ -402,7 +402,7 @@ sub _get_handle() { # Initialize it $LH->bindtextdomain($DOMAIN, $LOCALEDIRS{$DOMAIN}); $LH->textdomain($DOMAIN); - # Respect the MO file encoding unless there is a user preferrence + # Respect the MO file encoding unless there is a user preference if (!exists $PARAMS{"USERSET_ENCODING"}) { if (exists $LH->{"MO_ENCODING"}) { $PARAMS{"ENCODING"} = $LH->{"MO_ENCODING"}; @@ -419,7 +419,7 @@ sub _get_handle() { return _lang($LH); } -# _get_empty_handle: Obtain the empty language handle +# Obtain the empty language handle sub _get_empty_handle() { local ($_, %_); if (!defined $_EMPTY) { @@ -432,7 +432,7 @@ sub _get_empty_handle() { return _lang($LH); } -# _reset: Initialize everything +# Initialize everything sub _reset() { local ($_, %_); @@ -448,7 +448,7 @@ sub _reset() { return; } -# _new_rid: Generate a new random ID +# Generate a new random ID sub _new_rid() { local ($_, %_); my ($id); @@ -463,12 +463,12 @@ sub _new_rid() { return $id; } -# _k: Build the key for the domain registry +# Build the key for the domain registry sub _k($) { return join "\n", $LOCALEDIRS{$_[0]}, $CATEGORY, $_[0]; } -# _lang: The langage from a language handle. language_tag is not quite sane. +# The language from a language handle. language_tag is not quite sane. sub _lang($) { local ($_, %_); $_ = $_[0]; @@ -484,16 +484,14 @@ use 5.008; use strict; use warnings; use base qw(Locale::Maketext::Gettext); -use vars qw($VERSION @ISA %Lexicon); -$VERSION = 0.01; +our $VERSION = 0.01; package Locale::Maketext::Gettext::Functions::_EMPTY::i_default; use 5.008; use strict; use warnings; use base qw(Locale::Maketext::Gettext); -use vars qw($VERSION @ISA %Lexicon); -$VERSION = 0.01; +our $VERSION = 0.01; return 1; @@ -557,7 +555,7 @@ C. Attempts to translate a text message into the native language of the user, by looking up the translation in an MO lexicon file. Refer to L for the C plural -grammer. +grammar. =item $message = __($key, @param...) @@ -567,7 +565,7 @@ that it is cleaner when you employ maketext to your existing project. =item ($key, @param...) = N_($key, @param...) Returns the original text untouched. This is to enable the text be -catched with xgettext. +caught with xgettext. =item $message = dmaketext($domain, $key, @param...) @@ -575,13 +573,13 @@ Temporarily switch to another text domain and attempts to translate a text message into the native language of the user in that text domain. Use "--keyword=dmaketext:2" for the xgettext utility. -=item $message = pmaketext($ctxt, $key, @param...) +=item $message = pmaketext($context, $key, @param...) Attempts to translate a text message in a particular context into the native language of the user. Use "--keyword=pmaketext:1c,2" for the xgettext utility. -=item $message = dpmaketext($domain, $ctxt, $key, @param...) +=item $message = dpmaketext($domain, $context, $key, @param...) Temporarily switch to another text domain and attempts to translate a text message in a particular context into the native language of @@ -613,7 +611,7 @@ be working. =item encode_failure(CHECK) Set the action when encode fails. This happens when the output text -is out of the scope of your output encoding. For exmaple, output +is out of the scope of your output encoding. For example, output Chinese into US-ASCII. Refer to L for the possible values of this C. The default is C, which is a safe choice that never fails. But part of your text may @@ -635,17 +633,17 @@ are read and parsed from the disk, to reduce I/O and parsing overhead on busy sites. reload_text() purges this cache, so that updated MO files can take effect at run-time. This is used when your MO file is updated, but you cannot shutdown and restart the application. for -example, when you are a co-hoster on a mod_perl-enabled Apache, or +example, when you are a virtual host on a mod_perl-enabled Apache, or when your mod_perl-enabled Apache is too vital to be restarted for every update of your MO file, or if you are running a vital daemon, such as an X display server. -=item %Lexicon = read_mo($MOfile) +=item %Lexicon = read_mo($MO_file) Read and parse the MO file. Returns the read %Lexicon. The returned lexicon is in its original encoding. -If you need the meta infomation of your MO file, parse the entry +If you need the meta information of your MO file, parse the entry C<$Lexicon{""}>. For example: /^Content-Type: text\/plain; charset=(.*)$/im; @@ -766,7 +764,7 @@ L, L, L, L. Also, please refer to the official GNU gettext manual at -L. +L. =head1 AUTHOR @@ -774,7 +772,7 @@ imacat =head1 COPYRIGHT -Copyright (c) 2003-2008 imacat. All rights reserved. This program is free +Copyright (c) 2003-2021 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/script/maketext b/script/maketext old mode 100755 new mode 100644 index 5015898..eb427e2 --- a/script/maketext +++ b/script/maketext @@ -1,31 +1,30 @@ #! /usr/bin/perl -w # Command-line interface to Locale::Maketext::Gettext (and Locale::Maketext) -# Copyright (c) 2003-2007 imacat. All rights reserved. This program is free +# Copyright (c) 2003-2021 imacat. All rights reserved. This program is free # software; you can redistribute it and/or modify it under the same terms # as Perl itself. -# First written: 2003-05-03 +# First written: 2003/5/3 use 5.008; use strict; use warnings; use Getopt::Long qw(GetOptions); use Locale::Maketext::Gettext::Functions; -use vars qw($VERSION); -$VERSION = 0.05; +our $VERSION = 0.05; # Prototype declaration sub main(); sub parse_args(); -use vars qw($THIS_FILE $SHORTHELP $VERSTR $SEARCH $HELP); +our ($THIS_FILE, $SHORT_HELP, $VER_STR, $SEARCH, $HELP); $THIS_FILE = $0; $THIS_FILE =~ s/^.*\///; -$SHORTHELP = "Try `$THIS_FILE --help' for more information."; -$VERSTR = "$THIS_FILE v$VERSION by imacat "; +$SHORT_HELP = "Try `$THIS_FILE --help' for more information."; +$VER_STR = "$THIS_FILE v$VERSION by imacat "; $SEARCH = join " ", @Locale::Maketext::Gettext::Functions::SYSTEM_LOCALEDIRS; $HELP = << "EOT"; Usage: maketext [OPTION] [--domain=TEXTDOMAIN] MSGKEY [PARAM...] -or: maketext [OPTION] -s MSGID [PARAM...] +or: maketext [OPTION] -s MSGKEY [PARAM...] Maketext and display native language translation of a textual message. @@ -46,14 +45,14 @@ Standard search directories: $SEARCH Report bugs to . EOT -use vars qw($DOMAIN $LOCALEDIR $ECHO $KEY @PARAM); +our ($DOMAIN, $LOCALEDIR, $ECHO, $KEY, @PARAM); $ECHO = 0; # Main program main(); exit 0; -# main: Main program +# Main program sub main() { local ($_, %_); @@ -69,18 +68,18 @@ sub main() { return; } -# parse_args: Parse the arguments +# Parse the arguments sub parse_args() { local ($_, %_); - # Get the arguments ¨ú±o°Ñ¼Æ + # Get the arguments $_ = eval { local $SIG{__WARN__} = sub { die $_[0]; }; Getopt::Long::Configure("no_auto_abbrev"); GetOptions( "domain|d=s"=>\$DOMAIN, "s"=>sub { $ECHO = 1; }, "help|h"=>sub { print $HELP; exit 0; }, - "version|V"=>sub { print "$VERSTR\n"; exit 0; }); + "version|V"=>sub { print "$VER_STR\n"; exit 0; }); return 1; }; die "$THIS_FILE: $@" if !defined $_; @@ -108,7 +107,7 @@ maketext - translate and make messages =head1 SYNOPSIS maketext [OPTION] [--domain=TEXTDOMAIN] MSGKEY [PARAM...] - maketext [OPTION] -s MSGID [PARAM...] + maketext [OPTION] -s MSGKEY [PARAM...] =head1 DESCRIPTION @@ -174,7 +173,7 @@ parameter is not given. =item TEXTDOMAINDIR -TEXTDOMAINDIR is used to search the message catelog/MO file if it +TEXTDOMAINDIR is used to search the message catalog/MO file if it does not reside in the system locale directories. =back @@ -200,7 +199,7 @@ L, L, L, L. Also, please refer to the official GNU gettext manual at -L. +L. =head1 AUTHOR @@ -208,7 +207,7 @@ imacat =head1 COPYRIGHT -Copyright (c) 2003-2007 imacat. All rights reserved. This program is free +Copyright (c) 2003-2021 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/t/11-command-line.t b/t/11-command-line.t index 735ce61..6d6094a 100755 --- a/t/11-command-line.t +++ b/t/11-command-line.t @@ -14,7 +14,7 @@ BEGIN { plan tests => 10 } use FindBin; use File::Spec::Functions qw(catdir catfile updir); use lib $FindBin::Bin; -use vars qw($LOCALEDIR $r $maketext); +our ($LOCALEDIR, $r, $maketext); $LOCALEDIR = catdir($FindBin::Bin, "locale"); $maketext = catdir($FindBin::Bin, updir, "blib", "script", "maketext"); diff --git a/t/12-cache.t b/t/12-cache.t index e7c97f4..78d94cb 100755 --- a/t/12-cache.t +++ b/t/12-cache.t @@ -1,6 +1,6 @@ #! /usr/bin/perl -w # Basic test suite -# Copyright (c) 2019 imacat. All rights reserved. This program is free +# Copyright (c) 2019-2021 imacat. All rights reserved. This program is free # software; you can redistribute it and/or modify it under the same terms # as Perl itself. @@ -14,7 +14,7 @@ BEGIN { plan tests => 4 } use FindBin; use File::Spec::Functions qw(catdir catfile); use lib $FindBin::Bin; -use vars qw($LOCALEDIR $r); +our ($LOCALEDIR, $r); $LOCALEDIR = catdir($FindBin::Bin, "locale"); # bindtextdomain @@ -42,7 +42,6 @@ $r = eval { $_->bindtextdomain("test-cache", $LOCALEDIR); $_->textdomain("test-cache"); $_[0] = $_->maketext("Hello, world!"); - my %Lexicon = %{$_->{"Lexicon"}}; # Update the file but keep the size and mtime open $FH, "+<$mo_file1" or die "$mo_file1: $!";