Compare commits

..

6 Commits

Author SHA1 Message Date
Sebastian Lange
2f96bc8569 0.36.0 2020-07-16 11:37:56 +02:00
Rainer Killinger
9ce4026b1a build: lower npm audit vulnerabilities 2020-07-01 08:00:26 +00:00
Rainer Killinger
e434b2d26e test: add tests for translatedThingType function 2020-07-01 08:00:26 +00:00
Rainer Killinger
fe7f1a53ae feat: add function to get translated SCThingType 2020-07-01 08:00:26 +00:00
Frank Nagel
907d61b5d2 ci: Change 'npm audit' failure behaviour
The audit fails only if the results include a vulnerability with a level of
at least 'high' in scheduled pipelines.
2020-06-19 13:12:14 +02:00
Rainer Killinger
5fb9755841 docs: update changelog 2020-05-13 11:59:43 +02:00
6 changed files with 946 additions and 429 deletions

View File

@@ -37,7 +37,7 @@ audit:
scheduled-audit:
stage: audit
script:
- npm audit
- npm audit --audit-level=high
only:
- schedules

View File

@@ -1,3 +1,7 @@
# [0.35.0](https://gitlab.com/openstapps/core/compare/v0.34.0...v0.35.0) (2020-05-13)
# [0.34.0](https://gitlab.com/openstapps/core/compare/v0.33.0...v0.34.0) (2020-04-21)

1337
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@openstapps/core",
"version": "0.35.0",
"version": "0.36.0",
"description": "StAppsCore - Generalized model of data",
"keywords": [
"Model",

View File

@@ -229,6 +229,26 @@ export class SCThingTranslator {
return this.getAllMetaFieldTranslations(type, targetLanguage) as T;
}
/**
* Given a SCThingType this function will translate it
*
* @param type The type that will be translated
* @param language The language the type will be translated to
* @returns Known translation of type parameter
*/
public translatedThingType<T extends unknown>(type: SCThingType,
language?: keyof SCTranslations<T>): string {
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
const metaClass = this.getMetaClassInstance(type);
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
typeof metaClass.fieldValueTranslations[targetLanguage].type !== 'undefined') {
return metaClass.fieldValueTranslations[targetLanguage].type as string ;
}
return type;
}
/**
* Recursively translates the given object in-place
* Translated values overwrite current values (destructive)

View File

@@ -263,6 +263,16 @@ export class MetaTranslationSpec {
expect(dishMetaTranslationsEN).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.en);
}
@test
public retrieveTranslatedThingType() {
const dishTypeDE = translator.translatedThingType(dish.type);
const dishTypeEN = translator.translatedThingType(dish.type, 'en');
const dishTypeBASE = translatorWithFallback.translatedThingType(dish.type);
expect(dishTypeDE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.de.type);
expect(dishTypeEN).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
expect(dishTypeBASE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
}
@test
public thingWithoutMetaClass() {
const dishCopy = clone(dish);