gnucash-htdocs master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sun Jun 29 23:26:08 EDT 2025
Updated via https://github.com/Gnucash/gnucash-htdocs/commit/9d2412cf (commit)
via https://github.com/Gnucash/gnucash-htdocs/commit/5a48589b (commit)
from https://github.com/Gnucash/gnucash-htdocs/commit/9ec702b0 (commit)
commit 9d2412cf57600ef10977a8285e3b975825a3d5bf
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Jun 29 19:48:19 2025 -0700
Announce release of GnuCash 5.12
diff --git a/externals/global_params.php b/externals/global_params.php
index aea65e9..be3f81e 100644
--- a/externals/global_params.php
+++ b/externals/global_params.php
@@ -6,15 +6,15 @@
$major_stable ="5";
// TODO: on major_stable 5 in download.phtml copy from $old_stable into the historical
// section: last_win7 and $last_mac_sierra
- $minor_stable ="11";
+ $minor_stable ="12";
// Number of Translations: Did we add or dropped some?
define("PROG_TRANSLATIONS", 61);
$latest_stable = $major_stable.".".$minor_stable;
$latest_stable_win = $latest_stable;
//$latest_stable_win = $latest_stable."-1";
- $latest_stable_mac_arm = $latest_stable."-2";
- $latest_stable_mac_x86 = $latest_stable."-2";
+ $latest_stable_mac_arm = $latest_stable."-1";
+ $latest_stable_mac_x86 = $latest_stable."-1";
// Change this when there has been a re-tag to add the re-tag letter,
// e.g. if one retagged 2.6.13 to 2.6.13a, make $tarball = $latest_stable."a".
$tarball = $latest_stable."";
diff --git a/news/250629-5.12.news b/news/250629-5.12.news
new file mode 100644
index 0000000..1bc4793
--- /dev/null
+++ b/news/250629-5.12.news
@@ -0,0 +1,127 @@
+<b>Announcement:</b> GnuCash 5.12 Released
+2025-06-29
+
+<h2>GnuCash 5.12 Released</h2>
+
+<p>The GnuCash development team announces GnuCash 5.12, the thirteenth release in the stable 5.x series.</p>
+
+<h4>Between 5.11 and 5.12, the following bugfixes were accomplished:</h4>
+<ul>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=648768">Bug 648768 - Warning "Change Reconciled Split" has wrong cursor focus</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=797766">Bug 797766 - Automatic decimal point doesn't work properly with zeros when entering stocks.</a><p> Preserve the decimal point when printing numbers with no decimal places to stop the auto-decimal code from triggering when exiting the field. </p></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799490">Bug 799490 - Error on start or opening a gnucash file: Can't parse the URL</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799506">Bug 799506 - reconcile bad date pops to 1969</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799521">Bug 799521 - Segmentation fault on Autocomplete of Description with Ã</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799572">Bug 799572 - Return proper status code when Finance::Quote errors during price quote retrieval via CLI. </li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799580">Bug 799580 - Swiss currency symbol is displayed as SFr. instead of CHF</a><p>Replace SFr. with Fr. as SFr. is obsolete but Fr. is still widely used. This is the local symbol so users who want CHF can set it in the security editor. </p></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799582">Bug 799582 - Mortgage and Loan Assistant - Compounding Formula</a><p>Adds a semi-annual compounding period for Canadians and implements the more correct simple-rate formula provided by a Canadian licensed accountant. Also adds support for day-interval loan payments, ensures that the formula on the repayment page reflects changes on that page, ensures that the number and amounts of payments are correct when payments are more frequent than monthly, use the correct intest rate for compunding calculations, and fixes some memory issues.</p></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799590">Bug 799590 - Pressing enter after changing date on initial reconcile information window does not change ending balance.</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799592">Bug 799592 - "No transactions found" when importing CSV transactions</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799593">Bug 799593 - macOS: mariadb hardcodes plugin paths to original install directory.</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799594">Bug 799594 - GnuCash 5.11 fails to build with boost 1.88</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799597">Bug 799597 - Crash when deleting all splits in General Journal</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799602">Bug 799602 - Unit Price on Invoice will NOT display as decimals</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799603">Bug 799603 - Does not save to mysql on localhost.</a></li>
+ <li><a href="https://bugs.gnucash.org/show_bug.cgi?id=799623">Bug 799623 - test-backend-dbi fails after 2038</a></li>
+</ul>
+
+<h4>The following fixes and improvements were not associated with bug reports:</h4>
+<ul>
+ <li>[reports]Lazily generate sub-reports. Reports with links to detail sub-reports like the budget reports would take a long time to generate because they built both the main report and all of the sub-reports. Now the sub-reports generate when the user clicks the link in the main report.</li>
+ <li>Security editor quote sources: Add new source, China Merchants Bank. Remove no longer supported F::Q Modules Bloomberg.pm, DWSFunds, Investor's Exchange (U.S.), Morningstar Australia, Skanddinaviska Enskilda Banken, Tiaacref.pm, Troweprice.pm and many of the multi-source sources from the Security Editor.</li>
+ <li>[import-main-matcher.cpp] Add tooltips to transaction A, U+C, and C action columns in the generic transaction import matcher. </li>
+ <li>[reports] Use ICU for Unicode string comparison and substring search because it knows how to correctly localize comparisons of accented and unaccented characters.</li>
+ <li>[reports] more robust error handling if target report doesn't exist.</li>
+ <li>Register: Ensure splits belong to transaction when doing bulk operations on a transaction's splits.</li>
+ <li>Drop the definition of __EXTENSIONS__ from three files and instead move it to compiler options if on a platform that needs it.</li>
+ <li>Avoid non-POSIX "echo -n" behavior in util/gnc-vcs-info.</li>
+ <li>Add testbuild target which builds tests without running them to accommodate packaging processes that run ctest separately.</li>
+ <li>[engine.i] convert gnc_account_accumulate_at_dates to c++.</li>
+ <li>[gnc-engine-guile.cpp] helper gnc_split_to_scm function.</li>
+ <li>[gnc-engine-guile] reduce overhead of gnc_foo_to_scm by caching the result of SWIG_TypeQuery(typestr) </li>
+ <li>[balance-forecast] optimise some loops: fewer temporary lists and gc </li>
+ <li>Let cmake probe for the existence of HAVE_STRUCT_TM_GMTOFF, fix build of test-gnc-date on systems without HAVE_STRUCT_TM_GMTOFF, and avoid unused variable warnings on systems without HAVE_STRUCT_TM_GMTOFF</li>
+ <li>Wrap include of gtest.h and gmock.h with a warning-silencing pragma. See https://github.com/google/googletest/issues/4701 The warnings cause the Arch Linux CI to fail because of -Werror. </li>
+ <li>Fixed GetInvoiceFromTxn to convert to the right type of Python object for a GncInvoice.</li>
+ <li>[test-report-utilities] more tests for gnc:account-accumulate-at-dates testing balances at date boundaries </li>
+</ul>
+<p>New and Updated Translations: Arabic, Bulgarian, Chinese (Simplified Han script), Danish, Dutch, Finnish, French, German, Hungarian, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish</p>
+
+
+<a href="https://hosted.weblate.org/engage/gnucash/">Help translate GnuCash on Weblate</a>
+
+<h4>Known Problems</h4>
+<p><a href="https://bugs.gnucash.org/buglist.cgi?bug_severity=blocker&bug_severity=critical&bug_severity=major&bug_severity=normal&bug_severity=minor&bug_severity=trivial&bug_status=NEW&bug_status=ASSIGNED&bug_status=NEEDINFO&bug_status=REOPENED&limit=0&list_id=8149&order=priority%2Cbug_severity&query_format=advanced">Complete list of all open bugs.</a></p>
+
+<h2>Documentation</h2>
+<h4>The following fixes and improvements were not associated with bug reports:</h4>
+<ul>
+ <li>German translation: Fix some typos</li>
+ <li>German translation: Remove the Finance::Quote appendix. The content has been moved to the wiki.</li>
+</ul>
+
+<p>Updated Translations: German.</p>
+
+<h3>Getting GnuCash for Windows and MacOS</h3>
+<p>GnuCash is provided for both Microsoft Windows 10® and later
+ and MacOS 10.13 (High Sierra)® and later in pre-built, all-in-one
+ packages. An installer is provided for Microsoft Windows® while
+ the MacOS® package is a disk image containing a drag-and-drop
+ application bundle.</p>
+
+<p>GnuCash is also available as a flatpak from Flathub.org. <a href="https://wiki.gnucash.org/wiki/Flatpak">Instructions for installing and running.</a></p>
+
+<p>The SHA256 Hashes for the downloadable files are:</p>
+<ul>
+ <li><code>b35b4756be12bcfdbed54468f30443fa53f238520a9cead5bde2e6c4773fbf39</code> gnucash-5.12.tar.bz2</li>
+ <li><code>fa279ac0378b1860ede15a8b6645628e17e7e94df496d69be8fd5d20a570ccc7</code> gnucash-5.12.tar.gz</li>
+ <li><code>55e03a7161d9dc34309a453b85d0e16f1e58f4b7f7b4b2b17aa8be03d538f863</code> gnucash-5.12.setup.exe</li>
+ <li><code>a1f7454d07bfb536e641ccf9423b51f00dbd2374d8097d5ac5b918159832cc37</code> Gnucash-Arm-5.12-1.dmg</li>
+ <li><code>090d197df67926823360ee8bfaacffa60c10f467036080fd2a83f9f96bdebc40</code> Gnucash-Intel-5.12-1.dmg</li>
+ <li><code>c2a67aef439f25b8e3d43cf5cc29756fae0e82e252f0abf059b35663594ea994</code> gnucash-docs-5.12.tar.gz</li>
+</ul>
+
+<ul>
+ <li>SourceForge:
+ <ul>
+ <li><a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/gnucash-5.12.setup.exe">Win32</a></li>
+ <li><a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/Gnucash-Arm-5.12-1.dmg">Mac-Apple Silicon</a></li>
+ <li><a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/Gnucash-Intel-5.12-1.dmg">Mac-Intel</a></li>
+ </ul></li>
+ <li>Github
+ <ul>
+ <li><a href="https://github.com/Gnucash/gnucash/releases/download/5.12/gnucash-5..setup.exe">Win32</a></li>
+ <li><a href="https://github.com/Gnucash/gnucash/releases/download/5.12/Gnucash-Arm-5.12-1.dmg">Mac-Apple Silicon</a></li>
+ <li><a href="https://github.com/Gnucash/gnucash/releases/download/5.12/Gnucash-Intel-5.12-1.dmg">Mac-Intel</a></li>
+ </ul></li></ul>
+
+<h3>Getting GnuCash as source code</h3>
+<p>If you want to compile GnuCash 5.12 for yourself, the source code can be downloaded from:</p>
+<ul>
+
+ <li>Sourceforge: <a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/gnucash-5.12.tar.bz2">bzip2</a>, <a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/gnucash-5.12.tar.gz">gzip</a>.</li>
+
+ <li>Github: <a href="https://github.com/Gnucash/gnucash/releases/download/5.12/gnucash-5.12.tar.bz2">bzip</a>, <a href="https://github.com/Gnucash/gnucash/releases/download/5.12/gnucash-5.12.tar.gz">gzip</a></li>
+
+ <li>You can also checkout the sources directly from the git repository as <a href="https://wiki.gnucash.org/wiki/Git">described here.</a></li>
+</ul>
+
+<p>To compile GnuCash from the source code by yourself, you will need at least <a href="https://www.gtk.org">Gtk+</a> 3.22.30, <a href="https://www.gnu.org/software/guile/">Guile</a> 2.0.9, <a href="https://www.boost.org/">Boost</a> 1.67, <a href="https://webkitgtk.org/">WebKitGtk</a> 2.4, <a href="https://github.com/google/googletest">GoogleTest</a> 1.8.0, <a href="https://cmake.org/">cmake 3.14.5</a> and <a href="http://www.swig.org/">SWIG</a> 3.0.12. Please consult the README.dependencies file in the sources for the exact list of dependencies and versions.</p>
+
+<h3>Getting the documentation</h3>
+
+<p>The documentation is available at <a href="https://www.gnucash.org/docs.phtml">Documentation page</a> of the <a href="https://www.gnucash.org/">GnuCash website</a>. The 5.12 documentation can be found under "GnuCash v5 (current stable release)" in multiple languages both for reading online and for download in pdf, epub, and mobi formats. The documentation is also included in the MacOS and Windows application bundles.</p>
+
+<p>If you want to compile the GnuCash Documentation 5.12 for yourself, the source code can be downloaded from:</p>
+<ul>
+ <li><a href="https://downloads.sourceforge.net/gnucash/gnucash%20%28stable%29/5.12/gnucash-docs-5.12.tar.gz">Sourceforge</a> or <a href="https://github.com/Gnucash/gnucash/releases/download/5.12/gnucash-docs-5.11.tar.gz">GitHub</a></li>
+ <li>You can also checkout the sources directly from the git repository as <a href="https://wiki.gnucash.org/wiki/Git">described here.</a></li>
+</ul>
+
+
+<h3>About the Program</h3>
+
+<p>GnuCash is a free, open source accounting program released under
+ the GNU General Public License (GPL) and available for GNU/Linux,
+ *BSD, Solaris, MacOS, and Microsoft Windows. Programming on GnuCash
+ began in 1997, and its first stable release was in 1998.</p>
commit 5a48589b0891dd18c5bf5080cc418c9465751e6c
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Jun 29 20:22:26 2025 -0700
Copy latest php-gettext code, replacing ancient copies we had before.
diff --git a/externals/gettext.inc b/externals/gettext.inc
index 399a0f2..423eb77 100644
--- a/externals/gettext.inc
+++ b/externals/gettext.inc
@@ -32,7 +32,6 @@ LC_MESSAGES 5
LC_ALL 6
*/
-
// LC_MESSAGES is not available if php-gettext is not loaded
// while the other constants are already available from session extension.
if (!defined('LC_MESSAGES')) {
@@ -168,21 +167,20 @@ function _check_locale_and_function($function=false) {
function _get_codeset($domain=null) {
global $text_domains, $default_domain, $LC_CATEGORIES;
if (!isset($domain)) $domain = $default_domain;
- return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding');
+ return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('default_charset');
}
/**
* Convert the given string to the encoding set by bind_textdomain_codeset.
*/
function _encode($text) {
+ $target_encoding = _get_codeset();
+ if (function_exists("mb_detect_encoding")) {
$source_encoding = mb_detect_encoding($text);
- $target_encoding = _get_codeset();
- if ($source_encoding != $target_encoding) {
- return mb_convert_encoding($text, $target_encoding, $source_encoding);
- }
- else {
- return $text;
- }
+ if ($source_encoding != $target_encoding)
+ $text = mb_convert_encoding($text, $target_encoding, $source_encoding);
+ }
+ return $text;
}
@@ -229,7 +227,9 @@ function _setlocale($category, $locale) {
}
// Allow locale to be changed on the go for one translation domain.
global $text_domains, $default_domain;
- unset($text_domains[$default_domain]->l10n);
+ if (array_key_exists($default_domain, $text_domains)) {
+ unset($text_domains[$default_domain]->l10n);
+ }
return $CURRENTLOCALE;
}
}
@@ -288,9 +288,9 @@ function __($msgid) {
/**
* Plural version of gettext.
*/
-function _ngettext($single, $plural, $number) {
+function _ngettext($singular, $plural, $number) {
$l10n = _get_reader();
- return _encode($l10n->ngettext($single, $plural, $number));
+ return _encode($l10n->ngettext($singular, $plural, $number));
}
/**
@@ -304,9 +304,9 @@ function _dgettext($domain, $msgid) {
/**
* Plural version of dgettext.
*/
-function _dngettext($domain, $single, $plural, $number) {
+function _dngettext($domain, $singular, $plural, $number) {
$l10n = _get_reader($domain);
- return _encode($l10n->ngettext($single, $plural, $number));
+ return _encode($l10n->ngettext($singular, $plural, $number));
}
/**
@@ -319,9 +319,9 @@ function _dcgettext($domain, $msgid, $category) {
/**
* Plural version of dcgettext.
*/
-function _dcngettext($domain, $single, $plural, $number, $category) {
+function _dcngettext($domain, $singular, $plural, $number, $category) {
$l10n = _get_reader($domain, $category);
- return _encode($l10n->ngettext($single, $plural, $number));
+ return _encode($l10n->ngettext($singular, $plural, $number));
}
/**
@@ -405,29 +405,29 @@ function T_($msgid) {
if (_check_locale_and_function()) return _($msgid);
return __($msgid);
}
-function T_ngettext($single, $plural, $number) {
+function T_ngettext($singular, $plural, $number) {
if (_check_locale_and_function())
- return ngettext($single, $plural, $number);
- else return _ngettext($single, $plural, $number);
+ return ngettext($singular, $plural, $number);
+ else return _ngettext($singular, $plural, $number);
}
function T_dgettext($domain, $msgid) {
if (_check_locale_and_function()) return dgettext($domain, $msgid);
else return _dgettext($domain, $msgid);
}
-function T_dngettext($domain, $single, $plural, $number) {
+function T_dngettext($domain, $singular, $plural, $number) {
if (_check_locale_and_function())
- return dngettext($domain, $single, $plural, $number);
- else return _dngettext($domain, $single, $plural, $number);
+ return dngettext($domain, $singular, $plural, $number);
+ else return _dngettext($domain, $singular, $plural, $number);
}
function T_dcgettext($domain, $msgid, $category) {
if (_check_locale_and_function())
return dcgettext($domain, $msgid, $category);
else return _dcgettext($domain, $msgid, $category);
}
-function T_dcngettext($domain, $single, $plural, $number, $category) {
+function T_dcngettext($domain, $singular, $plural, $number, $category) {
if (_check_locale_and_function())
- return dcngettext($domain, $single, $plural, $number, $category);
- else return _dcngettext($domain, $single, $plural, $number, $category);
+ return dcngettext($domain, $singular, $plural, $number, $category);
+ else return _dcngettext($domain, $singular, $plural, $number, $category);
}
function T_pgettext($context, $msgid) {
@@ -451,26 +451,27 @@ function T_dcpgettext($domain, $context, $msgid, $category) {
return _dcpgettext($domain, $context, $msgid, $category);
}
-function T_npgettext($context, $singular, $plural) {
+function T_npgettext($context, $singular, $plural, $number) {
if (_check_locale_and_function('npgettext'))
- return npgettext($context, $single, $plural, $number);
+ return npgettext($context, $singular, $plural, $number);
else
- return _npgettext($context, $single, $plural, $number);
+ return _npgettext($context, $singular, $plural, $number);
}
-function T_dnpgettext($domain, $context, $singular, $plural) {
+function T_dnpgettext($domain, $context, $singular, $plural, $number) {
if (_check_locale_and_function('dnpgettext'))
- return dnpgettext($domain, $context, $single, $plural, $number);
+ return dnpgettext($domain, $context, $singular, $plural, $number);
else
- return _dnpgettext($domain, $context, $single, $plural, $number);
+ return _dnpgettext($domain, $context, $singular, $plural, $number);
}
-function T_dcnpgettext($domain, $context, $singular, $plural, $category) {
+function T_dcnpgettext($domain, $context, $singular, $plural,
+ $number, $category) {
if (_check_locale_and_function('dcnpgettext'))
- return dcnpgettext($domain, $context, $single,
+ return dcnpgettext($domain, $context, $singular,
$plural, $number, $category);
else
- return _dcnpgettext($domain, $context, $single,
+ return _dcnpgettext($domain, $context, $singular,
$plural, $number, $category);
}
@@ -494,39 +495,39 @@ if (!function_exists('gettext')) {
function _($msgid) {
return __($msgid);
}
- function ngettext($single, $plural, $number) {
- return _ngettext($single, $plural, $number);
+ function ngettext($singular, $plural, $number) {
+ return _ngettext($singular, $plural, $number);
}
function dgettext($domain, $msgid) {
return _dgettext($domain, $msgid);
}
- function dngettext($domain, $single, $plural, $number) {
- return _dngettext($domain, $single, $plural, $number);
+ function dngettext($domain, $singular, $plural, $number) {
+ return _dngettext($domain, $singular, $plural, $number);
}
function dcgettext($domain, $msgid, $category) {
return _dcgettext($domain, $msgid, $category);
}
- function dcngettext($domain, $single, $plural, $number, $category) {
- return _dcngettext($domain, $single, $plural, $number, $category);
+ function dcngettext($domain, $singular, $plural, $number, $category) {
+ return _dcngettext($domain, $singular, $plural, $number, $category);
}
function pgettext($context, $msgid) {
return _pgettext($context, $msgid);
}
- function npgettext($context, $single, $plural, $number) {
- return _npgettext($context, $single, $plural, $number);
+ function npgettext($context, $singular, $plural, $number) {
+ return _npgettext($context, $singular, $plural, $number);
}
function dpgettext($domain, $context, $msgid) {
return _dpgettext($domain, $context, $msgid);
}
- function dnpgettext($domain, $context, $single, $plural, $number) {
- return _dnpgettext($domain, $context, $single, $plural, $number);
+ function dnpgettext($domain, $context, $singular, $plural, $number) {
+ return _dnpgettext($domain, $context, $singular, $plural, $number);
}
function dcpgettext($domain, $context, $msgid, $category) {
return _dcpgettext($domain, $context, $msgid, $category);
}
- function dcnpgettext($domain, $context, $single, $plural,
+ function dcnpgettext($domain, $context, $singular, $plural,
$number, $category) {
- return _dcnpgettext($domain, $context, $single, $plural,
+ return _dcnpgettext($domain, $context, $singular, $plural,
$number, $category);
}
}
diff --git a/externals/gettext.php b/externals/gettext.php
index d3826d8..295d4b0 100644
--- a/externals/gettext.php
+++ b/externals/gettext.php
@@ -21,6 +21,8 @@
*/
+require('plurals.php');
+
/**
* Provides a simple gettext replacement that works independently from
* the system's gettext abilities.
@@ -98,7 +100,7 @@ class gettext_reader {
* @param object Reader the StreamReader object
* @param boolean enable_cache Enable or disable caching of strings (default on)
*/
- function gettext_reader($Reader, $enable_cache = true) {
+ function __construct($Reader, $enable_cache = true) {
// If there isn't a StreamReader, turn on short circuit mode.
if (! $Reader || isset($Reader->error) ) {
$this->short_circuit = true;
@@ -157,15 +159,11 @@ class gettext_reader {
$this->cache_translations = array ();
/* read all strings in the cache */
for ($i = 0; $i < $this->total; $i++) {
- $offset = $i * 2 + 2;
- if (!($this && $this->table_originals[$offset])) {
- continue;
- }
- $this->STREAM->seekto($this->table_originals[$offset]);
- $original = $this->STREAM->read($this->table_originals[$offset - 1]);
- $this->STREAM->seekto($this->table_translations[$offset]);
- $translation = $this->STREAM->read($this->table_translations[$offset - 1]);
- $this->cache_translations[$original] = $translation;
+ $this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
+ $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
+ $this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
+ $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
+ $this->cache_translations[$original] = $translation;
}
}
}
@@ -273,41 +271,6 @@ class gettext_reader {
}
}
- /**
- * Sanitize plural form expression for use in PHP eval call.
- *
- * @access private
- * @return string sanitized plural form expression
- */
- function sanitize_plural_expression($expr) {
- // Get rid of disallowed characters.
- $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
-
- // Add parenthesis for tertiary '?' operator.
- $expr .= ';';
- $res = '';
- $p = 0;
- for ($i = 0; $i < strlen($expr); $i++) {
- $ch = $expr[$i];
- switch ($ch) {
- case '?':
- $res .= ' ? (';
- $p++;
- break;
- case ':':
- $res .= ') : (';
- break;
- case ';':
- $res .= str_repeat( ')', $p) . ';';
- $p = 0;
- break;
- default:
- $res .= $ch;
- }
- }
- return $res;
- }
-
/**
* Parse full PO header and extract only plural forms line.
*
@@ -334,14 +297,14 @@ class gettext_reader {
$this->load_tables();
// cache header field for plural forms
- if (! is_string($this->pluralheader)) {
+ if ($this->pluralheader === NULL) {
if ($this->enable_cache) {
$header = $this->cache_translations[""];
} else {
$header = $this->get_translation_string(0);
}
$expr = $this->extract_plural_forms_header_from_po_header($header);
- $this->pluralheader = $this->sanitize_plural_expression($expr);
+ $this->pluralheader = new PluralHeader($expr);
}
return $this->pluralheader;
}
@@ -354,16 +317,16 @@ class gettext_reader {
* @return int array index of the right plural form
*/
function select_string($n) {
- $string = $this->get_plural_forms();
- $string = str_replace('nplurals',"\$total",$string);
- $string = str_replace("n",$n,$string);
- $string = str_replace('plural',"\$plural",$string);
+ if (!is_int($n)) {
+ throw new InvalidArgumentException(
+ "Select_string only accepts integers: " . $n);
+ }
+ $plural_header = $this->get_plural_forms();
+ $plural = $plural_header->expression->evaluate($n);
- $total = 0;
- $plural = 0;
+ if ($plural < 0) $plural = 0;
+ if ($plural >= $plural_header->total) $plural = $plural_header->total - 1;
- eval("$string");
- if ($plural >= $total) $plural = $total - 1;
return $plural;
}
@@ -413,12 +376,23 @@ class gettext_reader {
function pgettext($context, $msgid) {
$key = $context . chr(4) . $msgid;
- return $this->translate($key);
+ $ret = $this->translate($key);
+ if (strpos($ret, "\004") !== FALSE) {
+ return $msgid;
+ } else {
+ return $ret;
+ }
}
function npgettext($context, $singular, $plural, $number) {
- $singular = $context . chr(4) . $singular;
- return $this->ngettext($singular, $plural, $number);
+ $key = $context . chr(4) . $singular;
+ $ret = $this->ngettext($key, $plural, $number);
+ if (strpos($ret, "\004") !== FALSE) {
+ return $singular;
+ } else {
+ return $ret;
+ }
+
}
}
diff --git a/externals/plurals.php b/externals/plurals.php
new file mode 100644
index 0000000..1c6ce12
--- /dev/null
+++ b/externals/plurals.php
@@ -0,0 +1,461 @@
+<?php
+/*
+ Copyright (c) 2020 Sunil Mohan Adapa <sunil at medhas dot org>
+
+ Drop in replacement for native gettext.
+
+ This file is part of PHP-gettext.
+
+ PHP-gettext is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ PHP-gettext is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with PHP-gettext; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+
+/**
+ * Lexical analyzer for gettext plurals expression. Takes a string to parse
+ * during construction and returns a single token every time peek() or
+ * fetch_token() are called. The special string '__END__' is returned if there
+ * are no more tokens to be read. Spaces are ignored during tokenization.
+ */
+class PluralsLexer {
+ private $string;
+ private $position;
+
+ /**
+ * Constructor
+ *
+ * @param string string Contains the value gettext plurals expression to
+ * analyze.
+ */
+ public function __construct(string $string) {
+ $this->string = $string;
+ $this->position = 0;
+ }
+
+ /**
+ * Return the next token and the length to advance the read position without
+ * actually advancing the read position. Tokens for operators and variables
+ * are simple strings containing the operator or variable. If there are no
+ * more token to provide, the special value ['__END__', 0] is returned. If
+ * there was an unexpected input an Exception is raised.
+ *
+ * @access private
+ * @throws Exception If there is unexpected input in the provided string.
+ * @return array The next token and length to advance the current position.
+ */
+ private function _tokenize() {
+ $buf = $this->string;
+
+ // Consume all spaces until the next token
+ $index = $this->position;
+ while ($index < strlen($buf) && $buf[$index] == ' ') {
+ $index++;
+ }
+ $this->position = $index;
+
+ // Return special token if next of the string is reached.
+ if (strlen($buf) - $index == 0) {
+ return ['__END__', 0];
+ }
+
+ // Operators with two characters
+ $doubles = ['==', '!=', '>=', '<=', '&&', '||'];
+ $next = substr($buf, $index, 2);
+ if (in_array($next, $doubles)) {
+ return [$next, 2];
+ }
+
+ // Operators with single character or variable 'n'.
+ $singles = [
+ 'n', '(', ')', '?', ':', '+', '-', '*', '/', '%', '!', '>', '<'];
+ if (in_array($buf[$index], $singles)) {
+ return [$buf[$index], 1];
+ }
+
+ // Whole number constants, return an integer.
+ $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
+ $pos = $index;
+ while ($pos < strlen($buf) && in_array($buf[$pos], $digits)) {
+ $pos++;
+ }
+ if ($pos != $index) {
+ $length = $pos - $index;
+ return [(int)substr($buf, $index, $length), $length];
+ }
+
+ // Throw and exception for all other unexpected input in the string.
+ throw new Exception('Lexical analysis failed');
+ }
+
+ /**
+ * Return the next token without actually advancing the read position.
+ * Tokens for operators and variables are simple strings containing the
+ * operator or variable. If there are no more tokens to provide, the special
+ * value '__END__' is returned. If there was an unexpected input an
+ * Exception is raised.
+ *
+ * @throws Exception If there is unexpected input in the provided string.
+ * @return string The next token.
+ */
+ public function peek() {
+ list($token, $length) = $this->_tokenize();
+ return $token;
+ }
+
+ /**
+ * Return the next token after advancing the read position. Tokens for
+ * operators and variables are simple strings containing the operator or
+ * variable. If there are no more token to provide, the special value
+ * '__END__' is returned. If there was an unexpected input an Exception is
+ * raised.
+ *
+ * @throws Exception If there is unexpected input in the provided string.
+ * @return string The next token.
+ */
+ public function fetch_token() {
+ list($token, $length) = $this->_tokenize();
+ $this->position += $length;
+ return $token;
+ }
+}
+
+/**
+ * A parsed representation of the gettext plural expression. This is a tree
+ * containing further expressions depending on how nested the given input is.
+ * Calling the evaluate() function computes the value of the expression if the
+ * variable 'n' is set a certain value. This is used to decide which plural
+ * string translation to use based on the number items at hand.
+ */
+class PluralsExpression {
+ private $operator;
+ private $operands;
+
+ const BINARY_OPERATORS = [
+ '==', '!=', '>=', '<=', '&&', '||', '+', '-', '*', '/', '%', '>', '<'];
+ const UNARY_OPERATORS = ['!'];
+
+ /**
+ * Constructor
+ *
+ * @param string Operator for the expression.
+ * @param (int|string|PuralsExpression)[] Variable number of operands of the
+ * expression. One int operand is expected in case the operator is 'const'.
+ * One string operand with value 'n' is expected in case the operator is
+ * 'var'. For all other operators, the operands much be objects of type
+ * PluralExpression. Unary operators expect one operand, binary operators
+ * expect two operands and trinary operators expect three operands.
+ */
+ public function __construct($operator, ...$operands) {
+ $this->operator = $operator;
+ $this->operands = $operands;
+ }
+
+ /**
+ * Return a parenthesized string representation of the expression for
+ * debugging purposes.
+ *
+ * @return string A string representation of the expression.
+ */
+ public function to_string() {
+ if ($this->operator == 'const' || $this->operator == 'var') {
+ return $this->operands[0];
+ } elseif (in_array($this->operator, self::BINARY_OPERATORS)) {
+ return sprintf(
+ "(%s %s %s)", $this->operands[0]->to_string(), $this->operator,
+ $this->operands[1]->to_string());
+ } elseif (in_array($this->operator, self::UNARY_OPERATORS)) {
+ return sprintf(
+ "(%s %s)", $this->operator, $this->operands[0]->to_string());
+ } elseif ($this->operator == '?') {
+ return sprintf(
+ "(%s ? %s : %s)", $this->operands[0]->to_string(),
+ $this->operands[1]->to_string(),
+ $this->operands[2]->to_string());
+ }
+ }
+
+ /**
+ * Return the computed value of the expression if the variable 'n' is set to
+ * a certain value.
+ *
+ * @param int The value of the variable n to use when evaluating.
+ * @throws Exception If the expression has been constructed incorrectly.
+ * @return int The value of the expression after evaluation.
+ */
+ public function evaluate($n) {
+ if (!in_array($this->operator, ['const', 'var'])) {
+ $operand1 = $this->operands[0]->evaluate($n);
+ }
+ if (in_array($this->operator, self::BINARY_OPERATORS) ||
+ $this->operator == '?') {
+ $operand2 = $this->operands[1]->evaluate($n);
+ }
+ if ($this->operator == '?') {
+ $operand3 = $this->operands[2]->evaluate($n);
+ }
+
+ switch ($this->operator) {
+ case 'const':
+ return $this->operands[0];
+ case 'var':
+ return $n;
+ case '!':
+ return !($operand1);
+ case '==':
+ return $operand1 == $operand2;
+ case '!=':
+ return $operand1 != $operand2;
+ case '>=':
+ return $operand1 >= $operand2;
+ case '<=':
+ return $operand1 <= $operand2;
+ case '>':
+ return $operand1 > $operand2;
+ case '<':
+ return $operand1 < $operand2;
+ case '&&':
+ return $operand1 && $operand2;
+ case '||':
+ return $operand1 || $operand2;
+ case '+':
+ return $operand1 + $operand2;
+ case '-':
+ return $operand1 - $operand2;
+ case '*':
+ return $operand1 * $operand2;
+ case '/':
+ return (int)($operand1 / $operand2);
+ case '%':
+ return $operand1 % $operand2;
+ case '?':
+ return $operand1 ? $operand2 : $operand3;
+ default:
+ throw new Exception('Invalid expression');
+ }
+ }
+}
+
+/**
+ * A simple operator-precedence parser for gettext plural expressions. Takes a
+ * string during construction and returns a PluralsExpression tree when
+ * parse() is called.
+ */
+class PluralsParser {
+ private $lexer;
+
+ /*
+ * Operator precedence. The parsing only happens with minimum precedence of
+ * 0. However, ':' and ')' exist here to make sure that parsing does not
+ * proceed beyond them when they are not to be parsed.
+ */
+ private const PREC = [
+ ':' => -1, '?' => 0, '||' => 1, '&&' => 2, '==' => 3, '!=' => 3,
+ '>' => 4, '<' => 4, '>=' => 4, '<=' => 4, '+' => 5, '-' => 5, '*' => 6,
+ '/' => 6, '%' => 6, '!' => 7, '__END__' => -1, ')' => -1
+ ];
+
+ // List of right associative operators
+ private const RIGHT_ASSOC = ['?'];
+
+ /**
+ * Constructor
+ *
+ * @param string string the plural expression to be parsed.
+ */
+ public function __construct(string $string) {
+ $this->lexer = new PluralsLexer($string);
+ }
+
+ /**
+ * Expect a primary next for parsing and return a PluralsExpression or throw
+ * and exception otherwise. A primary can be the variable 'n', an whole
+ * number constant, a unary operator expression string with '!', or a
+ * parenthesis expression.
+ *
+ * @throws Exception If the next token is not a primary or if parenthesis
+ * expression is not closes properly with ')'.
+ * @return PluralsExpression That is constructed from the parsed primary.
+ */
+ private function _parse_primary() {
+ $token = $this->lexer->fetch_token();
+ if ($token === 'n') {
+ return new PluralsExpression('var', 'n');
+ } elseif (is_int($token)) {
+ return new PluralsExpression('const', (int)$token);
+ } elseif ($token === '!') {
+ return new PluralsExpression('!', $this->_parse_primary());
+ } elseif ($token === '(') {
+ $result = $this->_parse($this->_parse_primary(), 0);
+ if ($this->lexer->fetch_token() != ')') {
+ throw new Exception('Mismatched parenthesis');
+ }
+ return $result;
+ }
+
+ throw new Exception('Primary expected');
+ }
+
+ /**
+ * Fetch an operator from the lexical analyzer and test for it. Optionally
+ * advance the position of the lexical analyzer to next token. Raise
+ * exception if the token retrieved is not an operator.
+ *
+ * @access private
+ * @param bool peek A flag to indicate whether the position of the lexical
+ * analyzer should *not* be advanced. If false, the lexical analyzer is
+ * advanced by one token.
+ * @throws Exception If the token read is not an operator.
+ * @return string The operator that has been fetched from the lexical
+ * analyzer.
+ */
+ private function _parse_operator($peek) {
+ if ($peek) {
+ $token = $this->lexer->peek();
+ } else {
+ $token = $this->lexer->fetch_token();
+ }
+
+ if ($token !== NULL && !array_key_exists($token, self::PREC)) {
+ throw new Exception('Operator expected');
+ }
+ return $token;
+ }
+
+ /**
+ * A parsing method suitable for recursion.
+ *
+ * @access private
+ * @param ParserExpression left_side A pre-parsed left-hand side expression
+ * of the file expression to be constructed. This helps with recursion.
+ * @param int min_precedence The minimum value of precedence for the
+ * operators to be considered for parsing. Parsing will stop and current
+ * expression is returned if an operator of a lower precedence is
+ * encountered.
+ * @throws Exception If the input string does not conform to the grammar of
+ * the gettext plural expression.
+ * @return ParserExpression A complete expression after parsing.
+ */
+ private function _parse($left_side, $min_precedence) {
+ $next_token = $this->_parse_operator(true);
+
+ while (self::PREC[$next_token] >= $min_precedence) {
+ $operator = $this->_parse_operator(false);
+ $right_side = $this->_parse_primary();
+
+ $next_token = $this->_parse_operator(true);
+
+ /*
+ * Consume (recursively) into right hand side all expressions of higher
+ * precedence.
+ */
+ while ((self::PREC[$operator] < self::PREC[$next_token]) ||
+ ((self::PREC[$operator] == self::PREC[$next_token]) &&
+ in_array($operator, self::RIGHT_ASSOC))) {
+ $right_side = $this->_parse(
+ $right_side, self::PREC[$next_token]);
+ $next_token = $this->_parse_operator(true);
+ }
+
+ if ($operator != '?') {
+ /*
+ * Handling for all binary operators. Consume into left hand side all
+ * expressions of equal precedence.
+ */
+ $left_side = new PluralsExpression($operator, $left_side, $right_side);
+ } else {
+ // Special handling for (a ? b : c) expression
+ $operator = $this->lexer->fetch_token();
+ if ($operator != ':') {
+ throw new Exception('Invalid ? expression');
+ }
+
+ $right_side2 = $this->_parse(
+ $this->_parse_primary(), self::PREC[$operator] + 1);
+ $next_token = $this->_parse_operator(true);
+ $left_side = new PluralsExpression(
+ '?', $left_side, $right_side, $right_side2);
+ }
+ }
+ return $left_side;
+ }
+
+ /**
+ * A simple implementation of an operator-precedence parser. See:
+ * https://en.wikipedia.org/wiki/Operator-precedence_parser for an analysis
+ * of the algorithm.
+ *
+ * @throws Exception If the input string does not conform to the grammar of
+ * the gettext plural expression.
+ * @return ParserExpression A complete expression after parsing.
+ */
+ public function parse() {
+ $expression = $this->_parse($this->_parse_primary(), 0);
+ // Special handling for an extra ')' at the end.
+ if ($this->lexer->peek() != '__END__') {
+ throw new Exception('Could not parse completely');
+ }
+ return $expression;
+ }
+}
+
+/**
+ * Provides a class to parse the value of the 'Plural-Forms:' header in the
+ * gettext translation files. Holds the expression tree and the number of
+ * plurals after parsing. Parsing happens during construction which takes as
+ * its only argument the string to parse. Error during parsing are silently
+ * suppressed and the fallback behavior is used with the value for Germanic
+ * languages as follows: "nplurals=2; plural=n == 1 ? 0 : 1;".
+ */
+class PluralHeader {
+ public $total;
+ public $expression;
+
+ /**
+ * Constructor
+ *
+ * @param string The value of the Plural-Forms: header as seen in .po files.
+ */
+ function __construct($string) {
+ try {
+ list($total, $expression) = $this->parse($string);
+ } catch (Exception $e) {
+ $string = "nplurals=2; plural=n == 1 ? 0 : 1;";
+ list($total, $expression) = $this->parse($string);
+ }
+ $this->total = $total;
+ $this->expression = $expression;
+ }
+
+ /**
+ * Return the number of plural forms and the parsed expression tree.
+ *
+ * @access private
+ * @param string string The value of the Plural-Forms: header.
+ * @throws Exception If the string could not be parsed.
+ * @return array The number of plural forms and parsed expression tree.
+ */
+ private function parse($string) {
+ $regex = "/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural\s*=([^;]+);/i";
+ if (preg_match($regex, $string, $matches)) {
+ $total = (int)$matches[1];
+ $expression_string = $matches[2];
+ } else {
+ throw new Exception('Invalid header value');
+ }
+
+ $parser = new PluralsParser($expression_string);
+ $expression = $parser->parse();
+ return [$total, $expression];
+ }
+}
diff --git a/externals/streams.php b/externals/streams.php
index 3cdc158..00cf6cc 100644
--- a/externals/streams.php
+++ b/externals/streams.php
@@ -49,7 +49,7 @@ class StringReader {
var $_pos;
var $_str;
- function StringReader($str='') {
+ function __construct($str='') {
$this->_str = $str;
$this->_pos = 0;
}
@@ -86,7 +86,7 @@ class FileReader {
var $_fd;
var $_length;
- function FileReader($filename) {
+ function __construct($filename) {
if (file_exists($filename)) {
$this->_length=filesize($filename);
@@ -143,7 +143,7 @@ class FileReader {
// Preloads entire file in memory first, then creates a StringReader
// over it (it assumes knowledge of StringReader internals)
class CachedFileReader extends StringReader {
- function CachedFileReader($filename) {
+ function __construct($filename) {
if (file_exists($filename)) {
$length=filesize($filename);
Summary of changes:
externals/gettext.inc | 93 ++++-----
externals/gettext.php | 90 +++------
externals/global_params.php | 6 +-
externals/plurals.php | 461 ++++++++++++++++++++++++++++++++++++++++++++
externals/streams.php | 6 +-
news/250629-5.12.news | 127 ++++++++++++
6 files changed, 673 insertions(+), 110 deletions(-)
create mode 100644 externals/plurals.php
create mode 100644 news/250629-5.12.news
More information about the gnucash-changes
mailing list