chore: support more language (#5522)

* chore: support more language

* chore: adjust ui
This commit is contained in:
Nathan.fooo
2024-06-12 23:17:57 +08:00
committed by GitHub
parent 4708c0f779
commit f1a4deb459
15 changed files with 196 additions and 115 deletions

View File

@ -30,20 +30,30 @@ impl From<TranslateTypeOptionPB> for TranslateTypeOption {
#[derive(Clone, Debug, Copy, ProtoBuf_Enum, Default)]
#[repr(i64)]
pub enum TranslateLanguagePB {
Chinese = 0,
TraditionalChinese = 0,
#[default]
English = 1,
French = 2,
German = 3,
Hindi = 4,
Spanish = 5,
Portuguese = 6,
StandardArabic = 7,
SimplifiedChinese = 8,
}
impl From<i64> for TranslateLanguagePB {
fn from(data: i64) -> Self {
match data {
0 => TranslateLanguagePB::Chinese,
0 => TranslateLanguagePB::TraditionalChinese,
1 => TranslateLanguagePB::English,
2 => TranslateLanguagePB::French,
3 => TranslateLanguagePB::German,
4 => TranslateLanguagePB::Hindi,
5 => TranslateLanguagePB::Spanish,
6 => TranslateLanguagePB::Portuguese,
7 => TranslateLanguagePB::StandardArabic,
8 => TranslateLanguagePB::SimplifiedChinese,
_ => TranslateLanguagePB::English,
}
}

View File

@ -428,8 +428,6 @@ impl DatabaseManager {
field_id: String,
) -> FlowyResult<()> {
let database = self.get_database_with_view_id(&view_id).await?;
//
let mut summary_row_content = SummaryRowContent::new();
if let Some(row) = database.get_row(&view_id, &row_id) {
let fields = database.get_fields(&view_id, None);
@ -437,6 +435,10 @@ impl DatabaseManager {
// When summarizing a row, skip the content in the "AI summary" cell; it does not need to
// be summarized.
if field.id != field_id {
// Don't summarize the summary field.
if field.field_type == FieldType::Summary as i64 {
continue;
}
if let Some(cell) = row.cells.get(&field.id) {
summary_row_content.insert(field.name.clone(), stringify_cell(cell, &field));
}
@ -480,6 +482,11 @@ impl DatabaseManager {
// When translate a row, skip the content in the "AI Translate" cell; it does not need to
// be translated.
if field.id != field_id {
// Don't translate the translate field.
if field.field_type == FieldType::Translate as i64 {
continue;
}
if let Some(cell) = row.cells.get(&field.id) {
translate_row_content.push(TranslateItem {
title: field.name.clone(),

View File

@ -23,10 +23,15 @@ pub struct TranslateTypeOption {
impl TranslateTypeOption {
pub fn language_from_type(language_type: i64) -> &'static str {
match language_type {
0 => "Chinese",
0 => "Traditional Chinese",
1 => "English",
2 => "French",
3 => "German",
4 => "Hindi",
5 => "Spanish",
6 => "Portuguese",
7 => "Standard Arabic",
8 => "Simplified Chinese",
_ => "English",
}
}

View File

@ -6,6 +6,7 @@ use crate::database::mock_data::{COMPLETED, FACEBOOK, GOOGLE, PAUSED, PLANNED, T
use event_integration_test::database_event::TestRowBuilder;
use flowy_database2::entities::FieldType;
use flowy_database2::services::field::summary_type_option::summary::SummarizationTypeOption;
use flowy_database2::services::field::translate_type_option::translate::TranslateTypeOption;
use flowy_database2::services::field::{
ChecklistTypeOption, DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption,
NumberFormat, NumberTypeOption, RelationTypeOption, SelectOption, SelectOptionColor,
@ -132,7 +133,16 @@ pub fn make_test_grid() -> DatabaseData {
.build();
fields.push(relation_field);
},
FieldType::Translate => {},
FieldType::Translate => {
let type_option = TranslateTypeOption {
auto_fill: false,
language_type: 0,
};
let translate_field = FieldBuilder::new(field_type, type_option)
.name("AI translate")
.build();
fields.push(translate_field);
},
}
}