Skip to content

Commit

Permalink
fix(nlu): translate system entities (#4617)
Browse files Browse the repository at this point in the history
* fix(nlu): translate system entities

* fixed sly comment

Co-authored-by: Francois-Xavier P. Darveau <955524+EFF@users.noreply.github.com>
  • Loading branch information
ierezell and EFF committed Mar 11, 2021
1 parent 73470a8 commit aaabd6a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
19 changes: 17 additions & 2 deletions modules/nlu/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,23 @@
"noSlotsToTag": "Selection can't be tagged. Define a slot first.",
"save": "Save slot",
"tagSelectionLabel": "Tag selection",
"tagSelectionMessage": "Click on a slot or use numbers as keyboard shortcuts"
"tagSelectionMessage": "Click on a slot or use numbers as keyboard shortcuts",
"names": {
"amountOfMoney": "amountOfMoney",
"distance": "distance",
"duration": "duration",
"email": "email",
"number": "number",
"ordinal": "ordinal",
"phoneNumber": "phoneNumber",
"quantity": "quantity",
"temperature": "temperature",
"time": "time",
"url": "url",
"volume": "volume",
"any": "any"
}
},
"title": "Language Understanding",
"trainNow": "Train now"
}
}
19 changes: 17 additions & 2 deletions modules/nlu/src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,23 @@
"noSlotsToTag": "Selection can't be tagged. Define a slot first.",
"save": "Guardar slot",
"tagSelectionLabel": "Selección de etiquetas",
"tagSelectionMessage": "Haga clic en un slot o use números como métodos abreviados de teclado"
"tagSelectionMessage": "Haga clic en un slot o use números como métodos abreviados de teclado",
"names": {
"amountOfMoney": "Cantidad de dinero",
"distance": "distancia",
"duration": "duración",
"email": "email",
"number": "número",
"ordinal": "ordinal",
"phoneNumber": "teléfono",
"quantity": "cantidad",
"temperature": "temperatura",
"time": "tiempo",
"url": "url",
"volume": "volumen",
"any": "cualquier"
}
},
"title": "Reconocimiento del Lenguaje",
"trainNow": "Entrenar ahora"
}
}
19 changes: 17 additions & 2 deletions modules/nlu/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,23 @@
"noSlotsToTag": "La sélection ne peut pas être marquée. Veuillez créer un paramètre d'abord.",
"save": "Enregistrer",
"tagSelectionLabel": "Marquer la sélection",
"tagSelectionMessage": "Sélectionnez un paramètre ou utilisez les chiffres pour choisir un élément"
"tagSelectionMessage": "Sélectionnez un paramètre ou utilisez les chiffres pour choisir un élément",
"names": {
"amountOfMoney": "Quantité de monnaie",
"distance": "distance",
"duration": "durée",
"email": "email",
"number": "nombre",
"ordinal": "ordinal",
"phoneNumber": "numéro de téléphone",
"quantity": "quantité",
"temperature": "température",
"time": "temps",
"url": "url",
"volume": "volume",
"any": "autre"
}
},
"title": "Compréhension du langage",
"trainNow": "Entraîner maintenant"
}
}
30 changes: 28 additions & 2 deletions modules/nlu/src/views/full/intents/slots/EntitySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ import { MenuItem, Position } from '@blueprintjs/core'
import { ItemRenderer, MultiSelect } from '@blueprintjs/select'
import { lang } from 'botpress/shared'
import React, { FC, useEffect, useState } from 'react'

import { NLUApi } from '../../../../api'
import style from '../style.scss'
import { entityNameInput } from './style.scss'

const SYSTEM_ENTITIES = [
'amountOfMoney',
'distance',
'duration',
'email',
'number',
'ordinal',
'phoneNumber',
'quantity',
'temperature',
'time',
'url',
'volume'
]

interface EntityOption {
type: string
Expand Down Expand Up @@ -41,9 +56,20 @@ export const EntitySelector: FC<Props> = props => {
}
}

const getEntityName = (entity: EntityOption): string => {
let entityName = `${entity.type}.${entity.name}`
const translatedName = lang.tr('module.nlu.slots.names.' + entity.name)

if (SYSTEM_ENTITIES.includes(entity.name) && translatedName !== entity.name) {
entityName += ` (${translatedName})`
}

return entityName
}

const entityItemRenderer: ItemRenderer<EntityOption> = (entity: EntityOption, { handleClick, modifiers }) => (
<MenuItem
text={`${entity.type}.${entity.name}`}
text={getEntityName(entity)}
key={`${entity.name}${entity.type}`}
onClick={handleClick}
active={modifiers.active}
Expand Down

0 comments on commit aaabd6a

Please sign in to comment.