mirror of
https://github.com/leon-ai/leon.git
synced 2025-01-04 15:55:58 +03:00
refactor(server): rename lang helper methods
This commit is contained in:
parent
8d3aee8da7
commit
713ece380b
@ -84,7 +84,7 @@ export default () =>
|
||||
/**
|
||||
* Training phases
|
||||
*/
|
||||
const shortLangs = LANG.getShortLanguages()
|
||||
const shortLangs = LANG.getShortCodes()
|
||||
for (let h = 0; h < shortLangs.length; h += 1) {
|
||||
const lang = shortLangs[h]
|
||||
|
||||
|
@ -160,7 +160,7 @@ class Brain {
|
||||
// Ask to repeat if Leon is not sure about the request
|
||||
if (
|
||||
obj.classification.confidence <
|
||||
langs[LANG.getLongLanguageCode(this._lang)].min_confidence
|
||||
langs[LANG.getLongCode(this._lang)].min_confidence
|
||||
) {
|
||||
if (!opts.mute) {
|
||||
const speech = `${this.wernicke('random_not_sure')}.`
|
||||
|
@ -539,7 +539,7 @@ class Nlu {
|
||||
}
|
||||
}
|
||||
|
||||
const isSupportedLanguage = LANG.getShortLanguages().includes(locale)
|
||||
const isSupportedLanguage = LANG.getShortCodes().includes(locale)
|
||||
if (!isSupportedLanguage) {
|
||||
this.brain.talk(
|
||||
`${this.brain.wernicke('random_language_not_supported')}.`,
|
||||
@ -558,7 +558,7 @@ class Nlu {
|
||||
|
||||
if (intent === 'None') {
|
||||
const fallback = this.fallback(
|
||||
langs[LANG.getLongLanguageCode(locale)].fallbacks
|
||||
langs[LANG.getLongCode(locale)].fallbacks
|
||||
)
|
||||
|
||||
if (fallback === false) {
|
||||
|
@ -28,9 +28,9 @@ class Lang {
|
||||
|
||||
/**
|
||||
* Get short language codes
|
||||
* @example getShortLanguages() // ["en", "fr"]
|
||||
* @example getShortCodes() // ["en", "fr"]
|
||||
*/
|
||||
public getShortLanguages(): ShortLanguageCode[] {
|
||||
public getShortCodes(): ShortLanguageCode[] {
|
||||
const longLanguages = Object.keys(langs) as LongLanguageCode[]
|
||||
|
||||
return longLanguages.map((lang) => langs[lang].short)
|
||||
@ -38,15 +38,15 @@ class Lang {
|
||||
|
||||
/**
|
||||
* Get long language code of the given short language code
|
||||
* @param shortLanguageCode The short language code of the language
|
||||
* @example getLongLanguageCode('en') // en-US
|
||||
* @param shortCode The short language code of the language
|
||||
* @example getLongCode('en') // en-US
|
||||
*/
|
||||
public getLongLanguageCode(shortLanguageCode: ShortLanguageCode) {
|
||||
public getLongCode(shortCode: ShortLanguageCode) {
|
||||
for (const longLanguage in langs) {
|
||||
const longLanguageType = longLanguage as LongLanguageCode
|
||||
const lang = langs[longLanguageType]
|
||||
|
||||
if (lang.short === shortLanguageCode) {
|
||||
if (lang.short === shortCode) {
|
||||
return longLanguageType
|
||||
}
|
||||
}
|
||||
@ -56,13 +56,11 @@ class Lang {
|
||||
|
||||
/**
|
||||
* Get short language code of the given long language code
|
||||
* @param longLanguageCode The long language code of the language
|
||||
* @example getShortLanguageCode('en-US') // en
|
||||
* @param longCode The long language code of the language
|
||||
* @example getShortCode('en-US') // en
|
||||
*/
|
||||
public getShortLanguageCode(
|
||||
longLanguageCode: LongLanguageCode
|
||||
): ShortLanguageCode {
|
||||
return langs[longLanguageCode].short
|
||||
public getShortCode(longCode: LongLanguageCode): ShortLanguageCode {
|
||||
return langs[longCode].short
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { Spinner } from 'cli-spinner'
|
||||
|
||||
import { LOG } from '@/helpers/log'
|
||||
|
||||
function randomNumber(min: number, max: number): number {
|
||||
function randomNumber(min: number, max: number) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import server from '@/core/http-server/server'
|
||||
process.title = 'leon'
|
||||
|
||||
global.tcpServerProcess = spawn(
|
||||
`pipenv run python bridges/python/tcp_server/main.py ${LANG.getShortLanguageCode(
|
||||
`pipenv run python bridges/python/tcp_server/main.py ${LANG.getShortCode(
|
||||
LEON_LANG
|
||||
)}`,
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ class Tts {
|
||||
|
||||
// Dynamically attribute the synthesizer
|
||||
this.synthesizer = require(`${__dirname}/${this.provider}/synthesizer`) // eslint-disable-line global-require
|
||||
this.synthesizer.default.init(LANG.getLongLanguageCode(this.lang))
|
||||
this.synthesizer.default.init(LANG.getLongCode(this.lang))
|
||||
|
||||
this.onSaved()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user