From e7e53675950dd7e63a7eb2927b085e1cedfa25c2 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 4 Nov 2024 12:21:50 -0500 Subject: [PATCH] added some missing grammar copy --- .../enum/analytics/morph_categories_enum.dart | 127 ++++++++++++++++++ .../enum/analytics/parts_of_speech_enum.dart | 87 ++++++++++++ lib/pangea/enum/construct_type_enum.dart | 14 ++ lib/pangea/utils/get_grammar_copy.dart | 34 ++++- .../analytics_summary/analytics_popup.dart | 18 ++- 5 files changed, 272 insertions(+), 8 deletions(-) create mode 100644 lib/pangea/enum/analytics/morph_categories_enum.dart create mode 100644 lib/pangea/enum/analytics/parts_of_speech_enum.dart diff --git a/lib/pangea/enum/analytics/morph_categories_enum.dart b/lib/pangea/enum/analytics/morph_categories_enum.dart new file mode 100644 index 000000000..6b52055d8 --- /dev/null +++ b/lib/pangea/enum/analytics/morph_categories_enum.dart @@ -0,0 +1,127 @@ +// ignore_for_file: constant_identifier_names + +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; + +enum MorphologicalCategories { + Pos, + AdvType, + Aspect, + Case, + ConjType, + Definite, + Degree, + Evident, + Foreign, + Gender, + Mood, + NounType, + NumForm, + NumType, + Number, + NumberPsor, + Person, + Polarity, + Polite, + Poss, + PrepCase, + PronType, + PunctSide, + PunctType, + Reflex, + Tense, + VerbForm, + VerbType, + Voice, +} + +extension MorphologicalCategoriesExtension on MorphologicalCategories { + /// Convert enum to string + String toShortString() { + return toString().split('.').last; + } + + /// Convert string to enum + static MorphologicalCategories? fromString(String category) { + return MorphologicalCategories.values.firstWhereOrNull( + (e) => e.toShortString() == category, + ); + } + + String getDisplayCopy(BuildContext context) { + switch (this) { + case MorphologicalCategories.Pos: + return L10n.of(context)!.grammarCopyPOS; + case MorphologicalCategories.AdvType: + return L10n.of(context)!.grammarCopyADVTYPE; + case MorphologicalCategories.Aspect: + return L10n.of(context)!.grammarCopyASPECT; + case MorphologicalCategories.Case: + return L10n.of(context)!.grammarCopyCASE; + case MorphologicalCategories.ConjType: + return L10n.of(context)!.grammarCopyCONJTYPE; + case MorphologicalCategories.Definite: + return L10n.of(context)!.grammarCopyDEFINITE; + case MorphologicalCategories.Degree: + return L10n.of(context)!.grammarCopyDEGREE; + case MorphologicalCategories.Evident: + return L10n.of(context)!.grammarCopyEVIDENT; + case MorphologicalCategories.Foreign: + return L10n.of(context)!.grammarCopyFOREIGN; + case MorphologicalCategories.Gender: + return L10n.of(context)!.grammarCopyGENDER; + case MorphologicalCategories.Mood: + return L10n.of(context)!.grammarCopyMOOD; + case MorphologicalCategories.NounType: + return L10n.of(context)!.grammarCopyNOUNTYPE; + case MorphologicalCategories.NumForm: + return L10n.of(context)!.grammarCopyNUMFORM; + case MorphologicalCategories.NumType: + return L10n.of(context)!.grammarCopyNUMTYPE; + case MorphologicalCategories.Number: + return L10n.of(context)!.grammarCopyNUMBER; + case MorphologicalCategories.NumberPsor: + return L10n.of(context)!.grammarCopyNUMBERPSOR; + case MorphologicalCategories.Person: + return L10n.of(context)!.grammarCopyPERSON; + case MorphologicalCategories.Polarity: + return L10n.of(context)!.grammarCopyPOLARITY; + case MorphologicalCategories.Polite: + return L10n.of(context)!.grammarCopyPOLITE; + case MorphologicalCategories.Poss: + return L10n.of(context)!.grammarCopyPOSS; + case MorphologicalCategories.PrepCase: + return L10n.of(context)!.grammarCopyPREPCASE; + case MorphologicalCategories.PronType: + return L10n.of(context)!.grammarCopyPRONTYPE; + case MorphologicalCategories.PunctSide: + return L10n.of(context)!.grammarCopyPUNCTSIDE; + case MorphologicalCategories.PunctType: + return L10n.of(context)!.grammarCopyPUNCTTYPE; + case MorphologicalCategories.Reflex: + return L10n.of(context)!.grammarCopyREFLEX; + case MorphologicalCategories.Tense: + return L10n.of(context)!.grammarCopyTENSE; + case MorphologicalCategories.VerbForm: + return L10n.of(context)!.grammarCopyVERBFORM; + case MorphologicalCategories.VerbType: + return L10n.of(context)!.grammarCopyVERBTYPE; + case MorphologicalCategories.Voice: + return L10n.of(context)!.grammarCopyVOICE; + } + } +} + +String? getMorphologicalCategoryCopy( + String categoryName, + BuildContext context, +) { + final MorphologicalCategories? category = + MorphologicalCategoriesExtension.fromString(categoryName); + + if (category == null) { + return null; + } + return category.getDisplayCopy(context); +} diff --git a/lib/pangea/enum/analytics/parts_of_speech_enum.dart b/lib/pangea/enum/analytics/parts_of_speech_enum.dart new file mode 100644 index 000000000..5348e938b --- /dev/null +++ b/lib/pangea/enum/analytics/parts_of_speech_enum.dart @@ -0,0 +1,87 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; + +enum GrammarCopyPOS { + sconj, + num, + verb, + affix, + part, + adj, + cconj, + punct, + adv, + aux, + space, + sym, + det, + pron, + adp, + propn, + noun, + intj, + x, +} + +extension GrammarCopyPOSExtension on GrammarCopyPOS { + /// Convert enum to string + String toShortString() { + return toString().split('.').last.toLowerCase(); + } + + GrammarCopyPOS? fromString(String categoryName) { + return GrammarCopyPOS.values.firstWhereOrNull( + (pos) => pos.toShortString() == categoryName.toLowerCase(), + ); + } + + String getDisplayCopy(BuildContext context) { + switch (this) { + case GrammarCopyPOS.sconj: + return L10n.of(context)!.grammarCopyPOSsconj; + case GrammarCopyPOS.num: + return L10n.of(context)!.grammarCopyPOSnum; + case GrammarCopyPOS.verb: + return L10n.of(context)!.grammarCopyPOSverb; + case GrammarCopyPOS.affix: + return L10n.of(context)!.grammarCopyPOSaffix; + case GrammarCopyPOS.part: + return L10n.of(context)!.grammarCopyPOSpart; + case GrammarCopyPOS.adj: + return L10n.of(context)!.grammarCopyPOSadj; + case GrammarCopyPOS.cconj: + return L10n.of(context)!.grammarCopyPOScconj; + case GrammarCopyPOS.punct: + return L10n.of(context)!.grammarCopyPOSpunct; + case GrammarCopyPOS.adv: + return L10n.of(context)!.grammarCopyPOSadv; + case GrammarCopyPOS.aux: + return L10n.of(context)!.grammarCopyPOSaux; + case GrammarCopyPOS.space: + return L10n.of(context)!.grammarCopyPOSspace; + case GrammarCopyPOS.sym: + return L10n.of(context)!.grammarCopyPOSsym; + case GrammarCopyPOS.det: + return L10n.of(context)!.grammarCopyPOSdet; + case GrammarCopyPOS.pron: + return L10n.of(context)!.grammarCopyPOSpron; + case GrammarCopyPOS.adp: + return L10n.of(context)!.grammarCopyPOSadp; + case GrammarCopyPOS.propn: + return L10n.of(context)!.grammarCopyPOSpropn; + case GrammarCopyPOS.noun: + return L10n.of(context)!.grammarCopyPOSnoun; + case GrammarCopyPOS.intj: + return L10n.of(context)!.grammarCopyPOSintj; + case GrammarCopyPOS.x: + return L10n.of(context)!.grammarCopyPOSx; + } + } +} + +String? getVocabCategoryName(String category, BuildContext context) { + return GrammarCopyPOS.values + .firstWhereOrNull((pos) => pos.toShortString() == category.toLowerCase()) + ?.getDisplayCopy(context); +} diff --git a/lib/pangea/enum/construct_type_enum.dart b/lib/pangea/enum/construct_type_enum.dart index 2b346b235..19d3641f1 100644 --- a/lib/pangea/enum/construct_type_enum.dart +++ b/lib/pangea/enum/construct_type_enum.dart @@ -1,4 +1,7 @@ import 'package:fluffychat/pangea/constants/analytics_constants.dart'; +import 'package:fluffychat/pangea/enum/analytics/morph_categories_enum.dart'; +import 'package:fluffychat/pangea/enum/analytics/parts_of_speech_enum.dart'; +import 'package:flutter/material.dart'; enum ConstructTypeEnum { grammar, @@ -28,6 +31,17 @@ extension ConstructExtension on ConstructTypeEnum { return AnalyticsConstants.morphUseMaxXP; } } + + String? getDisplayCopy(String category, BuildContext context) { + switch (this) { + case ConstructTypeEnum.morph: + return getMorphologicalCategoryCopy(category, context); + case ConstructTypeEnum.vocab: + return getVocabCategoryName(category, context); + default: + return null; + } + } } class ConstructTypeUtil { diff --git a/lib/pangea/utils/get_grammar_copy.dart b/lib/pangea/utils/get_grammar_copy.dart index cb9996959..cdcdcb3d6 100644 --- a/lib/pangea/utils/get_grammar_copy.dart +++ b/lib/pangea/utils/get_grammar_copy.dart @@ -1,3 +1,5 @@ +// ignore_for_file: constant_identifier_names + import 'dart:developer'; import 'package:fluffychat/pangea/utils/error_handler.dart'; @@ -6,15 +8,19 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; /// Used on morph constructs -String getGrammarCopy({ +String? getGrammarCopy({ required String category, /// This is the tag / feature required String lemma, required BuildContext context, }) { + if (category.toLowerCase() == 'other') { + return null; + } + final String key = - 'grammarCopy${category.toUpperCase()}${lemma.toLowerCase()}'; + 'grammarCopy${category.toUpperCase()}${lemma.replaceAll(",", "").toLowerCase()}'; switch (key) { case 'grammarCopyPOSsconj': @@ -119,8 +125,16 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyNUMBERplur; case 'grammarCopyPRONTYPEnpr': return L10n.of(context)!.grammarCopyPRONTYPEnpr; + case 'grammarCopyPRONTYPEprs': + return L10n.of(context)!.grammarCopyPRONTYPEprs; + case 'grammarCopyPRONTYPEind': + return L10n.of(context)!.grammarCopyPRONTYPEind; case 'grammarCopyPRONTYPEinterrogative': return L10n.of(context)!.grammarCopyPRONTYPEinterrogative; + case 'grammarCopyPRONTYPEart': + return L10n.of(context)!.grammarCopyPRONTYPEart; + case 'grammarCopyPRONTYPEtot': + return L10n.of(context)!.grammarCopyPRONTYPEtot; case 'grammarCopyPOLITEinfm': return L10n.of(context)!.grammarCopyPOLITEinfm; case 'grammarCopyADVTYPEtim': @@ -155,6 +169,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyPRONTYPEdem; case 'grammarCopyPREPCASEpre': return L10n.of(context)!.grammarCopyPREPCASEpre; + case 'grammarCopyPREPCASEnpr': + return L10n.of(context)!.grammarCopyPREPCASEnpr; case 'grammarCopyVERBFORMfin': return L10n.of(context)!.grammarCopyVERBFORMfin; case 'grammarCopyDEGREEpos': @@ -171,6 +187,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyTENSEprs; case 'grammarCopyDEFINITEdef': return L10n.of(context)!.grammarCopyDEFINITEdef; + case 'grammarCopyDEFINITEind': + return L10n.of(context)!.grammarCopyDEFINITEind; case 'grammarCopyNUMTYPEord': return L10n.of(context)!.grammarCopyNUMTYPEord; case 'grammarCopyCASEins': @@ -189,10 +207,14 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyCASErelativeCase; case 'grammarCopyPUNCTTYPEexcl': return L10n.of(context)!.grammarCopyPUNCTTYPEexcl; + case 'rammarCopyPUNCTTYPEperi': + return L10n.of(context)!.grammarCopyPUNCTTYPEperi; case 'grammarCopyPERSON1': return L10n.of(context)!.grammarCopyPERSON1; case 'grammarCopyPUNCTSIDEini': return L10n.of(context)!.grammarCopyPUNCTSIDEini; + case 'grammarCopyPUNCTSIDEfin': + return L10n.of(context)!.grammarCopyPUNCTSIDEfin; case 'grammarCopyGENDERperson': return L10n.of(context)!.grammarCopyGENDERperson; case 'grammarCopyFOREIGNyes': @@ -203,6 +225,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyVERBTYPEverbType; case 'grammarCopyPOSSpass': return L10n.of(context)!.grammarCopyPOSSpass; + case 'grammarCopyPOSSyes': + return L10n.of(context)!.grammarCopyPOSSyes; case 'grammarCopyPREPCASEprepCase': return L10n.of(context)!.grammarCopyPREPCASEprepCase; case 'grammarCopyNUMTYPEnumType': @@ -259,6 +283,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyGENDERcom; case 'grammarCopyREFLEXrflx': return L10n.of(context)!.grammarCopyREFLEXrflx; + case 'grammarCopyREFLEXyes': + return L10n.of(context)!.grammarCopyREFLEXyes; case 'grammarCopyPARTTYPEpar': return L10n.of(context)!.grammarCopyPARTTYPEpar; case 'grammarCopySPCspc': @@ -377,6 +403,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyPRONTYPEexc; case 'grammarCopyPRONTYPErcp': return L10n.of(context)!.grammarCopyPRONTYPErcp; + case 'grammarCopyPRONTYPEintrel': + return L10n.of(context)!.grammarCopyPRONTYPEintrel; case 'grammarCopyPRONTYPEintRelPronType': return L10n.of(context)!.grammarCopyPRONTYPEintRelPronType; case 'grammarCopyTENSEaor': @@ -385,6 +413,8 @@ String getGrammarCopy({ return L10n.of(context)!.grammarCopyTENSEeps; case 'grammarCopyTENSEprosp': return L10n.of(context)!.grammarCopyTENSEprosp; + case 'grammarCopyTENSEimp': + return L10n.of(context)!.grammarCopyTENSEimp; case 'grammarCopyVERBFORMpart': return L10n.of(context)!.grammarCopyVERBFORMpart; case 'grammarCopyVERBFORMconv': diff --git a/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup.dart b/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup.dart index 8870bd7aa..5eda9c97c 100644 --- a/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup.dart +++ b/lib/pangea/widgets/chat_list/analytics_summary/analytics_popup.dart @@ -66,8 +66,13 @@ class AnalyticsPopup extends StatelessWidget { return Column( children: [ ExpansionTile( - // GABBY TODO switch back to getGrammarCopy once it's updated - title: Text(category.key), + title: Text( + category.value.first.constructType.getDisplayCopy( + category.key, + context, + ) ?? + category.key, + ), children: category.value.map((constructUses) { return ConstructUsesXPTile( indicator: indicator, @@ -131,10 +136,11 @@ class ConstructUsesXPTile extends StatelessWidget { title: Text( constructsModel.type == ConstructTypeEnum.morph ? getGrammarCopy( - category: constructUses.category, - lemma: constructUses.lemma, - context: context, - ) + category: constructUses.category, + lemma: constructUses.lemma, + context: context, + ) ?? + constructUses.lemma : constructUses.lemma, ), subtitle: Row(