mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* AutoTranslate config settings * comment out Agents provider * Add auto translate timeout config validation * i18n messages for autotranslation config validation * fix test * validate url for libreTranslate * Feedback review * Admin Console UI for Auto-Translation * fix admin console conditional section display * i18n * removed unintentional change * update admin.general.localization.autoTranslateProviderDescription newline * fix lint * Fix types * UX feedback review * fix typo in i18n * Fix AutoTranslation feature flag * feedback review * Fix test default values * feedback review * re-add isHidden property to feature discovery * Database Migrations, Indexes and Methods for Auto-Translation * i18n * fix retrylayer and storetest * Fix search query * fix lint * remove the request.CTX and modify Translation model * fix lint and external url * Add settings to playwright * Add empty as a valid value for the Provider * Update jsonb queries * Fix queries and add model methods * fix go lint * go lint fix 2 * fix db migrations * feedback review + store cache * increase migration number * cleanup autotranslation store cache * use NULL as objectType for posts * fix bad merge * fix tests * add missing i18n * Switch prop bags column to boolean * fix lint * fix tests * Remove database search * use Builder methods --------- Co-authored-by: BenCookie95 <[email protected]> Co-authored-by: Hanzo Dev <[email protected]>
99 lines
2.5 KiB
Go
99 lines
2.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"maps"
|
|
)
|
|
|
|
// TranslationType indicates the type of translated content
|
|
type TranslationType string
|
|
|
|
const (
|
|
TranslationTypeString TranslationType = "string"
|
|
TranslationTypeObject TranslationType = "object"
|
|
)
|
|
|
|
// TranslationState represents the state of a translation
|
|
type TranslationState string
|
|
|
|
const (
|
|
TranslationStateReady TranslationState = "ready"
|
|
TranslationStateSkipped TranslationState = "skipped"
|
|
TranslationStateUnavailable TranslationState = "unavailable"
|
|
)
|
|
|
|
// Translation represents a single translation result
|
|
type Translation struct {
|
|
ObjectID string `json:"object_id"`
|
|
ObjectType string `json:"object_type"`
|
|
Lang string `json:"lang"`
|
|
Provider string `json:"provider"`
|
|
Type TranslationType `json:"type"`
|
|
Text string `json:"text"`
|
|
ObjectJSON json.RawMessage `json:"object_json,omitempty"`
|
|
Confidence *float64 `json:"confidence,omitempty"`
|
|
State TranslationState `json:"state"`
|
|
Meta map[string]any `json:"meta,omitempty"`
|
|
NormHash string `json:"norm_hash,omitempty"`
|
|
}
|
|
|
|
func (t *Translation) Clone() *Translation {
|
|
if t == nil {
|
|
return nil
|
|
}
|
|
var confidence *float64
|
|
if t.Confidence != nil {
|
|
val := *t.Confidence
|
|
confidence = &val
|
|
}
|
|
|
|
var meta map[string]any
|
|
if t.Meta != nil {
|
|
meta = make(map[string]any, len(t.Meta))
|
|
maps.Copy(meta, t.Meta)
|
|
}
|
|
var objectJSON json.RawMessage
|
|
if t.ObjectJSON != nil {
|
|
objectJSON = make([]byte, len(t.ObjectJSON))
|
|
copy(objectJSON, t.ObjectJSON)
|
|
}
|
|
return &Translation{
|
|
ObjectID: t.ObjectID,
|
|
ObjectType: t.ObjectType,
|
|
Lang: t.Lang,
|
|
Provider: t.Provider,
|
|
Type: t.Type,
|
|
Text: t.Text,
|
|
ObjectJSON: objectJSON,
|
|
Confidence: confidence,
|
|
State: t.State,
|
|
Meta: meta,
|
|
NormHash: t.NormHash,
|
|
}
|
|
}
|
|
|
|
func (t *Translation) IsValid() bool {
|
|
if t == nil {
|
|
return false
|
|
}
|
|
if t.Provider == "" || t.ObjectID == "" || !IsValidId(t.ObjectID) || t.ObjectType == "" || t.Lang == "" || t.Type == "" || t.State != TranslationStateReady {
|
|
return false
|
|
}
|
|
if t.Type != TranslationTypeString && t.Type != TranslationTypeObject {
|
|
return false
|
|
}
|
|
if t.Type == TranslationTypeString && t.Text == "" {
|
|
return false
|
|
}
|
|
if t.Type == TranslationTypeObject && len(t.ObjectJSON) == 0 {
|
|
return false
|
|
}
|
|
if t.NormHash == "" {
|
|
return false
|
|
}
|
|
return true
|
|
}
|