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

Develop #65

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/i18n-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -153,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);

Expand Down Expand Up @@ -210,6 +212,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate
}

functionsContent += `/// ${func.body}\n `;
this.functionNamesMap.set(func.name, func.name);

if (overwrite) {
functionsContent += "@override\n";
Expand All @@ -225,7 +228,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);
Expand Down Expand Up @@ -608,6 +619,8 @@ class I18n implements WidgetsLocalizations {
TextDirection get textDirection => TextDirection.ltr;

{functions}

{functionNamesMap}
}
`;

Expand Down