add gettext support

This commit is contained in:
crazywhalecc
2024-02-16 01:28:10 +08:00
parent 9777c9aa93
commit 05e3898e7a
13 changed files with 131 additions and 5 deletions

BIN
src/globals/objs/test.mo Normal file

Binary file not shown.

View File

@@ -13,7 +13,7 @@ declare(strict_types=1);
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'event',
'Linux', 'Darwin' => 'gettext',
'Windows' => 'mbstring,openssl',
};

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
assert(function_exists('gettext'));
assert(function_exists('bindtextdomain'));
assert(function_exists('bind_textdomain_codeset'));
if (!is_dir('locale/en_US/LC_MESSAGES/')) {
mkdir('locale/en_US/LC_MESSAGES/', 0755, true);
}
if (!file_exists('locale/en_US/LC_MESSAGES/test.mo')) {
file_put_contents('locale/en_US/LC_MESSAGES/test.mo', file_get_contents(__DIR__ . '/../objs/test.mo'));
}
putenv('LANG=en_US');
setlocale(LC_ALL, 'en_US');
$domain = 'test';
bindtextdomain($domain, 'locale/');
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
assert(gettext('示例') === 'Example');