diff --git a/app/Http/Controllers/InvestmentTerritoryController.php b/app/Http/Controllers/InvestmentTerritoryController.php index 52137843..834fffeb 100644 --- a/app/Http/Controllers/InvestmentTerritoryController.php +++ b/app/Http/Controllers/InvestmentTerritoryController.php @@ -18,6 +18,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; class InvestmentTerritoryController extends Controller @@ -78,8 +79,10 @@ class InvestmentTerritoryController extends Controller $query->where('parent_id', $data['parent_id'] ?? '00000000-0000-0000-0000-000000000000'); } if (! empty($data['q'])) { - $term = '%'.addcslashes($data['q'], '%_\\').'%'; - $query->where(fn ($q) => $q->whereRaw('name ILIKE ?', [$term])->orWhereRaw('code ILIKE ?', [$term])->orWhereRaw('source_code ILIKE ?', [$term])); + // Accents are ignored, so «Zambezia» still finds «Zambézia». + $term = '%'.addcslashes(Str::ascii($data['q']), '%_\\').'%'; + $query->where(fn ($q) => $q->whereRaw("translate(lower(name), 'áàâãäåéèêëíìîïóòôõöúùûüçýÿ', 'aaaaaaeeeeiiiiooooouuuucyy') ILIKE ?", [$term]) + ->orWhereRaw('code ILIKE ?', [$term])->orWhereRaw('source_code ILIKE ?', [$term])); } return response()->json($query->orderBy('name')->orderBy('id')->paginate(100, ['id', 'name', 'parent_id', 'location_type', 'source_code'])); diff --git a/app/Http/Controllers/TerritorialRegistryController.php b/app/Http/Controllers/TerritorialRegistryController.php index a6ec1dca..1df982df 100644 --- a/app/Http/Controllers/TerritorialRegistryController.php +++ b/app/Http/Controllers/TerritorialRegistryController.php @@ -72,7 +72,9 @@ class TerritorialRegistryController extends Controller } if (! empty($data['q'])) { $term = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $data['q']).'%'; + $plain = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], Str::ascii($data['q'])).'%'; $query->where(fn ($q) => $q->where('g.name', 'ilike', $term)->orWhere('g.code', 'ilike', $term) + ->orWhereRaw("translate(lower(g.name), 'áàâãäåéèêëíìîïóòôõöúùûüçýÿ', 'aaaaaaeeeeiiiiooooouuuucyy') ILIKE ?", [$plain]) ->orWhereExists(fn ($n) => $n->selectRaw('1')->from('geo_names')->whereColumn('geo_location_id', 'g.id')->where('name', 'ilike', $term))); } foreach (['parent_id', 'country_id', 'province_id', 'district_id', 'admin_post_id'] as $key) { diff --git a/database/migrations/2026_12_05_090000_zambezia_accented_province_name.php b/database/migrations/2026_12_05_090000_zambezia_accented_province_name.php new file mode 100644 index 00000000..08f55b41 --- /dev/null +++ b/database/migrations/2026_12_05_090000_zambezia_accented_province_name.php @@ -0,0 +1,21 @@ +where('location_type', 'province')->where('name', 'Zambezia')->update(['name' => 'Zambézia']); + } + + public function down(): void + { + DB::table('geo_locations')->where('location_type', 'province')->where('name', 'Zambézia')->update(['name' => 'Zambezia']); + } +}; diff --git a/resources/js/components/investment-territory.tsx b/resources/js/components/investment-territory.tsx index 4bfba658..01eaaa74 100644 --- a/resources/js/components/investment-territory.tsx +++ b/resources/js/components/investment-territory.tsx @@ -67,8 +67,14 @@ export function ProvinceSelect({ 'Não foi possível consultar a correspondência cartográfica.', ); const data = await response.json(); + // Saved text keeps its spelling; «Zambezia» and «Zambézia» are the same province. + const plain = (text: string) => + text + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLocaleLowerCase('pt'); const matches = (data.data as Option[]).filter( - (option) => option.name === value, + (option) => plain(option.name) === plain(value), ); if (controller.signal.aborted) return; if (matches.length === 1 && !data.next_page_url) diff --git a/resources/js/components/tempo-brand.tsx b/resources/js/components/tempo-brand.tsx index 7a52f96e..bc9868b2 100644 --- a/resources/js/components/tempo-brand.tsx +++ b/resources/js/components/tempo-brand.tsx @@ -151,7 +151,7 @@ const menuTranslations = [ 'Manifestaciones de interés y favoritos', ], ['Notificações', 'Notifications', 'Notifications', 'Notificaciones'], - ['A minha atividade', 'My activity', 'Mes activités', 'Mi actividad'], + ['A minha actividade', 'My activity', 'Mes activités', 'Mi actividad'], [ 'As minhas parcerias', 'My partnerships', @@ -186,7 +186,7 @@ const translations: Record> = { 'Siga a Revista Tempo para actualizações exclusivas.': 'Follow Revista Tempo for exclusive updates.', 'Número de registo': 'Registration number', - 'A minha conta e atividade': 'My account and activity', + 'A minha conta e actividade': 'My account and activity', 'Área de trabalho': 'Workspace', }, fr: { @@ -211,7 +211,7 @@ const translations: Record> = { 'Siga a Revista Tempo para actualizações exclusivas.': 'Suivez Revista Tempo pour des actualités exclusives.', 'Número de registo': 'Numéro d’enregistrement', - 'A minha conta e atividade': 'Mon compte et mes activités', + 'A minha conta e actividade': 'Mon compte et mes activités', 'Área de trabalho': 'Espace de travail', }, es: { @@ -236,7 +236,7 @@ const translations: Record> = { 'Siga a Revista Tempo para actualizações exclusivas.': 'Siga Revista Tempo para recibir novedades exclusivas.', 'Número de registo': 'Número de registro', - 'A minha conta e atividade': 'Mi cuenta y actividad', + 'A minha conta e actividade': 'Mi cuenta y actividad', 'Área de trabalho': 'Área de trabajo', }, }; diff --git a/resources/js/lib/portal-navigation.ts b/resources/js/lib/portal-navigation.ts index 3cbbdd92..d8e1ab85 100644 --- a/resources/js/lib/portal-navigation.ts +++ b/resources/js/lib/portal-navigation.ts @@ -791,7 +791,7 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] { ? [ { id: 'personal-activity', - label: 'A minha atividade', + label: 'A minha actividade', children: [ link( 'my-partnerships', diff --git a/tests/Feature/InvestmentTerritoryTest.php b/tests/Feature/InvestmentTerritoryTest.php index 6d749601..20c0a03f 100644 --- a/tests/Feature/InvestmentTerritoryTest.php +++ b/tests/Feature/InvestmentTerritoryTest.php @@ -375,6 +375,22 @@ class InvestmentTerritoryTest extends TestCase $this->assertDatabaseHas('sectors', ['name' => 'Mineração']); } + public function test_zambezia_is_spelled_with_its_accent_and_found_with_or_without_it(): void + { + // Mapa de erros: «Zambézia» as written across the portal; searches typed without the accent still find it. + $id = (string) Str::uuid(); + DB::table('geo_locations')->insert(['id' => $id, 'code' => $id, 'name' => 'Zambezia', 'location_type' => 'province', 'parent_id' => null]); + (include database_path('migrations/2026_12_05_090000_zambezia_accented_province_name.php'))->up(); + $this->assertSame('Zambézia', DB::table('geo_locations')->where('id', $id)->value('name')); + $user = User::factory()->create(); + config(['portal.managers' => [$user->email]]); + $this->actingAsWithMfa($user); + $this->actingAs($user); + foreach (['Zambezia', 'zambézia', 'ZAMBEZ'] as $typed) { + $this->getJson('/management/territory-options?type=province&q='.urlencode($typed))->assertOk()->assertJsonPath('data.0.id', $id); + } + } + private function location(string $type, ?string $parent = null): string { $id = (string) Str::uuid(); diff --git a/tests/Feature/PortfolioOpportunityAcceptanceTest.php b/tests/Feature/PortfolioOpportunityAcceptanceTest.php index d93a3122..f18aa11c 100644 --- a/tests/Feature/PortfolioOpportunityAcceptanceTest.php +++ b/tests/Feature/PortfolioOpportunityAcceptanceTest.php @@ -49,7 +49,7 @@ final class PortfolioOpportunityAcceptanceTest extends TestCase public function test_province_does_not_promote_unsited_opportunities_or_fiches_from_another_province(): void { $geography = app(InvestmentGeography::class); - $zambezia = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Zambezia')->value('id'); + $zambezia = $geography->publicReferences()->where('location_type', 'province')->whereIn('name', ['Zambézia', 'Zambezia'])->value('id'); $maputo = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Maputo Província')->value('id'); $mocuba = InvestmentPortfolioController::visible()->where('title', 'Construção da Cidadela Parlamentar de Mocuba')->firstOrFail(); foreach ([[$zambezia, true], [$maputo, false]] as [$province, $expected]) {