summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-21 14:05:03 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-21 14:05:03 +0300
commitf2ffbff424154aeb8767254e13b24d7bbeae366c (patch)
tree533bf05296306fffedf87f2599090adb6d1709a3 /src
parente5fc8680b2069da1ddf3f872b33c831a72b299e9 (diff)
downloadsql-parser-f2ffbff424154aeb8767254e13b24d7bbeae366c.zip
sql-parser-f2ffbff424154aeb8767254e13b24d7bbeae366c.tar.gz
sql-parser-f2ffbff424154aeb8767254e13b24d7bbeae366c.tar.bz2
Refactoring.
Improved localization tests.
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);