Skip to content

Commit

Permalink
Use locale pragma instead of POSIX::setlocale()
Browse files Browse the repository at this point in the history
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 `Language-Team` header in the project localization packages
in `po` directory to `Sqitch Hackers <sqitch-hackers@googlegroups.com>`.

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
theory committed Jan 7, 2024
1 parent 7edc536 commit 52d9d8d
Show file tree
Hide file tree
Showing 33 changed files with 182 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cockroach.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- name: Start CockroachDB
run: docker run -d -p 26257:26257 cockroachdb/cockroach:latest-v${{ matrix.version }} start-single-node --insecure
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: rm -rf /opt/hostedtoolcache
- name: Start CockroachDB
run: docker run -d -p 26257:26257 cockroachdb/cockroach:latest start-single-node --insecure
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/exasol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
ports: [ 8563 ]
options: --privileged
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/exasol.sh
- name: Setup Perl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/firebird.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
ISC_PASSWORD: nix
FIREBIRD_DATABASE: sqitchtest.db
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/firebird.sh
- name: Setup Perl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
ports: [ 3306 ]
options: --health-cmd="healthcheck.sh --innodb_initialized || mysqladmin ping --protocol=tcp" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/mysql.sh
- name: Setup Perl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
--health-timeout 10s
--health-retries 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/oracle.sh
- name: Setup Perl
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ jobs:
strategy:
matrix:
include:
- { icon: 🐧, os: ubuntu, name: Linux }
- { icon: 🍎, os: macos, name: macOS }
- { icon: 🪟, os: windows, name: Windows }
- { icon: 🐧, on: ubuntu, name: Linux }
- { icon: 🍎, on: macos, name: macOS }
- { icon: 🪟, on: windows, name: Windows }
name: ${{ matrix.icon }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.on }}-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
with: { perl-version: latest }
- run: perl -V
- if: runner.os == 'Linux'
name: Install Apt Packages
run: sudo apt-get install -qq aspell-en language-pack-fr language-pack-en language-pack-de language-pack-it
- name: Cache CPAN Modules
uses: actions/cache@v3
with:
path: local
key: perl-${{ steps.perl.outputs.perl-hash }}
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends ExtUtils::MakeMaker List::MoreUtils::XS
# Remove Locale::TextDomain if https://github.com/gflohr/libintl-perl/issues/7 fixed and released.
- if: ${{ matrix.os == 'windows' }}
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::Locale Win32::ShellQuote DateTime::TimeZone::Local::Win32 Locale::TextDomain@1.31
- if: runner.os == 'Windows'
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::ShellQuote DateTime::TimeZone::Local::Win32
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends --cpanfile dist/cpanfile
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Test::Spelling Test::Pod Test::Pod::Coverage
- name: prove
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/perl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ jobs:
name: 🧅 Perl ${{ matrix.perl }} on ${{ matrix.os[0] }} ${{ matrix.os[1] }}
runs-on: ${{ matrix.os[1] }}-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
with: { perl-version: "${{ matrix.perl }}" }
- run: perl -V
- if: runner.os == 'Linux'
name: Install Apt Packages
run: sudo apt-get install -qq language-pack-fr language-pack-en language-pack-de language-pack-it
- name: Cache CPAN Modules
uses: actions/cache@v3
with:
path: local
key: perl-${{ steps.perl.outputs.perl-hash }}
# Remove Locale::TextDomain if https://github.com/gflohr/libintl-perl/issues/7 fixed and released.
- if: ${{ matrix.os[1] == 'windows' }}
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::Locale Win32::ShellQuote DateTime::TimeZone::Local::Win32 Locale::TextDomain@1.31
- if: runner.os == 'Windows'
run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Encode Win32::Console::ANSI Win32API::Net Win32::ShellQuote DateTime::TimeZone::Local::Win32
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends --cpanfile dist/cpanfile
- run: cpm install --verbose --show-build-log-on-failure --no-test --with-recommends Test::Spelling Test::Pod Test::Pod::Coverage
- name: prove
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: 🐘 Postgres ${{ matrix.pg }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: ❄️ Snowflake
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/snowflake.sh
- name: Setup Perl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: 💡 SQLite ${{ matrix.sqlite }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vertica.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
image: ${{ matrix.image }}:${{ matrix.version }}
ports: [ 5433 ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Clients
run: .github/ubuntu/vertica.sh
- name: Setup Perl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yugabyte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: jameshartig/yugabyte-db-action@master
with:
yb_image_tag: "${{ matrix.tag }}"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Perl
id: perl
uses: shogo82148/actions-setup-perl@v1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
/_rpmbuild
/target
.build/
*.mo
.al
/latest_changes.md
/local/
/LocaleData/
/lib/LocaleData/
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Revision history for Perl extension App::Sqitch
(#795)!
- Fixed Oracle and Firebird test failures due to incorrect use of `chmod`.
Thanks to Slaven Rezić for the report and the fix (#807)!
- Updated the locale configuration to fix issues in more recent versions
of Perl, and added tests to ensure that the sqitch CLI executes and
properly emits localized messages (except on Windows, where the language
codes are incompatible). Eliminated use of Win32::Locale.

1.4.0 2023-08-01T23:37:30Z
- Fixed Snowflake warehouse and role setup to properly quote identifiers
Expand Down
11 changes: 1 addition & 10 deletions bin/sqitch
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;
2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = App-Sqitch
license = MIT
copyright_holder = "iovation Inc., David E. Wheeler"
copyright_year = 2012-2023
version = v1.4.1-dev
version = v1.4.1

[GatherDir]
exclude_filename = dist/cpanfile
Expand Down
1 change: 0 additions & 1 deletion inc/Module/Build/Sqitch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ sub new {
Win32::Console::ANSI
Win32API::Net
);
$p{requires}{'Win32::Locale'} = 0;
$p{requires}{'Win32::ShellQuote'} = 0;
$p{requires}{'DateTime::TimeZone::Local::Win32'} = 0;
}
Expand Down
10 changes: 3 additions & 7 deletions lib/App/Sqitch/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use utf8;
use parent 'DateTime';
use DateTime 1.04;
use Locale::TextDomain qw(App-Sqitch);
use POSIX ();

use App::Sqitch::X qw(hurl);
use List::Util qw(first);
use constant ISWIN => $^O eq 'MSWin32';
Expand Down Expand Up @@ -57,13 +59,7 @@ sub as_string {
s/\+0000$/-0000/;
return $rv;
} else {
if (ISWIN) {
require Win32::Locale;
$dt->set_locale( Win32::Locale::get_locale() );
} else {
require POSIX;
$dt->set_locale( POSIX::setlocale( POSIX::LC_TIME() ) );
}
$dt->set_locale( POSIX::setlocale( POSIX::LC_TIME() ) );
return $dt->format_cldr($format) if $format =~ s/^cldr://;
return $dt->strftime($format) if $format =~ s/^strftime://;
my $meth = $dt->locale->can("datetime_format_$format") or hurl(
Expand Down
2 changes: 1 addition & 1 deletion po/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
"POT-Creation-Date: 2023-07-30 20:02-0400\n"
"PO-Revision-Date: 2012-08-31 17:15-0700\n"
"Last-Translator: Thomas Iguchi <ti@nobu-games.com>\n"
"Language-Team: German <david@justatheory.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
2 changes: 1 addition & 1 deletion po/fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
"POT-Creation-Date: 2023-07-30 20:02-0400\n"
"PO-Revision-Date: 2012-10-12 11:28-0700\n"
"Last-Translator: Arnaud Assad <arhuman@gmail.com>\n"
"Language-Team: French <arhuman@gmail.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
2 changes: 1 addition & 1 deletion po/it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
"POT-Creation-Date: 2023-07-30 20:02-0400\n"
"PO-Revision-Date: 2017-10-12 10:30+0200\n"
"Last-Translator: Luca Ferrari <fluca1978@gmail.com>\n"
"Language-Team: Italian <fluca1978@gmail.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language: it_IT\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
10 changes: 3 additions & 7 deletions t/lib/LC.pm
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package LC;
use POSIX;

our $TIME = do {
if ($^O eq 'MSWin32') {
require Win32::Locale;
Win32::Locale::get_locale();
} else {
require POSIX;
POSIX::setlocale( POSIX::LC_TIME() );
}
require POSIX;
POSIX::setlocale( POSIX::LC_TIME );
};

# https://github.com/sqitchers/sqitch/issues/230#issuecomment-103946451
Expand Down
10 changes: 1 addition & 9 deletions t/sqitch
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#!/usr/bin/env perl -CAS

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 FindBin;
use lib "$FindBin::Bin/../lib";
use App::Sqitch;
Expand Down
Binary file added xt/locale/LocaleData/de_DE/LC_MESSAGES/App-Sqitch.mo
Binary file not shown.
Binary file added xt/locale/LocaleData/fr_FR/LC_MESSAGES/App-Sqitch.mo
Binary file not shown.
Binary file added xt/locale/LocaleData/it_IT/LC_MESSAGES/App-Sqitch.mo
Binary file not shown.
43 changes: 43 additions & 0 deletions xt/locale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
```

For errors where it can't find `msgformat` 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/
12 changes: 12 additions & 0 deletions xt/locale/po/de_DE.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Language: de\n"
"Project-Id-Version: Sqitch 1.4.1\n"
"PO-Revision-Date: 22024-01-06T21:10:06Z\n"
"Last-Translator: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "\"{command}\" is not a valid command"
msgstr "\"{command}\" ist ein ungültiger Befehl"
12 changes: 12 additions & 0 deletions xt/locale/po/fr_FR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Language: fr\n"
"Project-Id-Version: Sqitch 1.4.1\n"
"PO-Revision-Date: 22024-01-06T21:10:06Z\n"
"Last-Translator: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "\"{command}\" is not a valid command"
msgstr "\"{command}\" n'est pas une commande valide"
12 changes: 12 additions & 0 deletions xt/locale/po/it_IT.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Language: it\n"
"Project-Id-Version: Sqitch 1.4.1\n"
"PO-Revision-Date: 22024-01-06T21:10:06Z\n"
"Last-Translator: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"Language-Team: Sqitch Hackers <sqitch-hackers@googlegroups.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "\"{command}\" is not a valid command"
msgstr "\"{command}\" non è un comando valido"
Loading

0 comments on commit 52d9d8d

Please sign in to comment.