From 54956ed1055d879ce0a80f7b012edc89120cff3e Mon Sep 17 00:00:00 2001 From: GJS <1353990812@qq.com> Date: Wed, 9 Oct 2019 20:40:15 +0800 Subject: [PATCH 1/2] add functionNamesMap --- src/i18n-generator.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/i18n-generator.ts b/src/i18n-generator.ts index b74d032..a903d89 100644 --- a/src/i18n-generator.ts +++ b/src/i18n-generator.ts @@ -18,6 +18,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate private readonly hello = new Hello(); private readonly varibales = new Variables(); + private readonly functionNamesMap = new Map(); constructor( private workspaceFolder: string, @@ -210,6 +211,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate } functionsContent += `/// ${func.body}\n `; + this.functionNamesMap.set(func.name, func.name); if (overwrite) { functionsContent += "@override\n"; @@ -225,7 +227,15 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate const textDirection = isRtl ? "rtl" : "ltr"; + let functionNamesMap = 'Map get functionMap => {\n'; + this.functionNamesMap.forEach((value, key) => { + functionNamesMap += " "; + functionNamesMap += ` "${key}": ${value},\n`; + }); + functionNamesMap += " };\n"; + let result = template.replace(/{functions}/g, functionsContent); + result = result.replace(/{functionNamesMap}/g, functionNamesMap); result = result.replace(/{locale}/g, this.normalizeLocale(locale)); result = result.replace(/{derived}/g, derived); result = result.replace(/{textDirection}/g, textDirection); @@ -609,6 +619,8 @@ class I18n implements WidgetsLocalizations { TextDirection get textDirection => TextDirection.ltr; {functions} + + {functionNamesMap} } `; From ccdf1f144426ab80acc05561988c5130b58821d4 Mon Sep 17 00:00:00 2001 From: GJS <1353990812@qq.com> Date: Thu, 10 Oct 2019 13:03:40 +0800 Subject: [PATCH 2/2] clear the functionNamesMap before generating code --- src/i18n-generator.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/i18n-generator.ts b/src/i18n-generator.ts index a903d89..a7fd03e 100644 --- a/src/i18n-generator.ts +++ b/src/i18n-generator.ts @@ -154,6 +154,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate const defaultI18n = await this.readI18nFileAsync(config.defaultLocale || "", config); const functions = this.buildFunctionTable(defaultI18n); + this.functionNamesMap.clear(); dartContent += this.generateFunctions(I18nGenerator.dart, "", false, undefined, functions);