Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(i18n): add completion and search translations, remove hardcoded Chinese strings

t8y224c334ef61b1
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index 331c3bc246..d8cd840567 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { ref, nextTick, onMounted, onBeforeUnmount, watch, shallowRef } from "vue";
+import { ref, nextTick, onMounted, onBeforeUnmount, watch, shallowRef, computed } from "vue";
+import { useI18n } from "vue-i18n";
import type { CompletionContext } from "@codemirror/autocomplete";
import type { EditorView as EditorViewType } from "@codemirror/view";
import {
@@ -81,6 +82,58 @@ const view = shallowRef<EditorViewType | null>(null);
const connectionStore = useConnectionStore();
const settingsStore = useSettingsStore();
const { isDark } = useTheme();
+const { t } = useI18n();
+
+const SQL_FUNCTION_NAMES = [
+ "COUNT",
+ "SUM",
+ "AVG",
+ "MIN",
+ "MAX",
+ "GROUP_CONCAT",
+ "STRING_AGG",
+ "CONCAT",
+ "CONCAT_WS",
+ "SUBSTRING",
+ "REPLACE",
+ "TRIM",
+ "UPPER",
+ "LOWER",
+ "LENGTH",
+ "REGEXP_REPLACE",
+ "DATE_FORMAT",
+ "DATEDIFF",
+ "DATE_ADD",
+ "DATE_SUB",
+ "EXTRACT",
+ "NOW",
+ "ROUND",
+ "FLOOR",
+ "CEIL",
+ "ABS",
+ "MOD",
+ "COALESCE",
+ "IFNULL",
+ "NULLIF",
+ "CAST",
+ "JSON_EXTRACT",
+ "JSON_VALUE",
+ "JSON_OBJECT",
+ "JSON_ARRAY",
+] as const;
+
+const completionTranslations = computed(() => ({
+ nullValue: t("editor.completion.nullValue"),
+ isNull: t("editor.completion.isNull"),
+ isNotNull: t("editor.completion.isNotNull"),
+ stringLiteral: t("editor.completion.stringLiteral"),
+ numericLiteral: t("editor.completion.numericLiteral"),
+ booleanValue: t("editor.completion.booleanValue"),
+ starExpansionColumns: t("editor.completion.starExpansionColumns"),
+ functionDescriptions: Object.fromEntries(
+ SQL_FUNCTION_NAMES.map((name) => [name, t(`editor.completion.functionDescriptions.${name}`)]),
+ ) as Record<string, string>,
+}));
const MAX_COMPLETION_TABLES = 200;
const liveFontSize = ref(settingsStore.editorSettings.fontSize);
const gestureStartFontSize = ref(settingsStore.editorSettings.fontSize);
@@ -767,6 +820,7 @@ async function provideSqlCompletions(
tables,
columnsByTable,
schemas: schemaNames,
+ translations: completionTranslations.value,
});
if (items.length === 0) return null;
@@ -1336,13 +1390,13 @@ defineExpose({ openSearch });
autocorrect="off"
spellcheck="false"
class="w-48 h-6 text-xs bg-input border rounded px-2 outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground"
- placeholder="查找"
+ :placeholder="t('editor.search.find')"
@keydown="onSearchKeydown"
/>
<button
class="w-6 h-6 flex items-center justify-center rounded text-xs font-mono hover:bg-accent"
:class="caseSensitive ? 'bg-accent text-accent-foreground' : 'text-muted-foreground'"
- title="区分大小写"
+ :title="t('editor.search.caseSensitive')"
@click="caseSensitive = !caseSensitive"
>
Aa
@@ -1350,38 +1404,38 @@ defineExpose({ openSearch });
<button
class="w-6 h-6 flex items-center justify-center rounded text-xs font-mono hover:bg-accent"
:class="useRegex ? 'bg-accent text-accent-foreground' : 'text-muted-foreground'"
- title="正则表达式"
+ :title="t('editor.search.regex')"
@click="useRegex = !useRegex"
>
.*
</button>
<span v-if="searchText" class="text-xs text-muted-foreground min-w-[3rem] text-center shrink-0">
- {{ matchCount > 0 ? `${currentMatchIndex}/${matchCount}` : "无结果" }}
+ {{ matchCount > 0 ? `${currentMatchIndex}/${matchCount}` : t("editor.search.noResults") }}
</span>
<button
class="w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground"
- title="上一个 (Shift+Enter)"
+ :title="t('editor.search.prevMatch')"
@click="prevMatch"
>
<ChevronUp class="w-3.5 h-3.5" />
</button>
<button
class="w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground"
- title="下一个 (Enter)"
+ :title="t('editor.search.nextMatch')"
@click="nextMatch"
>
<ChevronDown class="w-3.5 h-3.5" />
</button>
<button
class="w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground"
- :title="showReplace ? '收起替换' : '展开替换'"
+ :title="showReplace ? t('editor.search.collapseReplace') : t('editor.search.expandReplace')"
@click="showReplace = !showReplace"
>
<ChevronRight class="w-3 h-3 transition-transform" :class="showReplace && 'rotate-90'" />
</button>
<button
class="w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground"
- title="关闭 (Esc)"
+ :title="t('editor.search.close')"
@click="closeSearch"
>
<X class="w-3.5 h-3.5" />
@@ -1394,19 +1448,19 @@ defineExpose({ openSearch });
autocorrect="off"
spellcheck="false"
class="w-48 h-6 text-xs bg-input border rounded px-2 outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground"
- placeholder="替换"
+ :placeholder="t('editor.search.replace')"
@keydown.enter.prevent="doReplace"
/>
<button
class="h-6 px-1.5 flex items-center justify-center rounded text-xs text-muted-foreground hover:bg-accent hover:text-foreground border"
- title="替换"
+ :title="t('editor.search.replace')"
@click="doReplace"
>
- 替换
+ {{ t("editor.search.replace") }}
</button>
<button
class="h-6 px-1.5 flex items-center justify-center rounded text-xs text-muted-foreground hover:bg-accent hover:text-foreground border"
- title="全部替换"
+ :title="t('editor.search.replaceAll')"
@click="doReplaceAll"
>
全部
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index bef3dc9e3f..a353a7f181 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -216,6 +216,65 @@ export default {
selectSchema: "Select schema",
setDefaultDatabase: "Set Default",
defaultDatabase: "Default",
+ completion: {
+ nullValue: "NULL value",
+ isNull: "Check if NULL",
+ isNotNull: "Check if not NULL",
+ stringLiteral: "String literal",
+ numericLiteral: "Numeric literal",
+ booleanValue: "Boolean value",
+ starExpansionColumns: "{count} columns",
+ functionDescriptions: {
+ COUNT: "Returns the number of rows",
+ SUM: "Returns the sum of a numeric column",
+ AVG: "Returns the average of a numeric column",
+ MIN: "Returns the minimum value",
+ MAX: "Returns the maximum value",
+ GROUP_CONCAT: "Concatenates group values into a string",
+ STRING_AGG: "Concatenates group strings",
+ CONCAT: "Concatenates multiple strings",
+ CONCAT_WS: "Concatenates strings with separator",
+ SUBSTRING: "Extracts a substring",
+ REPLACE: "Replaces content in a string",
+ TRIM: "Trims leading and trailing spaces",
+ UPPER: "Converts to uppercase",
+ LOWER: "Converts to lowercase",
+ LENGTH: "Returns the string length",
+ REGEXP_REPLACE: "Replaces using a regular expression",
+ DATE_FORMAT: "Formats a date with the given format",
+ DATEDIFF: "Calculates the difference between two dates",
+ DATE_ADD: "Adds an interval to a date",
+ DATE_SUB: "Subtracts an interval from a date",
+ EXTRACT: "Extracts a date part",
+ NOW: "Returns the current date and time",
+ ROUND: "Rounds to the specified decimal places",
+ FLOOR: "Rounds down",
+ CEIL: "Rounds up",
+ ABS: "Returns the absolute value",
+ MOD: "Returns the division remainder",
+ COALESCE: "Returns the first non-NULL argument",
+ IFNULL: "Returns a replacement value if NULL",
+ NULLIF: "Returns NULL if arguments are equal",
+ CAST: "Converts an expression to a target type",
+ JSON_EXTRACT: "Extracts a value from JSON",
+ JSON_VALUE: "Extracts a scalar value from JSON",
+ JSON_OBJECT: "Creates a JSON object",
+ JSON_ARRAY: "Creates a JSON array",
+ },
+ },
+ search: {
+ find: "Find",
+ replace: "Replace",
+ replaceAll: "Replace All",
+ caseSensitive: "Case sensitive",
+ regex: "Regular expression",
+ collapseReplace: "Collapse replace",
+ expandReplace: "Expand replace",
+ prevMatch: "Previous (Shift+Enter)",
+ nextMatch: "Next (Enter)",
+ close: "Close (Esc)",
+ noResults: "No results",
+ },
},
tabs: {
sql: "SQL",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 3b9bb26497..ccd6c1ef66 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -211,6 +211,65 @@ export default {
selectSchema: "Seleccionar esquema",
setDefaultDatabase: "Establecer como predeterminada",
defaultDatabase: "Predeterminada",
+ completion: {
+ nullValue: "Valor NULL",
+ isNull: "Comprobar si es NULL",
+ isNotNull: "Comprobar si no es NULL",
+ stringLiteral: "Literal de cadena",
+ numericLiteral: "Literal numérico",
+ booleanValue: "Valor booleano",
+ starExpansionColumns: "{count} columnas",
+ functionDescriptions: {
+ COUNT: "Devuelve el número de filas",
+ SUM: "Devuelve la suma de una columna numérica",
+ AVG: "Devuelve el promedio de una columna numérica",
+ MIN: "Devuelve el valor mínimo",
+ MAX: "Devuelve el valor máximo",
+ GROUP_CONCAT: "Concatena valores de grupo en una cadena",
+ STRING_AGG: "Concatena cadenas de grupo",
+ CONCAT: "Concatena múltiples cadenas",
+ CONCAT_WS: "Concatena cadenas con separador",
+ SUBSTRING: "Extrae una subcadena",
+ REPLACE: "Reemplaza contenido en una cadena",
+ TRIM: "Elimina espacios al inicio y final",
+ UPPER: "Convierte a mayúsculas",
+ LOWER: "Convierte a minúsculas",
+ LENGTH: "Devuelve la longitud de la cadena",
+ REGEXP_REPLACE: "Reemplaza usando expresión regular",
+ DATE_FORMAT: "Formatea una fecha con el formato dado",
+ DATEDIFF: "Calcula la diferencia entre dos fechas",
+ DATE_ADD: "Añade un intervalo a una fecha",
+ DATE_SUB: "Resta un intervalo de una fecha",
+ EXTRACT: "Extrae una parte de la fecha",
+ NOW: "Devuelve la fecha y hora actual",
+ ROUND: "Redondea a los decimales especificados",
+ FLOOR: "Redondea hacia abajo",
+ CEIL: "Redondea hacia arriba",
+ ABS: "Devuelve el valor absoluto",
+ MOD: "Devuelve el resto de la división",
+ COALESCE: "Devuelve el primer argumento no NULL",
+ IFNULL: "Devuelve un valor de reemplazo si es NULL",
+ NULLIF: "Devuelve NULL si los argumentos son iguales",
+ CAST: "Convierte una expresión a un tipo de destino",
+ JSON_EXTRACT: "Extrae un valor de JSON",
+ JSON_VALUE: "Extrae un valor escalar de JSON",
+ JSON_OBJECT: "Crea un objeto JSON",
+ JSON_ARRAY: "Crea un array JSON",
+ },
+ },
+ search: {
+ find: "Buscar",
+ replace: "Reemplazar",
+ replaceAll: "Reemplazar todo",
+ caseSensitive: "Distinguir mayúsculas",
+ regex: "Expresión regular",
+ collapseReplace: "Contraer reemplazo",
+ expandReplace: "Expandir reemplazo",
+ prevMatch: "Anterior (Shift+Enter)",
+ nextMatch: "Siguiente (Enter)",
+ close: "Cerrar (Esc)",
+ noResults: "Sin resultados",
+ },
},
tabs: {
sql: "SQL",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 9c554337ab..6631e63fc0 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -214,6 +214,65 @@ export default {
selectSchema: "选择模式",
setDefaultDatabase: "设为默认",
defaultDatabase: "默认库",
+ completion: {
+ nullValue: "空值",
+ isNull: "判断是否为 NULL",
+ isNotNull: "判断是否不为 NULL",
+ stringLiteral: "字符串字面量",
+ numericLiteral: "数值字面量",
+ booleanValue: "布尔值",
+ starExpansionColumns: "{count} 列",
+ functionDescriptions: {
+ COUNT: "返回行数",
+ SUM: "返回数值列的总和",
+ AVG: "返回数值列的平均值",
+ MIN: "返回最小值",
+ MAX: "返回最大值",
+ GROUP_CONCAT: "将分组中的值连接为字符串",
+ STRING_AGG: "将分组中的字符串连接起来",
+ CONCAT: "连接多个字符串",
+ CONCAT_WS: "使用分隔符连接多个字符串",
+ SUBSTRING: "提取子字符串",
+ REPLACE: "替换字符串中的内容",
+ TRIM: "去除首尾空格",
+ UPPER: "转换为大写",
+ LOWER: "转换为小写",
+ LENGTH: "返回字符串长度",
+ REGEXP_REPLACE: "使用正则表达式替换",
+ DATE_FORMAT: "按指定格式格式化日期",
+ DATEDIFF: "计算两个日期的差值",
+ DATE_ADD: "对日期进行加法运算",
+ DATE_SUB: "对日期进行减法运算",
+ EXTRACT: "提取日期中的指定部分",
+ NOW: "返回当前日期时间",
+ ROUND: "四舍五入到指定小数位",
+ FLOOR: "向下取整",
+ CEIL: "向上取整",
+ ABS: "返回绝对值",
+ MOD: "返回除法余数",
+ COALESCE: "返回第一个非 NULL 的参数",
+ IFNULL: "如果为 NULL 则返回替代值",
+ NULLIF: "如果相等则返回 NULL",
+ CAST: "将表达式转换为指定类型",
+ JSON_EXTRACT: "从 JSON 中提取值",
+ JSON_VALUE: "从 JSON 中提取标量值",
+ JSON_OBJECT: "创建 JSON 对象",
+ JSON_ARRAY: "创建 JSON 数组",
+ },
+ },
+ search: {
+ find: "查找",
+ replace: "替换",
+ replaceAll: "全部替换",
+ caseSensitive: "区分大小写",
+ regex: "正则表达式",
+ collapseReplace: "收起替换",
+ expandReplace: "展开替换",
+ prevMatch: "上一个 (Shift+Enter)",
+ nextMatch: "下一个 (Enter)",
+ close: "关闭 (Esc)",
+ noResults: "无结果",
+ },
},
tabs: {
sql: "SQL",
diff --git a/apps/desktop/src/lib/connectionUrl.ts b/apps/desktop/src/lib/connectionUrl.ts
index 8fc0fc354a..a3d86ced27 100644
--- a/apps/desktop/src/lib/connectionUrl.ts
+++ b/apps/desktop/src/lib/connectionUrl.ts
@@ -41,7 +41,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
dm: { type: "dameng", profile: "dm", label: "DM (Dameng)", defaultPort: 5236 },
dameng: { type: "dameng", profile: "dm", label: "DM (Dameng)", defaultPort: 5236 },
gaussdb: { type: "gaussdb", profile: "gaussdb", label: "GaussDB", defaultPort: 5432 },
- yashandb: { type: "yashandb", profile: "yashandb", label: "崖山 YashanDB", defaultPort: 1688 },
+ yashandb: { type: "yashandb", profile: "yashandb", label: "YashanDB", defaultPort: 1688 },
opengauss: { type: "gaussdb", profile: "opengauss", label: "openGauss", defaultPort: 5432 },
tdengine: { type: "tdengine", profile: "tdengine", label: "TDengine", defaultPort: 6041 },
"taos-ws": { type: "tdengine", profile: "tdengine", label: "TDengine", defaultPort: 6041 },
diff --git a/apps/desktop/src/lib/sqlCompletion.ts b/apps/desktop/src/lib/sqlCompletion.ts
index a55ca9d731..1ac1869667 100644
--- a/apps/desktop/src/lib/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sqlCompletion.ts
@@ -340,49 +340,46 @@ const WINDOW_FUNCTIONS = new Set([
"NTILE",
]);
-const FUNCTION_DESCRIPTIONS = new Map<string, string>([
- // Aggregate
- ["COUNT", "返回行数"],
- ["SUM", "返回数值列的总和"],
- ["AVG", "返回数值列的平均值"],
- ["MIN", "返回最小值"],
- ["MAX", "返回最大值"],
- ["GROUP_CONCAT", "将分组中的值连接为字符串"],
- ["STRING_AGG", "将分组中的字符串连接起来"],
- // String
- ["CONCAT", "连接多个字符串"],
- ["CONCAT_WS", "使用分隔符连接多个字符串"],
- ["SUBSTRING", "提取子字符串"],
- ["REPLACE", "替换字符串中的内容"],
- ["TRIM", "去除首尾空格"],
- ["UPPER", "转换为大写"],
- ["LOWER", "转换为小写"],
- ["LENGTH", "返回字符串长度"],
- ["REGEXP_REPLACE", "使用正则表达式替换"],
- // Date
- ["DATE_FORMAT", "按指定格式格式化日期"],
- ["DATEDIFF", "计算两个日期的差值"],
- ["DATE_ADD", "对日期进行加法运算"],
- ["DATE_SUB", "对日期进行减法运算"],
- ["EXTRACT", "提取日期中的指定部分"],
- ["NOW", "返回当前日期时间"],
- // Numeric
- ["ROUND", "四舍五入到指定小数位"],
- ["FLOOR", "向下取整"],
- ["CEIL", "向上取整"],
- ["ABS", "返回绝对值"],
- ["MOD", "返回除法余数"],
- // Conditional
- ["COALESCE", "返回第一个非 NULL 的参数"],
- ["IFNULL", "如果为 NULL 则返回替代值"],
- ["NULLIF", "如果相等则返回 NULL"],
- ["CAST", "将表达式转换为指定类型"],
- // JSON
- ["JSON_EXTRACT", "从 JSON 中提取值"],
- ["JSON_VALUE", "从 JSON 中提取标量值"],
- ["JSON_OBJECT", "创建 JSON 对象"],
- ["JSON_ARRAY", "创建 JSON 数组"],
-]);
+function getFunctionDescriptions(t?: SqlCompletionTranslations): Map<string, string> {
+ const d = t?.functionDescriptions ?? {};
+ return new Map<string, string>([
+ ["COUNT", d.COUNT || "返回行数"],
+ ["SUM", d.SUM || "返回数值列的总和"],
+ ["AVG", d.AVG || "返回数值列的平均值"],
+ ["MIN", d.MIN || "返回最小值"],
+ ["MAX", d.MAX || "返回最大值"],
+ ["GROUP_CONCAT", d.GROUP_CONCAT || "将分组中的值连接为字符串"],
+ ["STRING_AGG", d.STRING_AGG || "将分组中的字符串连接起来"],
+ ["CONCAT", d.CONCAT || "连接多个字符串"],
+ ["CONCAT_WS", d.CONCAT_WS || "使用分隔符连接多个字符串"],
+ ["SUBSTRING", d.SUBSTRING || "提取子字符串"],
+ ["REPLACE", d.REPLACE || "替换字符串中的内容"],
+ ["TRIM", d.TRIM || "去除首尾空格"],
+ ["UPPER", d.UPPER || "转换为大写"],
+ ["LOWER", d.LOWER || "转换为小写"],
+ ["LENGTH", d.LENGTH || "返回字符串长度"],
+ ["REGEXP_REPLACE", d.REGEXP_REPLACE || "使用正则表达式替换"],
+ ["DATE_FORMAT", d.DATE_FORMAT || "按指定格式格式化日期"],
+ ["DATEDIFF", d.DATEDIFF || "计算两个日期的差值"],
+ ["DATE_ADD", d.DATE_ADD || "对日期进行加法运算"],
+ ["DATE_SUB", d.DATE_SUB || "对日期进行减法运算"],
+ ["EXTRACT", d.EXTRACT || "提取日期中的指定部分"],
+ ["NOW", d.NOW || "返回当前日期时间"],
+ ["ROUND", d.ROUND || "四舍五入到指定小数位"],
+ ["FLOOR", d.FLOOR || "向下取整"],
+ ["CEIL", d.CEIL || "向上取整"],
+ ["ABS", d.ABS || "返回绝对值"],
+ ["MOD", d.MOD || "返回除法余数"],
+ ["COALESCE", d.COALESCE || "返回第一个非 NULL 的参数"],
+ ["IFNULL", d.IFNULL || "如果为 NULL 则返回替代值"],
+ ["NULLIF", d.NULLIF || "如果相等则返回 NULL"],
+ ["CAST", d.CAST || "将表达式转换为指定类型"],
+ ["JSON_EXTRACT", d.JSON_EXTRACT || "从 JSON 中提取值"],
+ ["JSON_VALUE", d.JSON_VALUE || "从 JSON 中提取标量值"],
+ ["JSON_OBJECT", d.JSON_OBJECT || "创建 JSON 对象"],
+ ["JSON_ARRAY", d.JSON_ARRAY || "创建 JSON 数组"],
+ ]);
+}
const SQL_SNIPPETS: Array<{ label: string; prefix: string; apply: string; detail: string }> = [
{
@@ -610,6 +607,17 @@ export interface SqlFunctionSignatureHelp {
parameters: string[];
}
+export interface SqlCompletionTranslations {
+ nullValue: string;
+ isNull: string;
+ isNotNull: string;
+ stringLiteral: string;
+ numericLiteral: string;
+ booleanValue: string;
+ starExpansionColumns: string;
+ functionDescriptions: Record<string, string>;
+}
+
export function buildSqlCompletionItems(
sql: string,
cursor: number,
@@ -617,6 +625,7 @@ export function buildSqlCompletionItems(
tables: SqlCompletionTable[];
columnsByTable: Map<string, SqlCompletionColumn[]>;
schemas?: string[];
+ translations?: SqlCompletionTranslations;
},
): SqlCompletionItem[] {
const context = getSqlCompletionContext(sql, cursor);
@@ -629,13 +638,15 @@ export function buildSqlCompletionItemsFromContext(
tables: SqlCompletionTable[];
columnsByTable: Map<string, SqlCompletionColumn[]>;
schemas?: string[];
+ translations?: SqlCompletionTranslations;
},
): SqlCompletionItem[] {
const items: SqlCompletionItem[] = [];
+ const t = input.translations;
if (!context.exclusiveTableSuggestions && !context.exclusiveColumnSuggestions) {
items.push(...buildSnippetItems(context.prefix));
- items.push(...buildFunctionSnippetItems(context.prefix));
+ items.push(...buildFunctionSnippetItems(context.prefix, getFunctionDescriptions(t)));
}
if (!context.exclusiveTableSuggestions && !context.exclusiveColumnSuggestions && context.prioritizeSelectAliases) {
@@ -677,12 +688,12 @@ export function buildSqlCompletionItemsFromContext(
// Type-aware value hints after comparison operator
if (context.comparisonLeftColumn && context.suggestKeywords) {
- items.push(...buildComparisonValueItems(context, input.columnsByTable));
+ items.push(...buildComparisonValueItems(context, input.columnsByTable, t));
}
// SELECT * expansion
if (context.onStar) {
- const starItem = buildStarExpansionItem(input.columnsByTable);
+ const starItem = buildStarExpansionItem(input.columnsByTable, t);
if (starItem) items.push(starItem);
}
@@ -847,9 +858,6 @@ export function getSqlCompletionContext(sql: string, cursor: number): SqlComplet
const statementKind = detectStatementKind(beforeCursor || fullStatement);
- // Detect column on left side of comparison operator (for type-aware filtering)
- const comparisonLeftColumn = detectComparisonLeftColumn(beforeCursor);
-
return {
prefix,
qualifier: insertInfo ? undefined : qualifier,
@@ -1453,7 +1461,10 @@ function buildSchemaItems(prefix: string, schemas: string[]): SqlCompletionItem[
}));
}
-function buildStarExpansionItem(columnsByTable: Map<string, SqlCompletionColumn[]>): SqlCompletionItem | null {
+function buildStarExpansionItem(
+ columnsByTable: Map<string, SqlCompletionColumn[]>,
+ t?: SqlCompletionTranslations,
+): SqlCompletionItem | null {
const allColumns: string[] = [];
const seen = new Set<string>();
for (const [, cols] of columnsByTable) {
@@ -1468,7 +1479,7 @@ function buildStarExpansionItem(columnsByTable: Map<string, SqlCompletionColumn[
return {
label: "* → columns",
type: "snippet" as const,
- detail: `${allColumns.length} 列: ${expansion.length > 60 ? expansion.slice(0, 57) + "..." : expansion}`,
+ detail: `${(t?.starExpansionColumns ?? "{count} 列").replace("{count}", String(allColumns.length))}: ${expansion.length > 60 ? expansion.slice(0, 57) + "..." : expansion}`,
apply: expansion,
boost: 1900,
};
@@ -1477,6 +1488,7 @@ function buildStarExpansionItem(columnsByTable: Map<string, SqlCompletionColumn[
function buildComparisonValueItems(
context: SqlCompletionContext,
columnsByTable: Map<string, SqlCompletionColumn[]>,
+ t?: SqlCompletionTranslations,
): SqlCompletionItem[] {
const colName = context.comparisonLeftColumn!;
const parts = colName.split(".");
@@ -1520,19 +1532,19 @@ function buildComparisonValueItems(
items.push({
label: "NULL",
type: "keyword" as const,
- detail: "空值",
+ detail: t?.nullValue ?? "空值",
boost: 1300,
});
items.push({
label: "IS NULL",
type: "keyword" as const,
- detail: "判断是否为 NULL",
+ detail: t?.isNull ?? "判断是否为 NULL",
boost: 1250,
});
items.push({
label: "IS NOT NULL",
type: "keyword" as const,
- detail: "判断是否不为 NULL",
+ detail: t?.isNotNull ?? "判断是否不为 NULL",
boost: 1200,
});
@@ -1547,7 +1559,7 @@ function buildComparisonValueItems(
items.push({
label: "''",
type: "snippet" as const,
- detail: "字符串字面量",
+ detail: t?.stringLiteral ?? "字符串字面量",
apply: "'${value}'",
boost: 1800,
});
@@ -1570,7 +1582,7 @@ function buildComparisonValueItems(
items.push({
label: "0",
type: "snippet" as const,
- detail: "数值字面量",
+ detail: t?.numericLiteral ?? "数值字面量",
apply: "${1:value}",
boost: 1750,
});
@@ -1580,8 +1592,8 @@ function buildComparisonValueItems(
// Boolean-ish: tinyint or bit
if (dt === "bit" || dt === "boolean" || dt === "bool") {
items.push(
- { label: "TRUE", type: "keyword" as const, detail: "布尔值", boost: 1700 },
- { label: "FALSE", type: "keyword" as const, detail: "布尔值", boost: 1650 },
+ { label: "TRUE", type: "keyword" as const, detail: t?.booleanValue ?? "布尔值", boost: 1700 },
+ { label: "FALSE", type: "keyword" as const, detail: t?.booleanValue ?? "布尔值", boost: 1650 },
);
}
@@ -1884,7 +1896,7 @@ function buildSnippetItems(prefix: string): SqlCompletionItem[] {
});
}
-function buildFunctionSnippetItems(prefix: string): SqlCompletionItem[] {
+function buildFunctionSnippetItems(prefix: string, functionDescriptions: Map<string, string>): SqlCompletionItem[] {
const items: SqlCompletionItem[] = [];
for (const [name, parameters] of SQL_FUNCTION_SIGNATURES.entries()) {
@@ -1893,7 +1905,7 @@ function buildFunctionSnippetItems(prefix: string): SqlCompletionItem[] {
items.push({
label: name,
type: "snippet" as const,
- detail: FUNCTION_DESCRIPTIONS.get(name) ?? "function",
+ detail: functionDescriptions.get(name) ?? "function",
apply: `${name}(${paramStr})`,
boost: computeBoost(name, prefix) + 300,
});