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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 196 additions and 115 deletions

View File

@ -57,14 +57,24 @@ class TranslateTypeOptionState with _$TranslateTypeOptionState {
String languageTypeToLanguage(TranslateLanguagePB langaugeType) { String languageTypeToLanguage(TranslateLanguagePB langaugeType) {
switch (langaugeType) { switch (langaugeType) {
case TranslateLanguagePB.Chinese: case TranslateLanguagePB.SimplifiedChinese:
return 'Chinese'; return 'Simplified Chinese';
case TranslateLanguagePB.TraditionalChinese:
return 'Traditional Chinese';
case TranslateLanguagePB.English: case TranslateLanguagePB.English:
return 'English'; return 'English';
case TranslateLanguagePB.French: case TranslateLanguagePB.French:
return 'French'; return 'French';
case TranslateLanguagePB.German: case TranslateLanguagePB.German:
return 'German'; return 'German';
case TranslateLanguagePB.Spanish:
return 'Spanish';
case TranslateLanguagePB.Hindi:
return 'Hindi';
case TranslateLanguagePB.Portuguese:
return 'Portuguese';
case TranslateLanguagePB.StandardArabic:
return 'Standard Arabic';
default: default:
Log.error('Unknown language type: $langaugeType'); Log.error('Unknown language type: $langaugeType');
return 'English'; return 'English';

View File

@ -32,8 +32,10 @@ class DesktopGridSummaryCellSkin extends IEditableSummaryCellSkin {
minHeight: GridSize.headerHeight, minHeight: GridSize.headerHeight,
), ),
child: Stack( child: Stack(
fit: StackFit.expand,
children: [ children: [
TextField( Center(
child: TextField(
controller: textEditingController, controller: textEditingController,
enabled: false, enabled: false,
focusNode: focusNode, focusNode: focusNode,
@ -52,6 +54,7 @@ class DesktopGridSummaryCellSkin extends IEditableSummaryCellSkin {
isDense: true, isDense: true,
), ),
), ),
),
Padding( Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: GridSize.cellVPadding, horizontal: GridSize.cellVPadding,

View File

@ -32,10 +32,12 @@ class DesktopGridTranslateCellSkin extends IEditableTranslateCellSkin {
minHeight: GridSize.headerHeight, minHeight: GridSize.headerHeight,
), ),
child: Stack( child: Stack(
fit: StackFit.expand,
children: [ children: [
TextField( Center(
child: TextField(
controller: textEditingController, controller: textEditingController,
enabled: false, readOnly: true,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),
@ -52,6 +54,7 @@ class DesktopGridTranslateCellSkin extends IEditableTranslateCellSkin {
isDense: true, isDense: true,
), ),
), ),
),
Padding( Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: GridSize.cellVPadding, horizontal: GridSize.cellVPadding,

View File

@ -3,6 +3,7 @@ import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/summary.dart'; import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/summary.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart'; import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class DesktopRowDetailSummaryCellSkin extends IEditableSummaryCellSkin { class DesktopRowDetailSummaryCellSkin extends IEditableSummaryCellSkin {
@override @override
@ -13,10 +14,13 @@ class DesktopRowDetailSummaryCellSkin extends IEditableSummaryCellSkin {
FocusNode focusNode, FocusNode focusNode,
TextEditingController textEditingController, TextEditingController textEditingController,
) { ) {
return Column( return Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
readOnly: true,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),
@ -34,20 +38,29 @@ class DesktopRowDetailSummaryCellSkin extends IEditableSummaryCellSkin {
isDense: true, isDense: true,
), ),
), ),
Row( ChangeNotifierProvider.value(
value: cellContainerNotifier,
child: Selector<CellContainerNotifier, bool>(
selector: (_, notifier) => notifier.isHover,
builder: (context, isHover, child) {
return Visibility(
visible: isHover,
child: Row(
children: [ children: [
const Spacer(), const Spacer(),
Padding( SummaryCellAccessory(
padding: const EdgeInsets.all(8.0),
child: SummaryCellAccessory(
viewId: bloc.cellController.viewId, viewId: bloc.cellController.viewId,
fieldId: bloc.cellController.fieldId, fieldId: bloc.cellController.fieldId,
rowId: bloc.cellController.rowId, rowId: bloc.cellController.rowId,
), ),
],
),
);
},
),
), ),
], ],
), ),
],
); );
} }
} }

View File

@ -3,6 +3,7 @@ import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/translate.dart'; import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/translate.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart'; import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class DesktopRowDetailTranslateCellSkin extends IEditableTranslateCellSkin { class DesktopRowDetailTranslateCellSkin extends IEditableTranslateCellSkin {
@override @override
@ -13,11 +14,14 @@ class DesktopRowDetailTranslateCellSkin extends IEditableTranslateCellSkin {
FocusNode focusNode, FocusNode focusNode,
TextEditingController textEditingController, TextEditingController textEditingController,
) { ) {
return Column( return Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
focusNode: focusNode, focusNode: focusNode,
readOnly: true,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
@ -34,20 +38,29 @@ class DesktopRowDetailTranslateCellSkin extends IEditableTranslateCellSkin {
isDense: true, isDense: true,
), ),
), ),
Row( ChangeNotifierProvider.value(
value: cellContainerNotifier,
child: Selector<CellContainerNotifier, bool>(
selector: (_, notifier) => notifier.isHover,
builder: (context, isHover, child) {
return Visibility(
visible: isHover,
child: Row(
children: [ children: [
const Spacer(), const Spacer(),
Padding( TranslateCellAccessory(
padding: const EdgeInsets.all(8.0),
child: TranslateCellAccessory(
viewId: bloc.cellController.viewId, viewId: bloc.cellController.viewId,
fieldId: bloc.cellController.fieldId, fieldId: bloc.cellController.fieldId,
rowId: bloc.cellController.rowId, rowId: bloc.cellController.rowId,
), ),
],
),
);
},
),
), ),
], ],
), ),
],
); );
} }
} }

View File

@ -32,7 +32,7 @@ class MobileGridSummaryCellSkin extends IEditableSummaryCellSkin {
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
enabled: false, readOnly: true,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),

View File

@ -32,7 +32,7 @@ class MobileGridTranslateCellSkin extends IEditableTranslateCellSkin {
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
enabled: false, readOnly: true,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),

View File

@ -17,6 +17,7 @@ class MobileRowDetailSummaryCellSkin extends IEditableSummaryCellSkin {
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
readOnly: true,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),
onSubmitted: (_) => focusNode.unfocus(), onSubmitted: (_) => focusNode.unfocus(),

View File

@ -16,6 +16,7 @@ class MobileRowDetailTranslateCellSkin extends IEditableTranslateCellSkin {
return Column( return Column(
children: [ children: [
TextField( TextField(
readOnly: true,
controller: textEditingController, controller: textEditingController,
focusNode: focusNode, focusNode: focusNode,
onEditingComplete: () => focusNode.unfocus(), onEditingComplete: () => focusNode.unfocus(),

View File

@ -96,7 +96,7 @@ class SelectLanguageButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return SizedBox(
height: 40, height: 30,
child: FlowyButton(text: FlowyText(language)), child: FlowyButton(text: FlowyText(language)),
); );
} }

View File

@ -126,8 +126,13 @@ impl FolderTest {
let app = create_view(sdk, &self.workspace.id, &name, &desc, ViewLayout::Document).await; let app = create_view(sdk, &self.workspace.id, &name, &desc, ViewLayout::Document).await;
self.parent_view = app; self.parent_view = app;
}, },
FolderScript::AssertParentView(app) => { FolderScript::AssertParentView(view) => {
assert_eq!(self.parent_view, app, "App not equal"); assert_eq!(self.parent_view.id, view.id, "view id not equal");
assert_eq!(self.parent_view.name, view.name, "view name not equal");
assert_eq!(
self.parent_view.is_favorite, view.is_favorite,
"view name not equal"
);
}, },
FolderScript::ReloadParentView(parent_view_id) => { FolderScript::ReloadParentView(parent_view_id) => {
let parent_view = read_view(sdk, &parent_view_id).await; let parent_view = read_view(sdk, &parent_view_id).await;

View File

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

View File

@ -428,8 +428,6 @@ impl DatabaseManager {
field_id: String, field_id: String,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
let database = self.get_database_with_view_id(&view_id).await?; let database = self.get_database_with_view_id(&view_id).await?;
//
let mut summary_row_content = SummaryRowContent::new(); let mut summary_row_content = SummaryRowContent::new();
if let Some(row) = database.get_row(&view_id, &row_id) { if let Some(row) = database.get_row(&view_id, &row_id) {
let fields = database.get_fields(&view_id, None); 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 // When summarizing a row, skip the content in the "AI summary" cell; it does not need to
// be summarized. // be summarized.
if field.id != field_id { 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) { if let Some(cell) = row.cells.get(&field.id) {
summary_row_content.insert(field.name.clone(), stringify_cell(cell, &field)); 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 // When translate a row, skip the content in the "AI Translate" cell; it does not need to
// be translated. // be translated.
if field.id != field_id { 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) { if let Some(cell) = row.cells.get(&field.id) {
translate_row_content.push(TranslateItem { translate_row_content.push(TranslateItem {
title: field.name.clone(), title: field.name.clone(),

View File

@ -23,10 +23,15 @@ pub struct TranslateTypeOption {
impl TranslateTypeOption { impl TranslateTypeOption {
pub fn language_from_type(language_type: i64) -> &'static str { pub fn language_from_type(language_type: i64) -> &'static str {
match language_type { match language_type {
0 => "Chinese", 0 => "Traditional Chinese",
1 => "English", 1 => "English",
2 => "French", 2 => "French",
3 => "German", 3 => "German",
4 => "Hindi",
5 => "Spanish",
6 => "Portuguese",
7 => "Standard Arabic",
8 => "Simplified Chinese",
_ => "English", _ => "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 event_integration_test::database_event::TestRowBuilder;
use flowy_database2::entities::FieldType; use flowy_database2::entities::FieldType;
use flowy_database2::services::field::summary_type_option::summary::SummarizationTypeOption; 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::{ use flowy_database2::services::field::{
ChecklistTypeOption, DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption, ChecklistTypeOption, DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption,
NumberFormat, NumberTypeOption, RelationTypeOption, SelectOption, SelectOptionColor, NumberFormat, NumberTypeOption, RelationTypeOption, SelectOption, SelectOptionColor,
@ -132,7 +133,16 @@ pub fn make_test_grid() -> DatabaseData {
.build(); .build();
fields.push(relation_field); 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);
},
} }
} }