-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use locale pragma instead of POSIX::set_locale()
The Pragma is more likely to do the right thing, as confirmed by new tests, which fail when using `setlocale` and now succeed with `use locale`. The tests, in `xt/locale`, include compiled locale dictionaries (`*.mo` files) with a single message for the tested languages. This is in contrast to the released locale dictionaries, which are generated at release time but not stored in the repository. Update the `os.yml` and `perl.yml` workflows, which run all tests including the new locale tests, to install the required locales on Linux and to set the full `runs-on:` image name in the matrix (in response to shogo82148/actions-setup-perl#1699). Also remove the installation of an older version of Locale::TextDomain from those workflows, since gflohr/libintl-perl#7 has been fixed and released. While at it, upgrade to `actions/checkout@v4` in all workflows and use `runner.os` instead of `matrix.os` in conditionals.
- Loading branch information
Showing
26 changed files
with
136 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
/_rpmbuild | ||
/target | ||
.build/ | ||
*.mo | ||
.al | ||
/latest_changes.md | ||
/local/ | ||
/LocaleData/ | ||
/lib/LocaleData/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
#!perl -w -CAS | ||
|
||
# VERSION | ||
use POSIX qw(setlocale); | ||
BEGIN { | ||
if ($^O eq 'MSWin32') { | ||
require Win32::Locale; | ||
setlocale POSIX::LC_ALL, Win32::Locale::get_locale(); | ||
} else { | ||
setlocale POSIX::LC_ALL, ''; | ||
} | ||
} | ||
use locale; | ||
use App::Sqitch; | ||
|
||
exit App::Sqitch->go; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Sqitch Locale Test | ||
================== | ||
|
||
This directory contains the files necessary to test the Sqitch CLI to ensure it | ||
properly detects locale settings and emits translated messages. The | ||
[`po` directory here](./po/), unlike the canonical translations in the root `po` | ||
directory, contains only a few languages translating a single message: | ||
|
||
``` | ||
"{command}" is not a valid command | ||
``` | ||
|
||
The `LocaleData` directory contains the compiled forms of these dictionaries, | ||
and unlike the main dictionaries, these are committed to the repository. This | ||
allows the [OS](.github/workflows/os.yml) and [Perl](.github/workflows/os.yml) | ||
workflows to run without the overhead of compiling them (a PITA since `gettext` | ||
is hard to get on Windows and Dist::Zilla supports only more recent versions of | ||
Perl). If the messages need to change, recompile the dictionaries with these | ||
commands: | ||
|
||
```sh | ||
cpanm Dist::Zilla --notest | ||
dzil authordeps --missing | cpanm --notest | ||
dzil msg-compile -d xt/locale xt/locale/po/*.po | ||
``` | ||
|
||
It's safe to ignore the warnings from `msg-compile`, as long as each translates | ||
a single message. For errors where it can't find `msgforat` or `gettext`, be | ||
sure that [gettext] is installed (readily available via `apt-get`, `yum`, or | ||
`brew`). | ||
|
||
Now run the test, which validates the output from [`bin/sqitch`](bin/sqitch): | ||
|
||
```sh | ||
prove -lv xt/locale/test-cli.t | ||
``` | ||
|
||
If tests fail, be sure each of the locales is installed on your system. | ||
Apt-based systems, for example, require the relevant language packs: | ||
|
||
```sh | ||
sudo apt-get install -qq language-pack-fr language-pack-en language-pack-de language-pack-it | ||
``` | ||
|
||
[gettext]: https://www.gnu.org/software/gettext/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
msgid "" | ||
msgstr "" | ||
"Language: de\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
msgid "\"{command}\" is not a valid command" | ||
msgstr "\"{command}\" ist ein ungültiger Befehl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
msgid "" | ||
msgstr "" | ||
"Language: fr\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
msgid "\"{command}\" is not a valid command" | ||
msgstr "\"{command}\" n'est pas une commande valide" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
msgid "" | ||
msgstr "" | ||
"Language: it\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
msgid "\"{command}\" is not a valid command" | ||
msgstr "\"{command}\" non è un comando valido" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/perl -w | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More tests => 4; | ||
use File::Spec; | ||
use Capture::Tiny qw(:all); | ||
|
||
# Requires xt/locale/LocaleData; see xt/lcoale/README.md for details. | ||
my @cli = (qw(-Ilib -CAS -Ixt/locale), File::Spec->catfile(qw(bin sqitch))); | ||
|
||
# Each locale must be installed on the local system. Adding a new lang? Also add | ||
# the relevant language-pack-XX package to os.yml and perl.yml. | ||
for my $tc ( | ||
{ lang => 'en_US', err => q{"nonesuch" is not a valid command} }, | ||
{ lang => 'fr_FR', err => q{"nonesuch" n'est pas une commande valide} }, | ||
{ lang => 'de_DE', err => q{"nonesuch" ist ein ungültiger Befehl} }, | ||
{ lang => 'it_IT', err => q{"nonesuch" non è un comando valido} }, | ||
) { | ||
subtest $tc->{lang} || 'default' => sub { | ||
local $ENV{LC_ALL} = "$tc->{lang}.UTF-8"; | ||
|
||
# Test successful run. | ||
my ($stdout, $stderr, $exit) = capture { system $^X, @cli, 'help' }; | ||
is $exit >> 8, 0, 'Should have exited normally'; | ||
like $stdout, qr/\AUsage\b/, 'Should have usage statement in STDOUT'; | ||
is $stderr, '', 'Should have no STDERR'; | ||
|
||
# Test localized error. | ||
($stdout, $stderr, $exit) = capture { system $^X, @cli, 'nonesuch' }; | ||
is $exit >> 8, 2, 'Should have exit val 2'; | ||
is $stdout, '', 'Should have no STDOUT'; | ||
like $stderr, qr/\A\Q$tc->{err}/, | ||
'Should have localized error message in STDERR'; | ||
}; | ||
} |