From 1df2599e6cb322b62b18341c49cc7ea227f73e8a Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 15 Mar 2022 18:45:10 -0400 Subject: [PATCH] Fix regex for localize text --- src/core/configuration/ConfigurationManager.ts | 5 +++++ src/core/configuration/IConfigurationManager.ts | 3 ++- src/nitro/localization/NitroLocalizationManager.ts | 14 +++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/configuration/ConfigurationManager.ts b/src/core/configuration/ConfigurationManager.ts index 00d51724..11145f26 100644 --- a/src/core/configuration/ConfigurationManager.ts +++ b/src/core/configuration/ConfigurationManager.ts @@ -169,4 +169,9 @@ export class ConfigurationManager extends NitroManager implements IConfiguration //@ts-ignore return NitroConfig as { [index: string]: any }; } + + public get definitions(): Map + { + return this._definitions; + } } diff --git a/src/core/configuration/IConfigurationManager.ts b/src/core/configuration/IConfigurationManager.ts index 1d18a8f4..7f9f8165 100644 --- a/src/core/configuration/IConfigurationManager.ts +++ b/src/core/configuration/IConfigurationManager.ts @@ -5,4 +5,5 @@ export interface IConfigurationManager extends INitroManager interpolate(value: string, regex?: RegExp): string; getValue(key: string, value?: T): T; setValue(key: string, value: string): void; -} \ No newline at end of file + definitions: Map; +} diff --git a/src/nitro/localization/NitroLocalizationManager.ts b/src/nitro/localization/NitroLocalizationManager.ts index ed529abc..d18a97be 100644 --- a/src/nitro/localization/NitroLocalizationManager.ts +++ b/src/nitro/localization/NitroLocalizationManager.ts @@ -119,10 +119,22 @@ export class NitroLocalizationManager extends NitroManager implements INitroLoca { if(!key || !key.length) return null; - if(key.startsWith('${')) key = key.substr(2, (key.length - 3)); + const keys = key.match(/\$\{.[^}]*\}/g); + + if(keys && keys.length) + { + for(const splitKey of keys) key = key.replace(splitKey, this.getValue(splitKey.slice(2, -1), doParams)); + } let value = (this._definitions.get(key) || null); + if(!value) + { + value = (Nitro.instance.core.configuration.definitions.get(key) as any); + + if(value) return value; + } + if(value && doParams) { const parameters = this._parameters.get(key);