-
Notifications
You must be signed in to change notification settings - Fork 0
feat: i18n 시스템에 변수 보간 기능 구현 #786
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,17 @@ const dictionaries = { | |
|
|
||
| /** Documented. */ | ||
| export function createTranslator(locale: Locale = "en") { | ||
| return function t(key: TranslationKey): string { | ||
| return dictionaries[locale][key] ?? dictionaries.en[key]; | ||
| return function t(key: TranslationKey, variables?: Record<string, string | number>): string { | ||
| let result = dictionaries[locale][key] ?? dictionaries.en[key]; | ||
|
|
||
| if (variables) { | ||
| for (const [varName, varValue] of Object.entries(variables)) { | ||
| const escapedVarName = varName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| result = result.replace(new RegExp(`\\{${escapedVarName}\\}`, "g"), String(varValue)); | ||
| } | ||
| } | ||
|
Comment on lines
+19
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file="apps/desktop/src/i18n/index.ts"
ast-grep outline "$file" --lang typescript
printf '\n--- relevant source ---\n'
sed -n '1,80p' "$file"
printf '\n--- usages and tests ---\n'
rg -n --glob '!node_modules' 'replaceVariables|variables|\\\{[^}]+\\\}' apps/desktop/src/i18n apps/desktop/src | head -200Repository: ContextualWisdomLab/bandscope Length of output: 2195 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- tests ---'
sed -n '1,150p' apps/desktop/src/i18n/index.test.ts
printf '%s\n' '--- placeholder inventory ---'
rg -o --no-filename '\{[^{}]+\}' apps/desktop/src/locales | sort | uniq -c | head -200
printf '%s\n' '--- JavaScript behavior probes ---'
node - <<'JS'
const cases = [
['dot', 'a.b', 'x {axb} {a.b}', 'VALUE'],
['bracket', '[', 'x {[}', 'VALUE'],
['replacement-token', 'name', 'x {name}', '$&'],
['replacement-dollar', 'name', 'x {name}', '$$'],
['replacement-group', 'name', 'x {name}', '$1'],
];
for (const [label, varName, input, value] of cases) {
try {
const re = new RegExp(`\\{${varName}\\}`, 'g');
console.log(label, 'pattern=', re.source, 'output=', input.replace(re, String(value)));
} catch (error) {
console.log(label, 'error=', error.name + ': ' + error.message);
}
}
const input = 'x {a.b} {axb} {name} {[}';
const variables = {'a.b': 'D', name: '$&', '[': 'B'};
console.log('callback=', input.replace(/\{([^{}]+)\}/g, (placeholder, varName) =>
Object.prototype.hasOwnProperty.call(variables, varName)
? String(variables[varName])
: placeholder
));
JSRepository: ContextualWisdomLab/bandscope Length of output: 3548 정규식과 치환 값을 literal-safe하게 처리하세요.
정적 placeholder 정식 표현식으로 한 번 순회하고, callback에서 값을 반환하세요. 🧰 Tools🪛 ast-grep (0.45.0)[warning] 20-20: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
|
|
||
| return result; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
중복된
[Unreleased]heading을 제거하세요.기존 heading은 line 3에 이미 있습니다. 현재 구조는 markdownlint MD024 경고를 발생시킵니다. 새 i18n 항목을 기존
[Unreleased]의Added목록에 병합하세요.수정 예시
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 10-10: Multiple headings with the same content
(MD024, no-duplicate-heading)
🤖 Prompt for AI Agents
Source: Linters/SAST tools