Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/core/l10n/translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@

const Map<String, Map<String, String>> appTranslations = {
'en': {
// Desktop search interface.
'desktop_search_remove_recent': 'Remove',
'desktop_search_songs_artists_albums_playlists': 'Songs, artists, albums, playlists…',
'desktop_search_recently_searched': 'Recently Searched',
'desktop_search_browse_categories': 'Browse Categories',
'desktop_search_top_result': 'Top Result',
'desktop_search_playlist': 'Playlist',
'desktop_search_search_failed': 'Search failed',
'desktop_search_no_results': 'No results',
'desktop_search_check_your_connection_and_try_again': 'Check your connection and try again.',
'desktop_search_try_a_different_artist_album_or_track': 'Try a different artist, album or track.',
'desktop_search_song_1_s': 'Song · %1\$s',
'desktop_search_album_1_s': 'Album · %1\$s',
'desktop_search_hip_hop_rap': 'Hip-Hop/Rap',
'desktop_search_pop': 'Pop',
'desktop_search_r_b': 'R&B',
'desktop_search_electronic': 'Electronic',
'desktop_search_rock': 'Rock',
'desktop_search_jazz': 'Jazz',
'desktop_search_indie': 'Indie',
'desktop_search_k_pop': 'K-Pop',
'desktop_search_latin': 'Latin',
'desktop_search_classical': 'Classical',
'desktop_search_country': 'Country',
'desktop_search_afrobeats': 'Afrobeats',
'desktop_search_charts': 'Charts',
'desktop_search_chill': 'Chill',
'desktop_search_workout': 'Workout',
'performance_mode': 'Performance Mode',
'performance_mode_desc_on': 'Active — Running in smooth, low-resource mode.',
'performance_mode_desc_off': 'Optimizes graphics, blurs, and background tasks for smooth playback.',
Expand Down Expand Up @@ -2674,6 +2702,34 @@ const Map<String, Map<String, String>> appTranslations = {
'noResults': 'Sonuç bulunamadı',
},
'zh-CN': {
// Desktop search interface.
'desktop_search_remove_recent': '移除',
'desktop_search_songs_artists_albums_playlists': '搜索歌曲、歌手、专辑或歌单…',
'desktop_search_recently_searched': '最近搜索',
'desktop_search_browse_categories': '浏览分类',
'desktop_search_top_result': '最佳匹配',
'desktop_search_playlist': '歌单',
'desktop_search_search_failed': '搜索失败',
'desktop_search_no_results': '没有搜索结果',
'desktop_search_check_your_connection_and_try_again': '请检查网络连接后重试。',
'desktop_search_try_a_different_artist_album_or_track': '试试搜索其他歌手、专辑或歌曲。',
'desktop_search_song_1_s': '歌曲 · %1\$s',
'desktop_search_album_1_s': '专辑 · %1\$s',
'desktop_search_hip_hop_rap': '嘻哈/说唱',
'desktop_search_pop': '流行',
'desktop_search_r_b': '节奏布鲁斯',
'desktop_search_electronic': '电子',
'desktop_search_rock': '摇滚',
'desktop_search_jazz': '爵士',
'desktop_search_indie': '独立音乐',
'desktop_search_k_pop': '韩国流行',
'desktop_search_latin': '拉丁',
'desktop_search_classical': '古典',
'desktop_search_country': '乡村',
'desktop_search_afrobeats': 'Afrobeats(非洲流行)',
'desktop_search_charts': '排行榜',
'desktop_search_chill': '轻松惬意',
'desktop_search_workout': '运动健身',
'performance_mode': '性能模式',
'performance_mode_desc_on': '已开启 — 正以流畅、低资源占用模式运行。',
'performance_mode_desc_off': '优化图形、模糊效果和后台任务,让播放更流畅。',
Expand Down
113 changes: 63 additions & 50 deletions lib/ui/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../theme/wave_icons.dart';
import '../../app/track_actions.dart'
show formatDuration, playGenerated;
import '../../core/artwork/artwork_cache.dart';
import '../../core/l10n/app_localizations.dart';
import '../../core/audio/stream_models.dart';
import '../../core/storage/prefs.dart';
import '../../features/feed/feed_repository.dart';
Expand Down Expand Up @@ -73,22 +74,22 @@ final waveSearchPreviewProvider = FutureProvider.autoDispose
return ref.watch(searchRepositoryProvider).previewForQuery(q.trim());
});

const _browseCategories = <({String name, Color tint, String query})>[
(name: 'Hip-Hop/Rap', tint: Color(0xFFC45C1A), query: 'hip hop'),
(name: 'Pop', tint: Color(0xFFC45A88), query: 'pop'),
(name: 'R&B', tint: Color(0xFF7A4FC4), query: 'r&b soul'),
(name: 'Electronic', tint: Color(0xFF1A8A8A), query: 'electronic'),
(name: 'Rock', tint: Color(0xFFB03A4A), query: 'rock'),
(name: 'Jazz', tint: Color(0xFF2E6B8A), query: 'jazz'),
(name: 'Indie', tint: Color(0xFF3D8A62), query: 'indie'),
(name: 'K-Pop', tint: Color(0xFFC44A7A), query: 'k-pop'),
(name: 'Latin', tint: Color(0xFFC46A2A), query: 'latin'),
(name: 'Classical', tint: Color(0xFF5A6A7A), query: 'classical'),
(name: 'Country', tint: Color(0xFF8A6A2E), query: 'country'),
(name: 'Afrobeats', tint: Color(0xFFC48A1A), query: 'afrobeats'),
(name: 'Charts', tint: Color(0xFF4A6AC4), query: 'top hits'),
(name: 'Chill', tint: Color(0xFF3A7A8A), query: 'chill'),
(name: 'Workout', tint: Color(0xFFC43A3A), query: 'workout'),
const _browseCategories = <({String nameKey, Color tint, String query})>[
(nameKey: 'desktop_search_hip_hop_rap', tint: Color(0xFFC45C1A), query: 'hip hop'),
(nameKey: 'desktop_search_pop', tint: Color(0xFFC45A88), query: 'pop'),
(nameKey: 'desktop_search_r_b', tint: Color(0xFF7A4FC4), query: 'r&b soul'),
(nameKey: 'desktop_search_electronic', tint: Color(0xFF1A8A8A), query: 'electronic'),
(nameKey: 'desktop_search_rock', tint: Color(0xFFB03A4A), query: 'rock'),
(nameKey: 'desktop_search_jazz', tint: Color(0xFF2E6B8A), query: 'jazz'),
(nameKey: 'desktop_search_indie', tint: Color(0xFF3D8A62), query: 'indie'),
(nameKey: 'desktop_search_k_pop', tint: Color(0xFFC44A7A), query: 'k-pop'),
(nameKey: 'desktop_search_latin', tint: Color(0xFFC46A2A), query: 'latin'),
(nameKey: 'desktop_search_classical', tint: Color(0xFF5A6A7A), query: 'classical'),
(nameKey: 'desktop_search_country', tint: Color(0xFF8A6A2E), query: 'country'),
(nameKey: 'desktop_search_afrobeats', tint: Color(0xFFC48A1A), query: 'afrobeats'),
(nameKey: 'desktop_search_charts', tint: Color(0xFF4A6AC4), query: 'top hits'),
(nameKey: 'desktop_search_chill', tint: Color(0xFF3A7A8A), query: 'chill'),
(nameKey: 'desktop_search_workout', tint: Color(0xFFC43A3A), query: 'workout'),
];

/// Search result → playable (queue key = title|artist, matching playback).
Expand Down Expand Up @@ -250,7 +251,7 @@ class _WaveSearchPageState extends ConsumerState<WaveSearchPage> {
children: [
WaveEntrance(
rise: 10,
child: Text('Search',
child: Text(context.l10n.tr('navSearch'),
style: WaveType.pageTitle.copyWith(fontSize: 22)),
),
const SizedBox(height: 12),
Expand All @@ -263,7 +264,7 @@ class _WaveSearchPageState extends ConsumerState<WaveSearchPage> {
controller: _controller,
focusNode: _focus,
autofocus: true,
placeholder: 'Songs, artists, albums, playlists…',
placeholder: context.l10n.tr('desktop_search_songs_artists_albums_playlists'),
prefix: Padding(
padding: const EdgeInsets.only(left: 8),
child: Icon(WaveIcons.search,
Expand Down Expand Up @@ -459,11 +460,12 @@ class _RecentlySearched extends StatelessWidget {
children: [
Row(
children: [
Text('Recently Searched', style: WaveType.sectionTitle),
Text(context.l10n.tr('desktop_search_recently_searched'),
style: WaveType.sectionTitle),
const Spacer(),
WaveLink(
onPressed: onClear,
child: Text('Clear',
child: Text(context.l10n.tr('ytimport_clear_cd'),
style: WaveType.label.copyWith(color: waveAccent(context))),
),
],
Expand Down Expand Up @@ -519,16 +521,20 @@ class _RecentSearchCardState extends ConsumerState<_RecentSearchCard> {
bool _pressed = false;

String _kindLine(SearchResultItem? hit) {
if (hit == null) return 'Search';
if (hit == null) return context.l10n.tr('navSearch');
switch (hit.tab) {
case SearchTab.artists:
return 'Artist';
return context.l10n.tr('pd_sort_artist');
case SearchTab.tracks:
return hit.artist.isEmpty ? 'Song' : 'Song · ${hit.artist}';
return hit.artist.isEmpty
? context.l10n.tr('lyshare_mode_song')
: context.l10n.tr('desktop_search_song_1_s', [hit.artist]);
case SearchTab.albums:
return hit.artist.isEmpty ? 'Album' : 'Album · ${hit.artist}';
return hit.artist.isEmpty
? context.l10n.tr('art_type_album')
: context.l10n.tr('desktop_search_album_1_s', [hit.artist]);
case SearchTab.playlists:
return 'Playlist';
return context.l10n.tr('desktop_search_playlist');
}
}

Expand Down Expand Up @@ -617,7 +623,7 @@ class _RecentSearchCardState extends ConsumerState<_RecentSearchCard> {
),
if (_hover)
LWTooltip(
message: 'Remove',
message: context.l10n.tr('desktop_search_remove_recent'),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand Down Expand Up @@ -645,7 +651,8 @@ class _BrowseCategories extends ConsumerWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Browse Categories', style: WaveType.sectionTitle),
Text(context.l10n.tr('desktop_search_browse_categories'),
style: WaveType.sectionTitle),
const SizedBox(height: 12),
LayoutBuilder(builder: (context, c) {
final cols = c.maxWidth < 560
Expand All @@ -667,13 +674,13 @@ class _BrowseCategories extends ConsumerWidget {
width: width,
height: height,
child: _BrowseTile(
name: _browseCategories[i].name,
nameKey: _browseCategories[i].nameKey,
tint: _browseCategories[i].tint,
query: _browseCategories[i].query,
startIndex: i * 3,
onTap: () => context.go(
'/genre/${Uri.encodeComponent(_browseCategories[i].query)}'
'?name=${Uri.encodeComponent(_browseCategories[i].name)}',
'?name=${Uri.encodeComponent(context.l10n.tr(_browseCategories[i].nameKey))}',
),
),
),
Expand All @@ -686,13 +693,13 @@ class _BrowseCategories extends ConsumerWidget {
}

class _BrowseTile extends ConsumerStatefulWidget {
final String name;
final String nameKey;
final Color tint;
final String query;
final int startIndex;
final VoidCallback onTap;
const _BrowseTile({
required this.name,
required this.nameKey,
required this.tint,
required this.query,
required this.startIndex,
Expand Down Expand Up @@ -805,7 +812,7 @@ class _BrowseTileState extends ConsumerState<_BrowseTile> {
right: 12,
bottom: 12,
child: Text(
widget.name,
context.l10n.tr(widget.nameKey),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: WaveType.trackTitle.copyWith(
Expand All @@ -831,12 +838,12 @@ class _ResultFilters extends StatelessWidget {

@override
Widget build(BuildContext context) {
const items = <(SearchTab?, String)>[
(null, 'All'),
(SearchTab.tracks, 'Songs'),
(SearchTab.albums, 'Albums'),
(SearchTab.artists, 'Artists'),
(SearchTab.playlists, 'Playlists'),
final items = <(SearchTab?, String)>[
(null, context.l10n.tr('dl_filter_all')),
(SearchTab.tracks, context.l10n.tr('local_tab_songs')),
(SearchTab.albums, context.l10n.tr('art_albums')),
(SearchTab.artists, context.l10n.tr('search_tab_artists')),
(SearchTab.playlists, context.l10n.tr('navPlaylists')),
];
return Wrap(
spacing: 8,
Expand Down Expand Up @@ -1000,10 +1007,12 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
padding: const EdgeInsets.only(top: 20),
child: WaveEmpty(
icon: anyError ? FluentIcons.error : WaveIcons.search,
title: anyError ? 'Search failed' : 'No results',
title: anyError
? context.l10n.tr('desktop_search_search_failed')
: context.l10n.tr('desktop_search_no_results'),
subtitle: anyError
? 'Check your connection and try again.'
: 'Try a different artist, album or track.',
? context.l10n.tr('desktop_search_check_your_connection_and_try_again')
: context.l10n.tr('desktop_search_try_a_different_artist_album_or_track'),
),
);
}
Expand Down Expand Up @@ -1034,7 +1043,8 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child:
Text('Top Result', style: WaveType.sectionTitle),
Text(context.l10n.tr('desktop_search_top_result'),
style: WaveType.sectionTitle),
),
const SizedBox(height: 10),
if (_songs.isEmpty &&
Expand Down Expand Up @@ -1063,7 +1073,7 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child: _SectionHead(
label: 'Songs', loading: songsAsync.isLoading),
label: context.l10n.tr('local_tab_songs'), loading: songsAsync.isLoading),
),
const SizedBox(height: 4),
if (_songs.isEmpty)
Expand All @@ -1082,7 +1092,7 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child: _SectionHead(
label: 'Albums',
label: context.l10n.tr('art_albums'),
loading: albumsAsync.isLoading),
),
const SizedBox(height: 10),
Expand Down Expand Up @@ -1136,7 +1146,7 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child: _SectionHead(
label: 'Artists',
label: context.l10n.tr('search_tab_artists'),
loading: artistsAsync.isLoading),
),
const SizedBox(height: 10),
Expand Down Expand Up @@ -1197,7 +1207,7 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child: _SectionHead(
label: 'Playlists',
label: context.l10n.tr('navPlaylists'),
loading: playlistsAsync.isLoading),
),
const SizedBox(height: 10),
Expand Down Expand Up @@ -1237,7 +1247,7 @@ class _CombinedResultsState extends ConsumerState<_CombinedResults> {
index: slot(),
rise: 8,
child: _SectionHead(
label: 'Episodes',
label: context.l10n.tr('podcast_episodes'),
loading: podcastAsync.isLoading && episodes.isEmpty,
),
),
Expand Down Expand Up @@ -1456,7 +1466,12 @@ class _TopResult extends StatelessWidget {
borderRadius: BorderRadius.circular(999),
),
child: Text(
hero.tab.name.toUpperCase(),
switch (hero.tab) {
SearchTab.tracks => context.l10n.tr('lyshare_mode_song'),
SearchTab.albums => context.l10n.tr('art_type_album'),
SearchTab.artists => context.l10n.tr('pd_sort_artist'),
SearchTab.playlists => context.l10n.tr('desktop_search_playlist'),
},
style: WaveType.overline.copyWith(fontSize: 9),
),
),
Expand Down Expand Up @@ -1591,5 +1606,3 @@ class _CoverCard extends StatelessWidget {
));
}
}


31 changes: 31 additions & 0 deletions test/desktop_search_l10n_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:lastwave_desktop/core/l10n/app_language.dart';
import 'package:lastwave_desktop/core/l10n/app_localizations.dart';
import 'package:lastwave_desktop/core/l10n/translations.dart';

void main() {
test('Desktop search resources have Chinese and English fallback', () {
final keys = appTranslations['en']!.keys.where(
(key) => key.startsWith('desktop_search_'),
);
expect(keys, isNotEmpty);
for (final key in keys) {
expect(appTranslations['zh-CN']![key], isNotEmpty, reason: key);
for (final language in AppLanguage.values) {
if (language == AppLanguage.system) continue;
final expected =
appTranslations[language.tag]?[key] ?? appTranslations['en']![key];
expect(resolveTranslation(language.tag, key), expected, reason: key);
}
}
});

test('Recent search descriptions preserve artist names literally', () {
const artist = r'Artist $100 [Live]';
const english = AppLocalizations(AppLanguage.english);
const chinese = AppLocalizations(AppLanguage.chineseSimplified);
expect(english.tr('desktop_search_song_1_s', [artist]), 'Song · $artist');
expect(chinese.tr('desktop_search_song_1_s', [artist]), '歌曲 · $artist');
expect(chinese.tr('desktop_search_album_1_s', [artist]), '专辑 · $artist');
});
}