forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocLoader.ts
More file actions
44 lines (37 loc) · 1.47 KB
/
LocLoader.ts
File metadata and controls
44 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { loader } from 'webpack';
import { LocalizationPlugin } from '../LocalizationPlugin';
import { ILocalizationFile } from '../interfaces';
import { LocFileParser } from '../utilities/LocFileParser';
import {
loaderFactory,
IBaseLoaderOptions
} from './LoaderFactory';
import { EntityMarker } from '../utilities/EntityMarker';
export interface ILocLoaderOptions extends IBaseLoaderOptions {
pluginInstance: LocalizationPlugin;
}
export default loaderFactory(
function (
this: loader.LoaderContext,
locFilePath: string,
content: string,
options: ILocLoaderOptions
) {
const { pluginInstance } = options;
const locFileData: ILocalizationFile = LocFileParser.parseLocFileFromLoader(content, this);
pluginInstance.addDefaultLocFile(locFilePath, locFileData);
const resultObject: { [stringName: string]: string } = {};
for (const stringName in locFileData) { // eslint-disable-line guard-for-in
const stringKey: string = `${locFilePath}?${stringName}`;
if (pluginInstance.stringKeys.has(stringKey)) {
resultObject[stringName] = pluginInstance.stringKeys.get(stringKey)!.value;
} else {
throw new Error(`Unexpected - missing placeholder for string key "${stringKey}"`);
}
}
EntityMarker.markEntity(this._module, true);
return resultObject;
}
);