Skip to content

Commit

Permalink
[mob] Extract strings (#3323)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 committed Sep 18, 2024
2 parents 9df36a5 + 038a40b commit f890f61
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 9 deletions.
20 changes: 20 additions & 0 deletions mobile/lib/generated/intl/messages_en.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 161 additions & 0 deletions mobile/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions mobile/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,25 @@
"mlConsentPrivacy": "Please click here for more details about this feature in our privacy policy",
"mlConsentConfirmation": "I understand, and wish to enable machine learning",
"magicSearch": "Magic search",
"discover": "Discover",
"@discover": {
"description": "The text to display for the discover section under which we show receipts, screenshots, sunsets, greenery, etc."
},
"discover_identity": "Identity",
"discover_screenshots": "Screenshots",
"discover_receipts": "Receipts",
"discover_notes": "Notes",
"discover_memes": "Memes",
"discover_visiting_cards": "Visiting Cards",
"discover_babies": "Babies",
"discover_pets": "Pets",
"discover_selfies": "Selfies",
"discover_wallpapers": "Wallpapers",
"discover_food": "Food",
"discover_celebrations": "Celebrations",
"discover_sunset": "Sunset",
"discover_hills": "Hills",
"discover_greenery": "Greenery",
"mlIndexingDescription": "Please note that machine learning will result in a higher bandwidth and battery usage until all items are indexed. Consider using the desktop app for faster indexing, all results will be synced automatically.",
"loadingModel": "Downloading models...",
"waitingForWifi": "Waiting for WiFi...",
Expand Down
4 changes: 2 additions & 2 deletions mobile/lib/models/search/search_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension SectionTypeExtensions on SectionType {
case SectionType.face:
return S.of(context).people;
case SectionType.magic:
return "Discover";
return S.of(context).discover;
case SectionType.moment:
return S.of(context).moments;
case SectionType.location:
Expand Down Expand Up @@ -250,7 +250,7 @@ extension SectionTypeExtensions on SectionType {
case SectionType.face:
return SearchService.instance.getAllFace(limit);
case SectionType.magic:
return SearchService.instance.getMagicSectionResutls();
return SearchService.instance.getMagicSectionResutls(context);

case SectionType.moment:
return SearchService.instance.getRandomMomentsSearchResults(context);
Expand Down
54 changes: 49 additions & 5 deletions mobile/lib/services/magic_cache_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import "dart:io";

import "package:computer/computer.dart";
import "package:flutter/foundation.dart";
import "package:flutter/widgets.dart";
import "package:logging/logging.dart";
import "package:path_provider/path_provider.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/file_uploaded_event.dart";
import "package:photos/events/magic_cache_updated_event.dart";
import "package:photos/extensions/stop_watch.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/ml/discover/prompt.dart";
Expand Down Expand Up @@ -65,7 +67,45 @@ class MagicCache {
}
}

String getLocalizedTitle(BuildContext context, String title) {
switch (title) {
case 'Identity':
return context.l10n.discover_identity;
case 'Screenshots':
return context.l10n.discover_screenshots;
case 'Receipts':
return context.l10n.discover_receipts;
case 'Notes':
return context.l10n.discover_notes;
case 'Memes':
return context.l10n.discover_memes;
case 'Visiting Cards':
return context.l10n.discover_visiting_cards;
case 'Babies':
return context.l10n.discover_babies;
case 'Pets':
return context.l10n.discover_pets;
case 'Selfies':
return context.l10n.discover_selfies;
case 'Wallpapers':
return context.l10n.discover_wallpapers;
case 'Food':
return context.l10n.discover_food;
case 'Celebrations':
return context.l10n.discover_celebrations;
case 'Sunset':
return context.l10n.discover_sunset;
case 'Hills':
return context.l10n.discover_hills;
case 'Greenery':
return context.l10n.discover_greenery;
default:
return title; // If no match, return the original string
}
}

GenericSearchResult? toGenericSearchResult(
BuildContext context,
Prompt prompt,
List<EnteFile> enteFilesInMagicCache,
Map<int, int> fileIdToPositionMap,
Expand All @@ -79,25 +119,26 @@ GenericSearchResult? toGenericSearchResult(
.compareTo(fileIdToPositionMap[b.uploadedFileID!]!);
});
}
final String title = getLocalizedTitle(context, prompt.title);
return GenericSearchResult(
ResultType.magic,
prompt.title,
title,
enteFilesInMagicCache,
params: {
"enableGrouping": prompt.recentFirst,
"fileIdToPosMap": fileIdToPositionMap
"fileIdToPosMap": fileIdToPositionMap,
},
onResultTap: (ctx) {
routeToPage(
ctx,
MagicResultScreen(
enteFilesInMagicCache,
name: prompt.title,
name: title,
enableGrouping: prompt.recentFirst,
fileIdToPosMap: fileIdToPositionMap,
heroTag: GenericSearchResult(
ResultType.magic,
prompt.title,
title,
enteFilesInMagicCache,
).heroTag(),
),
Expand Down Expand Up @@ -255,7 +296,9 @@ class MagicCacheService {
await File(await _getCachePath()).delete();
}

Future<List<GenericSearchResult>> getMagicGenericSearchResult() async {
Future<List<GenericSearchResult>> getMagicGenericSearchResult(
BuildContext context,
) async {
try {
final EnteWatch? w =
kDebugMode ? EnteWatch("magicGenericSearchResult") : null;
Expand Down Expand Up @@ -296,6 +339,7 @@ class MagicCacheService {
}
for (final p in prompts) {
final genericSearchResult = toGenericSearchResult(
context,
p,
magicIdToFiles[p.title] ?? [],
promptFileOrder[p.title] ?? {},
Expand Down
6 changes: 4 additions & 2 deletions mobile/lib/services/search_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ class SearchService {
return searchResults;
}

Future<List<GenericSearchResult>> getMagicSectionResutls() async {
Future<List<GenericSearchResult>> getMagicSectionResutls(
BuildContext context,
) async {
if (localSettings.isMLIndexingEnabled && flagService.internalUser) {
return MagicCacheService.instance.getMagicGenericSearchResult();
return MagicCacheService.instance.getMagicGenericSearchResult(context);
} else {
return <GenericSearchResult>[];
}
Expand Down

0 comments on commit f890f61

Please sign in to comment.