Compare commits

..

4 Commits

Author SHA1 Message Date
Sebastian Lange
f97e199bb9 0.31.0 2019-11-14 11:04:28 +01:00
Rainer Killinger
abda5cf0ca fix: translator can now handle enum translations 2019-11-11 14:46:49 +01:00
Rainer Killinger
9658f05d31 fix: remove categories from custom translations 2019-11-11 14:46:49 +01:00
Wieland Schöbl
e92bf6f7c7 docs: update changelog 2019-11-08 11:07:38 +01:00
7 changed files with 46 additions and 17 deletions

View File

@@ -1,3 +1,13 @@
# [0.30.0](https://gitlab.com/openstapps/core/compare/v0.29.0...v0.30.0) (2019-11-08)
### Features
* add aggregatable tag for type field ([443cb74](https://gitlab.com/openstapps/core/commit/443cb74))
* add new field sequenceIndex to message ([01f92ba](https://gitlab.com/openstapps/core/commit/01f92ba))
# [0.29.0](https://gitlab.com/openstapps/core/compare/v0.28.0...v0.29.0) (2019-09-17)

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "@openstapps/core",
"version": "0.30.0",
"version": "0.31.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

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

View File

@@ -62,10 +62,6 @@ export interface SCThingWithCategories<T, U extends SCThingWithCategoriesSpecifi
*/
export interface SCThingWithCategoriesTranslatableProperties
extends SCThingTranslatableProperties {
/**
* translations of the categories of a thing with categories
*/
categories?: string[];
}
/**

View File

@@ -146,8 +146,8 @@ export class SCThingTranslator {
* Applies known field value translations of the given SCThings meta class to an instance
* Translated values overwrite current values inplace (destructive)
*
* @param language The language the thing is translated to
* @param thing The thing that will be translated
* @param instance The thing / object that will be translated
* @param language The language the thing / object is translated to
* @returns The thing with translated meta field values
*/
private replaceAvailableMetaFieldValueTranslations(instance: any,
@@ -159,13 +159,18 @@ export class SCThingTranslator {
if (typeof metaClass.fieldValueTranslations[language] !== 'undefined') {
Object.keys(metaClass.fieldValueTranslations[language])
.forEach((key) => {
if (metaClass.fieldValueTranslations[language][key] instanceof Object) {
if (metaClass.fieldValueTranslations[language][key] instanceof Object
&& (instance as any)[key] instanceof Object) {
// Assigns known translations of subproperties to property in given language (e.g. categories)
Object.keys((instance as any)[key])
.forEach((subKey) => {
(instance as any)[key][subKey] =
metaClass.fieldValueTranslations[language][key][(instance as any)[key][subKey]];
});
} else if (metaClass.fieldValueTranslations[language][key] instanceof Object
&& typeof (instance as any)[key] === 'string') {
// Assigns known translations of enum to property in given language (e.g. SCSettingInputType)
(instance as any)[key] = metaClass.fieldValueTranslations[language][key][(instance as any)[key]];
} else {
// Assigns property to known translation of fieldValueTranslations in given language
(instance as any)[key] = metaClass.fieldValueTranslations[language][key];
@@ -213,8 +218,8 @@ export class SCThingTranslator {
* All the values will be set to the known translations of the property/key name
* @example
* const translatedMetaDish = translator.translatedPropertyNames<SCCourseOfStudies>(SCThingType.CourseOfStudies);
* @param language The language the object is translated to
* @param thingType Type of the thing
* @param thing The thing whose property names will be translated
* @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
*/
public translatedPropertyNames<T extends SCThing>(thing: T,
@@ -228,8 +233,8 @@ export class SCThingTranslator {
* Recursively translates the given object in-place
* Translated values overwrite current values (destructive)
*
* @param language The language the thing is translated to
* @param thing The thing that will be translated
* @param instance The thing / object that will be translated
* @param language The language the thing / object is translated to
* @returns The thing translated
*/
public translateWholeThingDestructively(instance: any,

View File

@@ -16,7 +16,6 @@
},
"translations": {
"de": {
"categories": ["Benutzer"],
"description": "Die Sprache in der die App angezeigt wird.",
"name": "Sprache",
"values": [
@@ -25,9 +24,6 @@
]
},
"en": {
"categories": [
"User"
],
"description": "The language this app is going to use.",
"name": "Language",
"values": [

View File

@@ -18,6 +18,7 @@ import {slow, suite, test, timeout} from 'mocha-typescript';
import {SCThingOriginType, SCThingType} from '../src/things/abstract/thing';
import {SCBuildingWithoutReferences} from '../src/things/building';
import {SCDish, SCDishMeta} from '../src/things/dish';
import {SCSetting, SCSettingInputType} from '../src/things/setting';
import {SCThingTranslator} from '../src/translator';
const building: SCBuildingWithoutReferences = {
@@ -86,6 +87,23 @@ const dish: SCDish = {
uid: '540862f3-ea30-5b8f-8678-56b4dc217140',
};
const setting: SCSetting = {
categories: ['profile'],
defaultValue: 'student',
description: 'base-description',
inputType: SCSettingInputType.SingleChoice,
name: 'group',
order: 1,
origin: {
indexed: '2018-11-11T14:30:00Z',
name: 'Dummy',
type: SCThingOriginType.Remote,
},
type: SCThingType.Setting,
uid: '2c97aa36-4aa2-43de-bc5d-a2b2cb3a530e',
values: ['student', 'employee', true, 42],
};
const translator = new SCThingTranslator('de');
// tslint:disable-next-line:no-eval
const languageNonExistant = eval("'jp'");
@@ -95,6 +113,10 @@ const translatorWithFallback = new SCThingTranslator(languageNonExistant);
// tslint:disable:member-ordering TranslationSpecInplace
@suite(timeout(10000), slow(5000))
export class TranslationSpecInplace {
@test
public directEnumSingleValue () {
expect(translator.translate(setting).inputType()).to.equal('einfache Auswahl');
}
@test
public directStringLiteralType() {