s1seven / schema-tools

Tools to create, validate and render certificates using Material Identity JSON schemas
https://materialidentity.org/
Apache License 2.0
1 stars 1 forks source link

feat: load extra translations to generate HTML Certificate #118

Closed getlarge closed 2 years ago

getlarge commented 2 years ago

Description

Is this a BUG REPORT or FEATURE REQUEST ? FEATURE

What you expected to happen : Use the extra translations for external standards provided in the schema repositories (see CAMPUS example in CoA-schema ). Those translations will go beyond the current translations located at the root of schemas repositories that only translates properties known in the schema. They will only be loaded if the standards are declared in the certificate and once loaded, they can be used in the generators (HTML and PDF) by matching the PropertyId value from the certificate to the corresponding Id from a translation object.

export type CampusTranslations = { [key in Languages]?: { Id: string; Property: string; TestConditions?: string }[]; };

export type ExternalStandardsTranslations = {

};

export type ExtraTranslations = { [key in ExternalStandards]?: ExternalStandardsTranslations[key]; };

// once downloaded external standards translations downloaded we would get an object like : const extraTranslations: ExtraTranslations = { CAMPUS: { EN: [{ Id: '38', Property: 'Melt volume-flow rate', TestConditions: 'MVR' },...] }, }; // ... from which we can safely retrieve a given standard translations const campusTranslations: CampusTranslations = t.CAMPUS;



- [x] allow to provide `extraTranslations` from the generator options

- [x] within handlebarsBaseOptions, define a custom helper to handle extraTranslations.
  - This custom helper would use the `CertificateLanguages`, the `PropertyId` and the `<propertyName>` to replace. 
  - if `<propertyName>`  does not exist in the translations, resolve the `<propertyName>`  in the certificate object as fallback

- [x] Edit template.hbs to use the new helper function