| 41 | } |
| 42 | |
| 43 | export default class InstanceService |
| 44 | extends GlobalEvent |
| 45 | implements IInstanceServiceProps |
| 46 | { |
| 47 | private _config = { |
| 48 | extensions: defaultExtensions.concat(), |
| 49 | defaultLocale: 'en', |
| 50 | }; |
| 51 | |
| 52 | private rendered = false; |
| 53 | |
| 54 | constructor(config: IConfigProps) { |
| 55 | super(); |
| 56 | if (config.defaultLocale) { |
| 57 | this._config.defaultLocale = config.defaultLocale; |
| 58 | } |
| 59 | |
| 60 | if (Array.isArray(config.extensions)) { |
| 61 | this._config.extensions.push(...config.extensions); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | private initialLocaleService = (languagesExts: IExtension[]) => { |
| 66 | const locales = languagesExts.reduce((pre, cur) => { |
| 67 | const languages = cur.contributes?.languages || []; |
| 68 | return pre.concat(languages); |
| 69 | }, [] as ILocale[]); |
| 70 | |
| 71 | molecule.i18n.initialize( |
| 72 | locales, |
| 73 | localStorage.getItem(STORE_KEY) || this._config.defaultLocale |
| 74 | ); |
| 75 | }; |
| 76 | |
| 77 | public getConfig: () => IConfigProps = () => { |
| 78 | return Object.assign({}, this._config); |
| 79 | }; |
| 80 | |
| 81 | public render = (workbench: ReactElement) => { |
| 82 | if (!this.rendered) { |
| 83 | this.emit(InstanceHookKind.beforeInit); |
| 84 | |
| 85 | // get all locales including builtin and custom locales |
| 86 | const [languages, others] = molecule.extension.splitLanguagesExts( |
| 87 | this._config.extensions |
| 88 | ); |
| 89 | this.initialLocaleService(languages); |
| 90 | |
| 91 | const controllers = [ |
| 92 | ActivityBarController, |
| 93 | AuxiliaryController, |
| 94 | EditorController, |
| 95 | /** |
| 96 | * Explorer should called before EditorTreeController, |
| 97 | * @refer https://github.com/DTStack/molecule/issues/829 |
| 98 | */ |
| 99 | ExplorerController, |
| 100 | EditorTreeController, |
nothing calls this directly
no test coverage detected