mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 03:32:52 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f96bc8569 | ||
|
|
9ce4026b1a | ||
|
|
e434b2d26e | ||
|
|
fe7f1a53ae | ||
|
|
907d61b5d2 | ||
|
|
5fb9755841 | ||
|
|
e5dd02eeca | ||
|
|
e7b4a426a9 | ||
|
|
7dd74af305 | ||
|
|
4409101647 |
@@ -37,7 +37,7 @@ audit:
|
|||||||
scheduled-audit:
|
scheduled-audit:
|
||||||
stage: audit
|
stage: audit
|
||||||
script:
|
script:
|
||||||
- npm audit
|
- npm audit --audit-level=high
|
||||||
only:
|
only:
|
||||||
- schedules
|
- schedules
|
||||||
|
|
||||||
|
|||||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
|||||||
|
# [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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add [@sortable](https://gitlab.com/sortable) tags to certain translatable properties ([f5e8856](https://gitlab.com/openstapps/core/commit/f5e88569eb75578febbcde67259c0c14563e53fe))
|
||||||
|
* annotate SCThing uid and url as filterable ([70c1a3e](https://gitlab.com/openstapps/core/commit/70c1a3eaa3d1c88f4b86f0df86d0d362ad1f930c))
|
||||||
|
* Update src/things/book.ts - made ISBN optional ([6060113](https://gitlab.com/openstapps/core/commit/6060113df56b871bb5014a8a961974895e52158f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [0.33.0](https://gitlab.com/openstapps/core/compare/v0.32.0...v0.33.0) (2020-02-11)
|
# [0.33.0](https://gitlab.com/openstapps/core/compare/v0.32.0...v0.33.0) (2020-02-11)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1337
package-lock.json
generated
1337
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@openstapps/core",
|
"name": "@openstapps/core",
|
||||||
"version": "0.34.0",
|
"version": "0.36.0",
|
||||||
"description": "StAppsCore - Generalized model of data",
|
"description": "StAppsCore - Generalized model of data",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Model",
|
"Model",
|
||||||
|
|||||||
@@ -218,15 +218,35 @@ export class SCThingTranslator {
|
|||||||
* All the values will be set to the known translations of the property/key name
|
* All the values will be set to the known translations of the property/key name
|
||||||
* @example
|
* @example
|
||||||
* const translatedMetaDish = translator.translatedPropertyNames<SCCourseOfStudies>(SCThingType.CourseOfStudies);
|
* const translatedMetaDish = translator.translatedPropertyNames<SCCourseOfStudies>(SCThingType.CourseOfStudies);
|
||||||
* @param thing The thing whose property names will be translated
|
* @param type The type whose property names will be translated
|
||||||
* @param language The language all property names will be translated to
|
* @param language The language all property names will be translated to
|
||||||
* @returns An object with the properties of the SCThingType where the values are the known property tranlations
|
* @returns An object with the properties of the SCThingType where the values are the known property tranlations
|
||||||
*/
|
*/
|
||||||
public translatedPropertyNames<T extends SCThing>(thing: T,
|
public translatedPropertyNames<T extends SCThing>(type: SCThingType,
|
||||||
language?: keyof SCTranslations<T>): T | undefined {
|
language?: keyof SCTranslations<T>): T | undefined {
|
||||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
||||||
|
|
||||||
return this.getAllMetaFieldTranslations(thing.type, targetLanguage) as T;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -256,20 +256,30 @@ export class MetaTranslationSpec {
|
|||||||
|
|
||||||
@test
|
@test
|
||||||
public consistencyWithMetaClass() {
|
public consistencyWithMetaClass() {
|
||||||
const dishMetaTranslationsDE = translator.translatedPropertyNames(dish);
|
const dishMetaTranslationsDE = translator.translatedPropertyNames(dish.type);
|
||||||
const dishMetaTranslationsEN = translator.translatedPropertyNames(dish, 'en');
|
const dishMetaTranslationsEN = translator.translatedPropertyNames(dish.type, 'en');
|
||||||
expect(dishMetaTranslationsEN).to.not.deep.equal(dishMetaTranslationsDE);
|
expect(dishMetaTranslationsEN).to.not.deep.equal(dishMetaTranslationsDE);
|
||||||
expect(dishMetaTranslationsDE).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.de);
|
expect(dishMetaTranslationsDE).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.de);
|
||||||
expect(dishMetaTranslationsEN).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.en);
|
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
|
@test
|
||||||
public thingWithoutMetaClass() {
|
public thingWithoutMetaClass() {
|
||||||
const dishCopy = clone(dish);
|
const dishCopy = clone(dish);
|
||||||
const typeNonExistant = eval("(x) => x + 'typeNonExistant';");
|
const typeNonExistant = eval("(x) => x + 'typeNonExistant';");
|
||||||
// this will assign a non existant SCThingType to dishCopy
|
// this will assign a non existant SCThingType to dishCopy
|
||||||
dishCopy.type = typeNonExistant();
|
dishCopy.type = typeNonExistant();
|
||||||
const dishMetaTranslationsDE = translator.translatedPropertyNames(dishCopy);
|
const dishMetaTranslationsDE = translator.translatedPropertyNames(dishCopy.type);
|
||||||
expect(dishMetaTranslationsDE).to.be.undefined;
|
expect(dishMetaTranslationsDE).to.be.undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user