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

Support Namespace Delimiters and allow vertical bar (|) by default #1207

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion .vscode/i18n-ally-reviews.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
# Review comments generated by i18n-ally. Please commit this file.

{}
reviews:
config.namespace_delimiters:
locales:
de:
translation_candidate:
source: en
text: Namespace-Trennzeichen, standardmäßig [".", ":", "/", "|"]
time: '2024-09-20T05:09:02.785Z'
es:
translation_candidate:
source: en
text: >-
Delimitadores de espacio de nombres, por defecto [".", ":", "/",
"|"]
time: '2024-09-20T05:09:06.483Z'
fr:
translation_candidate:
source: en
text: Délimiteurs d'espace de noms, par défaut [".", ":", "/", "|"]
time: '2024-09-20T05:09:11.454Z'
hu:
translation_candidate:
source: en
text: Névtérhatárolók, alapértelmezés szerint [".", ":", "/", "|"]
time: '2024-09-20T05:09:14.467Z'
ja:
translation_candidate:
source: en
text: 名前空間区切り文字、デフォルトは ["."、":"、"/"、"|"]
time: '2024-09-20T05:09:17.596Z'
ko:
translation_candidate:
source: en
text: '네임스페이스 구분 기호(기본값: [".", ":", "/", "|"])'
time: '2024-09-20T05:09:24.426Z'
nb-NO:
translation_candidate:
source: en
text: Navneområdeskilletegn, som standard er [".", ":", "/", "|"]
time: '2024-09-20T05:09:28.583Z'
nl-NL:
translation_candidate:
source: en
text: >-
Scheidingstekens voor de naamruimte, standaard ingesteld op [".",
static: "/", "|"]
time: '2024-09-20T05:09:31.303Z'
pt-BR:
translation_candidate:
source: en
text: Delimitadores de namespace, padrão para [".", ":", "/", "|"]
time: '2024-09-20T05:09:34.448Z'
ru:
translation_candidate:
source: en
text: Разделители пространства имен, по умолчанию [.", ":", "/", "|"]
time: '2024-09-20T05:09:37.025Z'
sv-SE:
translation_candidate:
source: en
text: Namnområdesavgränsare, som standard är [".", ":", "/", "|"]
time: '2024-09-20T05:09:39.593Z'
th:
translation_candidate:
source: en
text: ตัวคั่นเนมสเปซ มีค่าเริ่มต้นเป็น [".", บาร์, "/", "|"]
time: '2024-09-20T05:09:42.003Z'
tr:
translation_candidate:
source: en
text: Ad alanı sınırlayıcıları, varsayılan olarak [".", ":", "/", "|"]
time: '2024-09-20T05:09:44.776Z'
uk-UA:
translation_candidate:
source: en
text: Роздільники простору імен, за замовчуванням [".", ":", "/", "|"]
time: '2024-09-20T05:09:48.097Z'
zh-CN:
translation_candidate:
source: en
text: 命名空间分隔符,默认为 [".", ":", "/", "|"]
time: '2024-09-20T05:09:51.453Z'
zh-TW:
translation_candidate:
source: en
text: 命名空間分隔符,預設為 [".", ":", "/", "|"]
time: '2024-09-20T05:09:54.556Z'
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"config.locale_country_map": "An object to map two letters locale code to country code",
"config.locales_paths": "Path to locales directory (relative to project root). Glob pattern is also acceptable.",
"config.namespace": "Enable namespaces. Check out the docs for more details.",
"config.namespace_delimiters": "Namespace delimiters, defaulting to [\".\", \":\", \"/\", \"|\"]",
"config.openai_api_key": "OpenAI API key",
"config.openai_api_model": "OpenAI chatgpt model",
"config.openai_api_root": "OpenAI API root URL",
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,13 @@
"type": "string",
"description": "%config.default_namespace%"
},
"i18n-ally.namespaceDelimiters": {
"type": "array",
"item": {
"type": "string"
},
"description": "%config.namespace_delimiters%"
},
"i18n-ally.derivedKeyRules": {
"deprecationMessage": "Deprecated. Use \"i18n-ally.usage.derivedKeyRules\" instead."
},
Expand Down
5 changes: 5 additions & 0 deletions src/core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Config {
'encoding',
'namespace',
'defaultNamespace',
'namespaceDelimiters',
'disablePathParsing',
'readonly',
'languageTagSystem',
Expand Down Expand Up @@ -146,6 +147,10 @@ export class Config {
return this.getConfig<string>('defaultNamespace')
}

static get namespaceDelimiters(): string[] | undefined {
return this.getConfig<string[]>('namespaceDelimiters')
}

static get enabledFrameworks(): string[] | undefined {
let ids = this.getConfig<string | string[]>('enabledFrameworks')
if (!ids || !ids.length)
Expand Down
10 changes: 5 additions & 5 deletions src/utils/Regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export function handleRegexMatch(
text: string,
match: RegExpExecArray,
dotEnding = false,
rewriteContext?: RewriteKeyContext,
scopes: ScopeRange[] = [],
namespaceDelimiters = [':', '/'],
rewriteContext: RewriteKeyContext | undefined,
scopes: ScopeRange[] | undefined,
namespaceDelimiters: string[],
defaultNamespace?: string,
starts: number[] = [],
): KeyInDocument | undefined {
Expand All @@ -23,7 +23,7 @@ export function handleRegexMatch(

const start = match.index + matchString.lastIndexOf(key)
const end = start + key.length
const scope = scopes.find(s => s.start <= start && s.end >= end)
const scope = (scopes ?? []).find(s => s.start <= start && s.end >= end)
const quoted = QUOTE_SYMBOLS.includes(text[start - 1])

const namespace = scope?.namespace || defaultNamespace
Expand Down Expand Up @@ -60,12 +60,12 @@ export function regexFindKeys(
dotEnding = false,
rewriteContext?: RewriteKeyContext,
scopes: ScopeRange[] = [],
namespaceDelimiters?: string[],
): KeyInDocument[] {
if (Config.disablePathParsing)
dotEnding = true

const defaultNamespace = Config.defaultNamespace
const namespaceDelimiters = Config.namespaceDelimiters || ['.', ':', '/', '|']
const keys: KeyInDocument[] = []
const starts: number[] = []

Expand Down