π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Search countries by native names
laurenspriem74f77e01b08d
diff --git a/mobile/apps/photos/changes/location-search.md b/mobile/apps/photos/changes/location-search.mdindex 065d55d3a2..6b89082ff9 100644--- a/mobile/apps/photos/changes/location-search.md+++ b/mobile/apps/photos/changes/location-search.md@@ -1 +1 @@-- Added country-name search and improved city matching for locations and memories.+- Added country-name search in the app language and each country's native languages, and improved city matching for locations and memories.diff --git a/mobile/apps/photos/lib/services/location_service.dart b/mobile/apps/photos/lib/services/location_service.dartindex e449cac074..92214ab2bb 100644--- a/mobile/apps/photos/lib/services/location_service.dart+++ b/mobile/apps/photos/lib/services/location_service.dart@@ -15,6 +15,7 @@ import "package:photos/models/local_entity_data.dart";import "package:photos/models/location/location.dart";import 'package:photos/models/location_tag/location_tag.dart';import "package:photos/service_locator.dart";+import "package:photos/services/native_country_locales.dart";import "package:photos/src/rust/api/location_api.dart" as rust;const double earthRadius = 6371; // Earth's radius in kilometers@@ -108,12 +109,9 @@ class LocationService {if (index == null) return {};final names = _countryNames[locale] ??= await CountryNamesClient.get(locale,+ nativeLocales: nativeCountryLocales,);- final normalizedQuery = query.toLowerCase();- final matchingCodes = names.names.entries- .where((entry) => entry.value.toLowerCase().contains(normalizedQuery))- .map((entry) => entry.key)- .toSet();+ final matchingCodes = names.matchingCodes(query);if (matchingCodes.isEmpty) return {};final files = allFiles.where((file) => file.hasLocation).toList();final groups = await index.groupCountries(diff --git a/mobile/apps/photos/lib/services/native_country_locales.dart b/mobile/apps/photos/lib/services/native_country_locales.dartnew file mode 100644index 0000000000..ca8c4209bf--- /dev/null+++ b/mobile/apps/photos/lib/services/native_country_locales.dart@@ -0,0 +1,311 @@+const Map<String, List<String>> nativeCountryLocales = {+ 'AD': ['ca'],+ 'AE': ['ar'],+ 'AF': ['fa', 'ps', 'tk', 'uz-Arab'],+ 'AG': ['en'],+ 'AI': ['en'],+ 'AL': ['sq'],+ 'AM': ['hy'],+ 'AO': ['pt'],+ 'AR': ['es'],+ 'AS': ['en', 'sm'],+ 'AT': ['de', 'hr', 'hu', 'sl'],+ 'AU': ['en'],+ 'AW': ['nl', 'pap'],+ 'AX': ['sv'],+ 'AZ': ['az', 'az-Cyrl'],+ 'BA': ['bs', 'bs-Cyrl', 'hr', 'sr', 'sr-Latn'],+ 'BB': ['en'],+ 'BD': ['bn'],+ 'BE': ['de', 'fr', 'nl'],+ 'BF': ['fr'],+ 'BG': ['bg'],+ 'BH': ['ar'],+ 'BI': ['en', 'fr', 'rn'],+ 'BJ': ['fr'],+ 'BL': ['fr'],+ 'BM': ['en'],+ 'BN': ['ms', 'ms-Arab'],+ 'BO': ['ay', 'es', 'qu'],+ 'BQ': ['nl'],+ 'BR': ['pt', 'vec'],+ 'BS': ['en'],+ 'BT': ['dz'],+ 'BW': ['en', 'tn'],+ 'BY': ['be', 'ru'],+ 'BZ': ['en'],+ 'CA': ['chp', 'crk', 'den', 'dgr', 'en', 'fr', 'gwi', 'iu', 'iu-Latn'],+ 'CC': ['en'],+ 'CD': ['fr', 'kg', 'ln', 'lua', 'sw'],+ 'CF': ['fr', 'sg'],+ 'CG': ['fr'],+ 'CH': ['de', 'fr', 'gsw', 'it', 'rm'],+ 'CI': ['fr'],+ 'CK': ['en'],+ 'CL': ['es'],+ 'CM': ['en', 'fr'],+ 'CN': ['bo', 'ko', 'mn-Mong', 'ug', 'za', 'zh'],+ 'CO': ['es'],+ 'CQ': ['en'],+ 'CR': ['es'],+ 'CU': ['es'],+ 'CV': ['pt'],+ 'CW': ['nl', 'pap'],+ 'CX': ['en'],+ 'CY': ['el', 'tr'],+ 'CZ': ['cs'],+ 'DE': ['de'],+ 'DG': ['en'],+ 'DJ': ['ar', 'fr'],+ 'DK': ['da', 'de', 'kl'],+ 'DM': ['en'],+ 'DO': ['es'],+ 'DZ': ['ar', 'fr'],+ 'EA': ['es'],+ 'EC': ['es', 'qu'],+ 'EE': ['et'],+ 'EG': ['ar'],+ 'EH': ['ar'],+ 'ER': ['ar', 'en', 'ti'],+ 'ES': ['ast', 'ca', 'es', 'eu', 'gl', 'oc'],+ 'ET': ['am'],+ 'FI': ['fi', 'sms', 'sv'],+ 'FJ': ['en', 'fj', 'hif'],+ 'FK': ['en'],+ 'FM': ['en'],+ 'FO': ['fo'],+ 'FR': ['fr'],+ 'GA': ['fr'],+ 'GB': ['cy', 'en', 'ga', 'gd'],+ 'GD': ['en'],+ 'GE': ['ab', 'ka', 'os'],+ 'GF': ['fr'],+ 'GG': ['en'],+ 'GH': ['ak', 'ee', 'en', 'gaa'],+ 'GI': ['en'],+ 'GL': ['kl'],+ 'GM': ['en'],+ 'GN': ['fr'],+ 'GP': ['fr'],+ 'GQ': ['es', 'fr', 'pt'],+ 'GR': ['el'],+ 'GS': ['en'],+ 'GT': ['caa', 'cak', 'es', 'ixl', 'quc', 'quv', 'usp', 'xin'],+ 'GU': ['ch', 'en'],+ 'GW': ['pt'],+ 'GY': ['en'],+ 'HK': ['en', 'zh-Hant'],+ 'HN': ['es'],+ 'HR': ['hr', 'it', 'vec'],+ 'HT': ['fr', 'ht'],+ 'HU': ['hu'],+ 'IC': ['es'],+ 'ID': ['id'],+ 'IE': ['en', 'ga'],+ 'IL': ['ar', 'he'],+ 'IM': ['en', 'gv'],+ 'IN': [+ 'as',+ 'bn',+ 'en',+ 'gu',+ 'hi',+ 'kha',+ 'kn',+ 'kok',+ 'ks',+ 'mai',+ 'ml',+ 'mr',+ 'ne',+ 'or',+ 'pa',+ 'sa',+ 'sat',+ 'sd',+ 'sd-Deva',+ 'ta',+ 'te',+ 'ur',+ ],+ 'IO': ['en'],+ 'IQ': ['ar', 'az-Arab', 'ckb'],+ 'IR': ['fa'],+ 'IS': ['is'],+ 'IT': ['fr', 'it', 'vec'],+ 'JE': ['en'],+ 'JM': ['en'],+ 'JO': ['ar'],+ 'JP': ['ja'],+ 'KE': ['en', 'sw'],+ 'KG': ['ky', 'ru'],+ 'KH': ['km'],+ 'KI': ['en', 'gil'],+ 'KM': ['ar', 'fr', 'wni', 'zdj'],+ 'KN': ['en'],+ 'KP': ['ko'],+ 'KR': ['ko'],+ 'KW': ['ar'],+ 'KY': ['en'],+ 'KZ': ['kk', 'ru'],+ 'LA': ['lo'],+ 'LB': ['ar'],+ 'LC': ['en'],+ 'LI': ['de', 'gsw'],+ 'LK': ['si', 'ta'],+ 'LR': ['en'],+ 'LS': ['en', 'st'],+ 'LT': ['lt'],+ 'LU': ['de', 'fr', 'lb'],+ 'LV': ['lv'],+ 'LY': ['ar'],+ 'MA': ['ar', 'fr', 'tzm'],+ 'MC': ['fr'],+ 'MD': ['ro'],+ 'ME': ['sr-Latn'],+ 'MF': ['fr'],+ 'MG': ['en', 'fr', 'mg'],+ 'MH': ['en', 'mh'],+ 'MK': ['mk', 'sq'],+ 'ML': ['fr'],+ 'MM': ['my'],+ 'MN': ['mn'],+ 'MO': ['pt', 'yue', 'zh-Hant'],+ 'MP': ['en'],+ 'MQ': ['fr'],+ 'MR': ['ar'],+ 'MS': ['en'],+ 'MT': ['en', 'mt'],+ 'MU': ['en', 'fr'],+ 'MV': ['dv'],+ 'MW': ['en', 'ny'],+ 'MX': ['es'],+ 'MY': ['ms'],+ 'MZ': ['pt'],+ 'NA': ['en'],+ 'NC': ['fr'],+ 'NE': ['fr'],+ 'NF': ['en'],+ 'NG': ['en', 'yo'],+ 'NI': ['es'],+ 'NL': ['fy', 'nl'],+ 'NO': ['nb', 'nn', 'no', 'se'],+ 'NP': ['ne'],+ 'NR': ['en', 'na'],+ 'NU': ['en', 'niu'],+ 'NZ': ['en', 'mi'],+ 'OM': ['ar'],+ 'PA': ['es'],+ 'PE': ['es', 'qu'],+ 'PF': ['fr', 'ty'],+ 'PG': ['en', 'ho', 'tpi'],+ 'PH': ['ceb', 'en', 'fil', 'hil', 'ilo', 'mdh', 'pag', 'tsg', 'war'],+ 'PK': ['en', 'ur'],+ 'PL': ['csb', 'de', 'lt', 'pl'],+ 'PM': ['fr'],+ 'PN': ['en'],+ 'PR': ['en', 'es'],+ 'PS': ['ar'],+ 'PT': ['pt'],+ 'PW': ['en', 'pau'],+ 'PY': ['es', 'gn'],+ 'QA': ['ar'],+ 'RE': ['fr'],+ 'RO': ['ro'],+ 'RS': ['hr', 'hu', 'ro', 'sk', 'sr', 'sr-Latn', 'uk'],+ 'RU': [+ 'ady',+ 'av',+ 'az-Cyrl',+ 'ba',+ 'bua',+ 'ce',+ 'inh',+ 'kbd',+ 'koi',+ 'krc',+ 'kum',+ 'kv',+ 'lbe',+ 'lez',+ 'mdf',+ 'myv',+ 'ru',+ 'sah',+ 'tt',+ 'tyv',+ 'udm',+ ],+ 'RW': ['en', 'fr', 'rw'],+ 'SA': ['ar'],+ 'SB': ['en'],+ 'SC': ['en', 'fr'],+ 'SD': ['ar', 'en'],+ 'SE': ['fi', 'sv'],+ 'SG': ['en', 'ms', 'ta', 'zh'],+ 'SH': ['en'],+ 'SI': ['sl', 'vec'],+ 'SJ': ['nb'],+ 'SK': ['sk'],+ 'SL': ['en'],+ 'SM': ['it'],+ 'SN': [+ 'bjt',+ 'bsc',+ 'dyo',+ 'ff',+ 'fr',+ 'knf',+ 'mey-Latn',+ 'mfv',+ 'sav',+ 'snf',+ 'srr',+ 'tnr',+ 'wo',+ ],+ 'SO': ['ar', 'so'],+ 'SR': ['nl'],+ 'SS': ['en'],+ 'ST': ['pt'],+ 'SV': ['es'],+ 'SX': ['en', 'nl'],+ 'SY': ['ar'],+ 'SZ': ['en', 'ss'],+ 'TC': ['en'],+ 'TD': ['ar', 'fr'],+ 'TG': ['fr'],+ 'TH': ['th'],+ 'TJ': ['tg'],+ 'TK': ['en', 'tkl'],+ 'TL': ['pt', 'tet'],+ 'TM': ['tk'],+ 'TN': ['ar', 'fr'],+ 'TO': ['en', 'to'],+ 'TR': ['tr'],+ 'TT': ['en'],+ 'TV': ['en', 'tvl'],+ 'TW': ['hak-Hant', 'nan-Hant', 'zh-Hant'],+ 'TZ': ['en', 'sw'],+ 'UA': ['ru', 'uk'],+ 'UG': ['en', 'sw'],+ 'UM': ['en'],+ 'US': ['en', 'es', 'haw'],+ 'UY': ['es'],+ 'UZ': ['uz', 'uz-Cyrl'],+ 'VA': ['it'],+ 'VC': ['en'],+ 'VE': ['es'],+ 'VG': ['en'],+ 'VI': ['en'],+ 'VN': ['vi'],+ 'VU': ['bi', 'en', 'fr'],+ 'WF': ['fr'],+ 'WS': ['en', 'sm'],+ 'XK': ['sq', 'sr', 'sr-Latn'],+ 'YE': ['ar'],+ 'YT': ['fr'],+ 'ZA': ['af', 'en', 'nr', 'nso', 'ss', 'st', 'tn', 'ts', 've', 'xh', 'zu'],+ 'ZM': ['en'],+ 'ZW': ['en', 'nd', 'sn'],+};diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/country/CountryNamesService.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/country/CountryNamesService.ktindex 72831213fc..e8257ab92d 100644--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/country/CountryNamesService.kt+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/country/CountryNamesService.kt@@ -5,16 +5,27 @@ import java.util.Localedata class CountryNames(val region: String?,val names: Map<String, String>,+ val nativeNames: Map<String, List<String>>,)class CountryNamesService {- fun names(localeTag: String): CountryNames {+ fun names(+ localeTag: String,+ nativeLocales: Map<String, List<String>>,+ ): CountryNames {val displayLocale = Locale.forLanguageTag(localeTag)return CountryNames(Locale.getDefault().country.ifEmpty { null },Locale.getISOCountries().associateWith { code ->Locale.Builder().setRegion(code).build().getDisplayCountry(displayLocale)},+ nativeLocales.mapValues { (code, localeTags) ->+ val country = Locale.Builder().setRegion(code).build()+ localeTags+ .map { country.getDisplayCountry(Locale.forLanguageTag(it)) }+ .filter { it.isNotEmpty() }+ .distinct()+ },)}}diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/CountryNamesChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/CountryNamesChannelAdapter.ktindex 5b82482736..0abaf5ea20 100644--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/CountryNamesChannelAdapter.kt+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/CountryNamesChannelAdapter.kt@@ -17,10 +17,20 @@ internal class CountryNamesChannelAdapter : MethodChannel.MethodCallHandler {override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) =when (call.method) {"get" -> {- val locale = call.arguments as? String+ val arguments = call.arguments as? Map<*, *>+ ?: return result.error("invalid_arguments", "Expected country name arguments", null)+ val locale = arguments["locale"] as? String?: return result.error("invalid_locale", "Expected a locale identifier", null)- val names = service.names(locale)- result.success(mapOf("region" to names.region, "names" to names.names))+ val nativeLocales = parseNativeLocales(arguments["nativeLocales"])+ ?: return result.error("invalid_native_locales", "Expected native country locales", null)+ val names = service.names(locale, nativeLocales)+ result.success(+ mapOf(+ "region" to names.region,+ "names" to names.names,+ "nativeNames" to names.nativeNames,+ ),+ )}else -> result.notImplemented()@@ -28,6 +38,17 @@ internal class CountryNamesChannelAdapter : MethodChannel.MethodCallHandler {fun detach() = channel.setMethodCallHandler(null)+ private fun parseNativeLocales(value: Any?): Map<String, List<String>>? {+ val map = value as? Map<*, *> ?: return null+ val result = mutableMapOf<String, List<String>>()+ for ((code, localeValues) in map) {+ if (code !is String || localeValues !is List<*>) return null+ val locales = localeValues.map { it as? String ?: return null }+ result[code] = locales+ }+ return result+ }+private companion object {const val CHANNEL = "io.ente.photos.platform/country_names"}diff --git a/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/CountryNamesChannelAdapter.swift b/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/CountryNamesChannelAdapter.swiftindex a75031c8ae..25bed11018 100644--- a/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/CountryNamesChannelAdapter.swift+++ b/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/CountryNamesChannelAdapter.swift@@ -15,12 +15,20 @@ final class CountryNamesChannelAdapter {result(FlutterMethodNotImplemented)return}- guard let locale = call.arguments as? String else {+ guard let arguments = call.arguments as? [String: Any] else {+ result(FlutterError(code: "invalid_arguments", message: "Expected country name arguments", details: nil))+ return+ }+ guard let locale = arguments["locale"] as? String else {result(FlutterError(code: "invalid_locale", message: "Expected a locale identifier", details: nil))return}- let names = service.names(localeIdentifier: locale)- result(["region": names.region, "names": names.names])+ guard let nativeLocales = arguments["nativeLocales"] as? [String: [String]] else {+ result(FlutterError(code: "invalid_native_locales", message: "Expected native country locales", details: nil))+ return+ }+ let names = service.names(localeIdentifier: locale, nativeLocales: nativeLocales)+ result(["region": names.region, "names": names.names, "nativeNames": names.nativeNames])}}diff --git a/mobile/apps/photos/plugins/ente_photos_platform/ios/Sources/PhotosPlatformCore/CountryNamesService.swift b/mobile/apps/photos/plugins/ente_photos_platform/ios/Sources/PhotosPlatformCore/CountryNamesService.swiftindex 9abab296b5..1c3e987db5 100644--- a/mobile/apps/photos/plugins/ente_photos_platform/ios/Sources/PhotosPlatformCore/CountryNamesService.swift+++ b/mobile/apps/photos/plugins/ente_photos_platform/ios/Sources/PhotosPlatformCore/CountryNamesService.swift@@ -3,12 +3,16 @@ import Foundationpublic struct CountryNames: Sendable {public let region: String?public let names: [String: String]+ public let nativeNames: [String: [String]]}public struct CountryNamesService {public init() {}- public func names(localeIdentifier: String) -> CountryNames {+ public func names(+ localeIdentifier: String,+ nativeLocales: [String: [String]]+ ) -> CountryNames {let locale = Locale(identifier: localeIdentifier)return CountryNames(region: Locale.current.regionCode,@@ -16,6 +20,17 @@ public struct CountryNamesService {uniqueKeysWithValues: Locale.isoRegionCodes.compactMap { code inlocale.localizedString(forRegionCode: code).map { (code, $0) }})+ ),+ nativeNames: Dictionary(+ uniqueKeysWithValues: nativeLocales.map { code, localeIdentifiers in+ (+ code,+ localeIdentifiers.compactMap { localeIdentifier in+ Locale(identifier: localeIdentifier).localizedString(forRegionCode: code)+ }+ )+ }+ ))}}diff --git a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/country_names.dart b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/country_names.dartindex febcdc3de1..f9b6355ad9 100644--- a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/country_names.dart+++ b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/country_names.dart@@ -1,10 +1,30 @@import 'package:flutter/services.dart';class CountryNames {- const CountryNames({required this.region, required this.names});+ const CountryNames({+ required this.region,+ required this.names,+ required this.nativeNames,+ });final String? region;final Map<String, String> names;+ final Map<String, List<String>> nativeNames;++ Set<String> matchingCodes(String query) {+ final normalizedQuery = query.toLowerCase();+ return names.entries+ .where(+ (entry) =>+ entry.value.toLowerCase().contains(normalizedQuery) ||+ (nativeNames[entry.key]?.any(+ (name) => name.toLowerCase().contains(normalizedQuery),+ ) ??+ false),+ )+ .map((entry) => entry.key)+ .toSet();+ }}class CountryNamesClient {@@ -12,14 +32,21 @@ class CountryNamesClient {'io.ente.photos.platform/country_names',);- static Future<CountryNames> get(String locale) async {- final result = await _channel.invokeMapMethod<String, dynamic>(- 'get',- locale,- );+ static Future<CountryNames> get(+ String locale, {+ required Map<String, List<String>> nativeLocales,+ }) async {+ final result = await _channel.invokeMapMethod<String, dynamic>('get', {+ 'locale': locale,+ 'nativeLocales': nativeLocales,+ });return CountryNames(region: result!['region'] as String?,names: (result['names'] as Map).cast<String, String>(),+ nativeNames: (result['nativeNames'] as Map).map(+ (code, names) =>+ MapEntry(code as String, (names as List).cast<String>()),+ ),);}}