Skip to content
Permalink
Browse files

Applies TS loading strategy to LocalesLoader

  • Loading branch information...
baflo committed Apr 4, 2019
1 parent d32a2d1 commit a2f978eebd7bdb916250437cb0338713a3054265
@@ -4,6 +4,7 @@ version 0.5.0
- adds option to UniferConfiguration that allows to change the way how request extractors are found.
- adds option to pass component's defaultConfiguration a function that returns a new configuration object
- passes list of components to except from autobind to inversify-components
- loads all TypeScript, JavaScript and JSON files from locales directory, if not i18next backend is configured

version 0.4.1
- fixes typing of StayInContextCallback and ClearContextCallback

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -47,6 +47,7 @@
"lodash": "^4.17.11",
"redis": "2.8.0",
"reflect-metadata": "^0.1.12",
"require-directory": "^2.1.1",
"resolve": "^1.8.1",
"rxjs": "^5.5.11"
},
@@ -10,6 +10,7 @@ import * as commander from "commander";
// Import node.js filesystem module
import * as fs from "fs";
import { Component } from "inversify-components";
import * as path from "path";
import { AssistantJSApplicationInitializer } from "./components/joined-interfaces";

// Get package.json data
@@ -63,6 +64,8 @@ export function cli(argv, resolvedApplicationInitializer) {
"config",
"config/locales",
"config/locales/en",
"config/locales/en/translation",
"config/locales/en/utterances",
"spec",
"spec/app",
"spec/app/states",
@@ -104,10 +107,21 @@ export function cli(argv, resolvedApplicationInitializer) {
fs.closeSync(fs.openSync(projectPath + touchableFile, "w"));
});

// Create empty json files
["config/locales/en/translation.json", "config/locales/en/utterances.json"].forEach(filePath => {
// Create base TypesScript files
["config/locales/en/translation/main-state.ts"].forEach(filePath => {
console.log("Creating " + filePath + "..");
fs.writeFileSync(projectPath + filePath, "{}");
fs.writeFileSync(
projectPath + filePath,
`export const ${path.basename(filePath, path.extname(filePath)).replace(/[\-]+([a-z])/gi, (m, c) => c.toUpperCase())} = {};`
);
});

["config/locales/en/utterances/invokeGenericIntent.ts"].forEach(filePath => {
console.log("Creating " + filePath + "..");
fs.writeFileSync(
projectPath + filePath,
`export const ${path.basename(filePath, path.extname(filePath)).replace(/[\-]+([a-z])/gi, (m, c) => c.toUpperCase())} = [];`
);
});
};

@@ -5,6 +5,7 @@ import { arraySplitter } from "./plugins/array-returns-sample.plugin";
import { Configuration } from "./private-interfaces";

import { injectionNames, Logger } from "../../assistant-source";
import { LocalesLoader } from "../unifier/public-interfaces";
import { I18nContext } from "./context";
import { InterpolationResolver as InterpolationResolverImpl } from "./interpolation-resolver";
import { InterpolationResolver, TranslateHelper, TranslateHelperFactory, TranslateValuesFor } from "./public-interfaces";
@@ -37,6 +38,7 @@ export const descriptor: ComponentDescriptor<Configuration.Defaults> = {
return new I18nextWrapper(
context.container.get<Component<Configuration.Runtime>>(getMetaInjectionName("core:i18n")),
context.container.get<Logger>(injectionNames.logger),
context.container.get<LocalesLoader>(injectionNames.localesLoader),
false
);
})
@@ -1,12 +1,18 @@
import * as fs from "fs";
import * as path from "path";

import { Component, getMetaInjectionName } from "inversify-components";
import { Configuration } from "./private-interfaces";

import * as i18next from "i18next";
import * as i18nextBackend from "i18next-sync-fs-backend";
import { inject, injectable, multiInject, optional } from "inversify";
import { inject, injectable } from "inversify";
import { injectionNames } from "../../injection-names";
import { Logger } from "../root/public-interfaces";

import * as requireDir from "require-directory";

import { LocalesLoader } from "../unifier/public-interfaces";
import { TEMPORARY_INTERPOLATION_END, TEMPORARY_INTERPOLATION_START } from "./interpolation-resolver";
import { arraySplitter, processor } from "./plugins/array-returns-sample.plugin";
import { processor as templateProcessor } from "./plugins/parse-template-language.plugin";
@@ -25,6 +31,7 @@ export class I18nextWrapper {
constructor(
@inject(getMetaInjectionName("core:i18n")) componentMeta: Component<Configuration.Runtime>,
@inject(injectionNames.logger) logger: Logger,
@inject(injectionNames.localesLoader) localesLoader: LocalesLoader,
returnOnlySample = true
) {
this.component = componentMeta;
@@ -36,7 +43,10 @@ export class I18nextWrapper {
}

this.instance = Object.assign(Object.create(Object.getPrototypeOf(this.configuration.i18nextInstance)), this.configuration.i18nextInstance);

const i18nextConfiguration = {
// If locales are found in `UnifierConfiguration#utterancePath`, pre-populate resources with them. May be overridden by `I18NConfiguration#backend`.
...{ resources: localesLoader.getLocales() },
...{ initImmediate: false, missingInterpolationHandler: this.onInterpolationMissing.bind(this) },
...this.configuration.i18nextAdditionalConfiguration,
};
Oops, something went wrong.

0 comments on commit a2f978e

Please sign in to comment.
You can’t perform that action at this time.