SCThingTranslator class

### Hierarchy

- SCThingTranslator

## Index

### Constructors

- constructor

### Properties

- baseLanguage
- deeptranslate
- getAllMetaFieldTranslations
- getMetaClassInstance
- language
- metaClasses
- valueFromPath

### Methods

- getFieldValueTranslation
- translate
- translatedPropertyNames

## Constructors

### constructor

- new SCThingTranslator(language: keyof SCTranslations<SCThing>, baseLanguage?: keyof SCTranslations<SCThing>): SCThingTranslator

- - Defined in node_modules/@openstapps/core/lib/index.d.ts:4208
  constructor
  example

    // returns translator instance for german new SCThingTranslator('de');

  #### Parameters

  - ##### language: keyof SCTranslations<SCThing>

  - ##### Optional baseLanguage: keyof SCTranslations<SCThing>

  #### Returns SCThingTranslator

## Properties

### Private baseLanguage

baseLanguage: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4200

Property representing the translators base language. This means every translation is given for this language.

### Private deeptranslate

deeptranslate: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4224

Get field value translation recursively

param

  Top level object that gets passed through the recursion

param

  The intermediate object / primitive returned by the Proxys get() method

param

  The keypath that (in the end) leads to the translatable property (when added to firstObject)

returns

  an OCType object allowing for access to translations or a translated value(s)

### Private getAllMetaFieldTranslations

getAllMetaFieldTranslations: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4232

Applies only known field translations of the given SCThings meta class to an instance

param

  The type of thing that will be translated

param

  The language the thing property values are translated to

returns

  The thing with all known meta values translated

### Private getMetaClassInstance

getMetaClassInstance: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4239

Returns meta class needed for translations given a SCThingType

param
returns

  An instance of the metaclass

### Private language

language: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4204

Property representing the translators target language

### Private metaClasses

metaClasses: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4208

Property provinding a mapping from a SCThingType to its known own meta class.

### Private valueFromPath

valueFromPath: any

- Defined in node_modules/@openstapps/core/lib/index.d.ts:4251

Returns property value at a certain (key) path of an object.

example

  // returns value of dish.offers[0].inPlace.categories[1] const dish: SCDish = {...}; this.valueFromPath(dish, 'offers[0].inPlace.categories[1]');

param

  Key path to evaluate

param

  Object to evaluate the key path upon

param

  Key path seperation element. Defaults to '.'

returns

  Property value at at key path

## Methods

### getFieldValueTranslation

- getFieldValueTranslation<T>(thing: T, field: SCThingsField): string | string[]

- - Defined in node_modules/@openstapps/core/lib/index.d.ts:4262

  Get field value translation

  example

    // returns translation of the property (if available) in the language defined when creating the translator object const dish: SCDish = {...}; translator.translate(dish, 'offers[0].inPlace.categories[1]');

  #### Type parameters

  - #### T: SCThing

  #### Parameters

  - ##### thing: T

    SCThing to get value translation for

  - ##### field: SCThingsField

    Field to get value translation for (keypath allowed)

  #### Returns string | string[]

  Translated value(s) or value(s) itself

### translate

- translate<T>(data?: T): OCType<T>

- - Defined in node_modules/@openstapps/core/lib/index.d.ts:4276

  Get field value translation recursively

  example

    const dish: SCDish = {...}; translator.translate(dish).offers[0].inPlace.categories1); // or const dishTranslatedAccess = translator.translate(dish); dishTranslatedAccess.offers[0].inPlace.categories1; // undoing the OCType const dishAsBefore: SCDish = dishTranslatedAccess()!;

  #### Type parameters

  - #### T: SCThing

  #### Parameters

  - ##### Optional data: T

    Top level object that gets passed through the recursion

  #### Returns OCType<T>

  an OCType object allowing for access to translations or a translated value(s)

### translatedPropertyNames

- translatedPropertyNames<T>(thing: T, language?: keyof SCTranslations<T>): T | undefined

- - Defined in node_modules/@openstapps/core/lib/index.d.ts:4286

  Given a SCThingType this function returns an object with the same basic structure as the corresponding SCThing. All the values will be set to the known translations of the property/key name.

  example

    const translatedMetaDish = translator.translatedPropertyNames(SCThingType.CourseOfStudies);

  #### Type parameters

  - #### T: SCThing

  #### Parameters

  - ##### thing: T

  - ##### Optional language: keyof SCTranslations<T>

    The language the object is translated to

  #### Returns T | undefined

  An object with the properties of the SCThingType where the values are the known property tranlations

Generated using TypeDoc