summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Lexer.php15
-rw-r--r--src/Parser.php15
2 files changed, 16 insertions, 14 deletions
diff --git a/src/Lexer.php b/src/Lexer.php
index d6c3784..cb3c658 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -13,14 +13,14 @@ namespace SqlParser;
use SqlParser\Exceptions\LexerException;
-if (!defined('USE_GETTEXT')) {
+if (!defined('TRANSLATE')) {
/**
- * Whether `gettext` function should be used to translate error messages
- * before throwing exceptions.
- * @var bool
+ * The name of the function that translates error messages.
+ * By default `__` (if exists).
+ * @var string
*/
- define('USE_GETTEXT', function_exists('gettext'));
+ define('TRANSLATE', function_exists('__') ? '__' : '');
}
if (!defined('USE_UTF_STRINGS')) {
@@ -322,8 +322,9 @@ class Lexer
public function error(
$msg = '', $str = '', $pos = 0, $args = null, $code = 0
) {
- if (USE_GETTEXT) {
- $msg = gettext($msg);
+ if (!empty(TRANSLATE)) {
+ $func = TRANSLATE;
+ $msg = $func($msg);
}
if (!empty($args)) {
$msg = vsprintf($msg, $args);
diff --git a/src/Parser.php b/src/Parser.php
index 2fdd27c..f29bc7d 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -12,14 +12,14 @@ namespace SqlParser;
use SqlParser\Statements\SelectStatement;
use SqlParser\Exceptions\ParserException;
-if (!defined('USE_GETTEXT')) {
+if (!defined('TRANSLATE')) {
/**
- * Whether `gettext` function should be used to translate error messages
- * before throwing exceptions.
- * @var bool
+ * The name of the function that translates error messages.
+ * By default `__` (if exists).
+ * @var string
*/
- define('USE_GETTEXT', function_exists('gettext'));
+ define('TRANSLATE', function_exists('__') ? '__' : '');
}
/**
@@ -419,8 +419,9 @@ class Parser
public function error(
$msg = '', Token $token = null, $args = null, $code = 0
) {
- if (USE_GETTEXT) {
- $msg = gettext($msg);
+ if (!empty(TRANSLATE)) {
+ $func = TRANSLATE;
+ $msg = $func($msg);
}
if (!empty($args)) {
$msg = vsprintf($msg, $args);