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

feat: add schema validation for localization files #12537

Merged
merged 7 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: add localization file validation
  • Loading branch information
anchenyi committed Oct 14, 2024
commit 94ceeec43fc9dce6395ad611b45240e3d10ba85a
3 changes: 3 additions & 0 deletions packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
"_error.appstudio.BotProvisionReturnsForbiddenResult.comment": "This is to describe API call, no need to translate 'Botframework'.",
"error.appstudio.BotProvisionReturnsConflictResult": "Botframework provisioning returns conflict result when attempting to create bot registration.",
"_error.appstudio.BotProvisionReturnsConflictResult.comment": "This is to describe API call, no need to translate 'Botframework'.",
"error.appstudio.localizationFile.pathNotDefined": "Localization file not found. Path: %s.",
"error.appstudio.localizationFile.validationFailed": "Localization file validation failed. File: %s. Error:\n%s",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"error.appstudio.localizationFile.validationException": "Localization file validation failed with exceptions. File: %s. Error: %s",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"error.generator.ScaffoldLocalTemplateError": "Unable to scaffold template based on local zip package.",
"error.generator.TemplateNotFoundError": "Unable to find template: %s.",
"error.generator.SampleNotFoundError": "Unable to find sample: %s.",
Expand Down
80 changes: 79 additions & 1 deletion packages/fx-core/src/component/driver/teamsApp/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Result, FxError, ok, err, Platform, ManifestUtil, Colors } from "@microsoft/teamsfx-api";
import {
Result,
FxError,
ok,
err,
Platform,
ManifestUtil,
Colors,
TeamsAppManifest,
UserError,
} from "@microsoft/teamsfx-api";
Fixed Show fixed Hide fixed
import { hooks } from "@feathersjs/hooks/lib";
import { Service } from "typedi";
import { EOL } from "os";
Expand Down Expand Up @@ -337,4 +347,72 @@ export class ValidateManifestDriver implements StepDriver {
}
return ok(undefined);
}

private async validateLocalizatoinFiles(
args: ValidateManifestArgs,
context: WrapDriverContext,
manifest: TeamsAppManifest
): Promise<Result<any, FxError>> {
const errors: string[] = [];
const additionalLanguages = manifest.localizationInfo?.additionalLanguages;
if (!additionalLanguages || additionalLanguages.length == 0) {
return ok(undefined);
}
for (const language of additionalLanguages) {
const filePath = language?.file;
if (!filePath) {
return err(
AppStudioResultFactory.UserError(
AppStudioError.ValidationFailedError.name,
AppStudioError.ValidationFailedError.message([
getLocalizedString("error.appstudio.localizationFile.pathNotDefined", filePath),
]),
HelpLinks.WhyNeedProvision
)
);
}
const localizationFileDir = path.dirname(
getAbsolutePath(args.manifestPath, context.projectPath)
);
const localizationFilePath = getAbsolutePath(filePath, localizationFileDir);
const manifestRes = await manifestUtils.getManifestV3(localizationFilePath, context);
if (manifestRes.isErr()) {
return err(manifestRes.error);
}
const localizationFile = manifestRes.value;
try {
const validationRes = await ManifestUtil.validateManifest(localizationFile);
if (validationRes.length > 0) {
return err(
AppStudioResultFactory.UserError(
AppStudioError.ValidationFailedError.name,
AppStudioError.ValidationFailedError.message([
getLocalizedString(
"error.appstudio.localizationFile.validationFailed",
filePath,
validationRes.join(EOL)
),
]),
HelpLinks.WhyNeedProvision
)
);
}
} catch (e: any) {
return err(
AppStudioResultFactory.UserError(
AppStudioError.ValidationFailedError.name,
AppStudioError.ValidationFailedError.message([
getLocalizedString(
"error.appstudio.localizationFile.validationException",
filePath,
e.message
),
]),
HelpLinks.WhyNeedProvision
)
);
}
}
return ok(undefined);
}
}