Skip to content

Commit

Permalink
support localized file info for extension samples
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkettner committed Jan 11, 2024
1 parent 8f1d35e commit cdde058
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .repo/sample-list-generator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ export interface ApiItemWithType extends ApiItem {
}

export interface ManifestData {
[key: string]: string;
name: string;
description: string;
permissions: string[];
}

export interface LocaleData {
[key: string]: {
message: string;
description: string;
};
}

export type SampleItem = {
type: FolderTypes;
name: string;
Expand All @@ -37,4 +45,4 @@ export type ApiTypeResult =
| 'type'
| 'unknown';

export type ExtensionApiMap = Record<string, Record<string, string[]>>
export type ExtensionApiMap = Record<string, Record<string, string[]>>
23 changes: 22 additions & 1 deletion .repo/sample-list-generator/src/utils/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import fs from 'fs/promises';
import { ManifestData } from '../types';
import { dirname } from 'path';
import { ManifestData, LocaleData } from '../types';
const localeRegex = /__MSG_([^_]*)__/

export const getManifest = async (
manifestPath: string
): Promise<ManifestData> => {
const manifest = await fs.readFile(manifestPath, 'utf8');
const parsedManifest = JSON.parse(manifest);

if (manifest.includes('__MSG_')) {
const directory = dirname(manifestPath);
const localeFile: string = await fs.readFile(`${directory}/_locales/en/messages.json`, 'utf8')
const localeData: LocaleData = JSON.parse(localeFile);

for (const [key, value] of Object.entries(parsedManifest)) {
if (typeof value === 'string' && value.startsWith('__MSG_')) {
const localeKey: string | undefined = value.match(localeRegex)?.[1];

if (localeKey) {
const localeKeyData = localeData[localeKey]
const localeMessage: string = localeKeyData?.message;

parsedManifest[key] = localeMessage;
}
}
}
}

return parsedManifest;
};

0 comments on commit cdde058

Please sign in to comment.