Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved localization. #1807

Merged
merged 1 commit into from Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion js/codemirror/addon/lint/sql-lint.js
Expand Up @@ -30,7 +30,8 @@ CodeMirror.sqlLint = function(text, updateLinting, options, cm) {
method: "POST",
url: "lint.php",
data: {
'sql_query': text
sql_query: text,
token: PMA_commonParams.get('token'),
},
success: handleResponse
});
Expand Down
24 changes: 12 additions & 12 deletions libraries/Linter.class.php
Expand Up @@ -78,19 +78,16 @@ public static function lint($query)
{
// Disabling lint for huge queries to save some resources.
if (/*overload*/mb_strlen($query) > 10000) {
echo json_encode(
return array(
array(
array(
'message' => 'Linting is disabled for this query because it exceeds the maximum length.',
'fromLine' => 0,
'fromColumn' => 0,
'toLine' => 0,
'toColumn' => 0,
'severity' => 'warning',
)
'message' => __('Linting is disabled for this query because it exceeds the maximum length.'),
'fromLine' => 0,
'fromColumn' => 0,
'toLine' => 0,
'toColumn' => 0,
'severity' => 'warning',
)
);
return;
}

/**
Expand Down Expand Up @@ -146,7 +143,10 @@ public static function lint($query)

// Building the response.
$response[] = array(
'message' => $error[0] . ' (near <code>' . $error[2] . '</code>)',
'message' => sprintf(
__('%1$s (near <code>%2$s</code>)'),
$error[0], $error[2]
),
'fromLine' => $fromLine,
'fromColumn' => $fromColumn,
'toLine' => $toLine,
Expand All @@ -156,7 +156,7 @@ public static function lint($query)
}

// Sending back the answer.
echo json_encode($response);
return $response;
}

}
3 changes: 2 additions & 1 deletion libraries/config/messages.inc.php
Expand Up @@ -58,7 +58,8 @@
);
$strConfigCodemirrorEnable_name = __('Enable CodeMirror');
$strConfigLintEnable_desc = __('Find any errors in the query before executing it.'
. ' Requires CodeMirror to be enabled.');
. ' Requires CodeMirror to be enabled.'
);
$strConfigLintEnable_name = __('Enable linter');
$strConfigMinSizeForInputField_desc = __(
'Defines the minimum size for input fields generated for CHAR and VARCHAR '
Expand Down
4 changes: 1 addition & 3 deletions libraries/sql-parser/src/Component.php
Expand Up @@ -35,9 +35,7 @@ abstract class Component
* @return mixed
*/
public static function parse(
Parser $parser,
TokensList $list,
array $options = array()
Parser $parser, TokensList $list, array $options = array()
) {
// This method should be abstract, but it can't be both static and
// abstract.
Expand Down
5 changes: 4 additions & 1 deletion libraries/sql-parser/src/Components/AlterOperation.php
Expand Up @@ -187,7 +187,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if ($ret->options->isEmpty()) {
$parser->error('Unrecognized alter operation.', $list->tokens[$list->idx]);
$parser->error(
__('Unrecognized alter operation.'),
$list->tokens[$list->idx]
);
return null;
}

Expand Down
11 changes: 9 additions & 2 deletions libraries/sql-parser/src/Components/Array2d.php
Expand Up @@ -85,7 +85,14 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if ($count === -1) {
$count = $arrCount;
} elseif ($arrCount != $count) {
$parser->error("{$count} values were expected, but found {$arrCount}.", $token);
$parser->error(
sprintf(
__('%1$d values were expected, but found %2$d.'),
$count,
$arrCount
),
$token
);
}
$ret[] = $arr;
$state = 1;
Expand All @@ -103,7 +110,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

if ($state === 0) {
$parser->error(
'An opening bracket followed by a set of values was expected.',
__('An opening bracket followed by a set of values was expected.'),
$list->tokens[$list->idx]
);
}
Expand Down
10 changes: 8 additions & 2 deletions libraries/sql-parser/src/Components/ArrayObj.php
Expand Up @@ -97,7 +97,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =

if ($state === 0) {
if (($token->type !== Token::TYPE_OPERATOR) || ($token->value !== '(')) {
$parser->error('An opening bracket was expected.', $token);
$parser->error(
__('An opening bracket was expected.'),
$token
);
break;
}
$state = 1;
Expand All @@ -111,7 +114,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 2;
} elseif ($state === 2) {
if (($token->type !== Token::TYPE_OPERATOR) || (($token->value !== ',') && ($token->value !== ')'))) {
$parser->error('A comma or a closing bracket was expected', $token);
$parser->error(
__('A comma or a closing bracket was expected'),
$token
);
break;
}
if ($token->value === ',') {
Expand Down
2 changes: 1 addition & 1 deletion libraries/sql-parser/src/Components/DataType.php
Expand Up @@ -122,7 +122,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if ($state === 0) {
$ret->name = strtoupper($token->value);
if (($token->type !== Token::TYPE_KEYWORD) || (!($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) {
$parser->error('Unrecognized data type.', $token);
$parser->error(__('Unrecognized data type.'), $token);
}
$state = 1;
} elseif ($state === 1) {
Expand Down
17 changes: 11 additions & 6 deletions libraries/sql-parser/src/Components/Expression.php
Expand Up @@ -219,7 +219,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
break;
}
} elseif ($brackets < 0) {
$parser->error('Unexpected closing bracket.', $token);
$parser->error(__('Unexpected closing bracket.'), $token);
$brackets = 0;
}
} elseif ($token->value === ',') {
Expand All @@ -240,7 +240,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if ($alias) {
// An alias is expected (the keyword `AS` was previously found).
if (!empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
$parser->error(__('An alias was previously found.'), $token);
}
$ret->alias = $token->value;
$alias = 0;
Expand All @@ -251,7 +251,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// the column name we parsed is actually the table name
// and the table name is actually a database name.
if ((!empty($ret->database)) || ($dot)) {
$parser->error('Unexpected dot.', $token);
$parser->error(__('Unexpected dot.'), $token);
}
$ret->database = $ret->table;
$ret->table = $ret->column;
Expand All @@ -277,7 +277,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
) {
if (!empty($ret->alias)) {
$parser->error(
'An alias was previously found.', $token
__('An alias was previously found.'),
$token
);
}
$ret->alias = $token->value;
Expand All @@ -296,7 +297,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
) {
if (!empty($ret->alias)) {
$parser->error(
'An alias was previously found.', $token
__('An alias was previously found.'),
$token
);
}
$ret->alias = $token->value;
Expand All @@ -318,7 +320,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if ($alias === 2) {
$parser->error('An alias was expected.', $list->tokens[$list->idx - 1]);
$parser->error(
__('An alias was expected.'),
$list->tokens[$list->idx - 1]
);
}

// Whitespaces might be added at the end.
Expand Down
4 changes: 1 addition & 3 deletions libraries/sql-parser/src/Components/ExpressionArray.php
Expand Up @@ -36,8 +36,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
{
$ret = array();

$expr = null;

/**
* The state of the parser.
*
Expand Down Expand Up @@ -92,7 +90,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

if ($state === 0) {
$parser->error(
'An expression was expected.',
__('An expression was expected.'),
$list->tokens[$list->idx]
);
}
Expand Down
10 changes: 8 additions & 2 deletions libraries/sql-parser/src/Components/FieldDefinition.php
Expand Up @@ -198,7 +198,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
$state = 1;
} else {
$parser->error('An opening bracket was expected.', $token);
$parser->error(
__('An opening bracket was expected.'),
$token
);
break;
}
} elseif ($state === 1) {
Expand Down Expand Up @@ -248,7 +251,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if (($state !== 0) && ($state !== 6)) {
$parser->error('A closing bracket was expected.', $list->tokens[$list->idx - 1]);
$parser->error(
__('A closing bracket was expected.'),
$list->tokens[$list->idx - 1]
);
}

--$list->idx;
Expand Down
7 changes: 5 additions & 2 deletions libraries/sql-parser/src/Components/Limit.php
Expand Up @@ -87,7 +87,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'OFFSET')) {
if ($offset) {
$parser->error('An offset was expected.', $token);
$parser->error(__('An offset was expected.'), $token);
}
$offset = true;
continue;
Expand All @@ -108,7 +108,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if ($offset) {
$parser->error('An offset was expected.', $list->tokens[$list->idx - 1]);
$parser->error(
__('An offset was expected.'),
$list->tokens[$list->idx - 1]
);
}

--$list->idx;
Expand Down
8 changes: 7 additions & 1 deletion libraries/sql-parser/src/Components/OptionsArray.php
Expand Up @@ -137,7 +137,13 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// real options (e.g. if there are 5 options, the first
// fake ID is 6).
if (isset($ret->options[$lastOptionId])) {
$parser->error('This option conflicts with \'' . $ret->options[$lastOptionId] . '\'.', $token);
$parser->error(
sprintf(
__('This option conflicts with "%1$s".'),
$ret->options[$lastOptionId]
),
$token
);
$lastOptionId = $lastAssignedId++;
}
} else {
Expand Down
20 changes: 16 additions & 4 deletions libraries/sql-parser/src/Components/RenameOperation.php
Expand Up @@ -98,14 +98,20 @@ public static function parse(Parser $parser, TokensList $list, array $options =
)
);
if (empty($expr->old)) {
$parser->error('The old name of the table was expected.', $token);
$parser->error(
__('The old name of the table was expected.'),
$token
);
}
$state = 1;
} elseif ($state === 1) {
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'TO')) {
$state = 2;
} else {
$parser->error('Keyword "TO" was expected.', $token);
$parser->error(
__('Keyword "TO" was expected.'),
$token
);
break;
}
} elseif ($state === 2) {
Expand All @@ -119,7 +125,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
)
);
if (empty($expr->new)) {
$parser->error('The new name of the table was expected.', $token);
$parser->error(
__('The new name of the table was expected.'),
$token
);
}
$state = 3;
} elseif ($state === 3) {
Expand All @@ -134,7 +143,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if ($state !== 3) {
$parser->error('A rename operation was expected.', $list->tokens[$list->idx - 1]);
$parser->error(
__('A rename operation was expected.'),
$list->tokens[$list->idx - 1]
);
}

// Last iteration was not saved.
Expand Down